Class Shape
In: rubycube.c
Parent: Object

Document-method: pos_x call-seq:

 Shape.pos_x -> number

Returns the X component of the shape position.

Methods

circle   color   color_i   custom   hide   line   line_strip   move   move_circle   move_to   normal   pos=   pos_x   pos_x=   pos_y   pos_y=   pos_z   pos_z=   rect   rotate   set_label   show   square   vel=   vel_x   vel_x=   vel_y   vel_y=   vel_z   vel_z=   vertex   vertex_xyz  

Public Class methods

Returns a new circle shape at the position 20,20 and a radius of 10

Returns a custom shape by specifying the underlying graphics format and size of the buffer of elements. This is an advanced method and extra care should be taken.

Parameters

x Initial position.x for translation y Initial position.y for translation format Underlying format to use for the shape. (see SHAPE_FORMAT_* constants) count Number of elements stored in the underlying vertex buffer and submitted

         to the GPU.

Returns a new line segment using the provided end points.

Returns a new shape defined as a strip of lines where lines are connected from the first point to the last. Points n and n+1 define line n. N-1 lines are drawn.

The first parameter ‘format’ specifies how many elements define a single point. This could also be defined as the ‘stride’ of the input set.

Return a new 2D rectangle or square shape with the provided x, y, width and height. The scalars can be presented in whatever format is most convient.

Return a new 2D rectangle or square shape with the provided x, y, width and height. The scalars can be presented in whatever format is most convient.

Public Instance methods

Document-method: Shape.show

Toggle visibility for a shape off.

Move a shape position over time in a desired direction

Parameters

  • position 2D or 3D coordinate as array
  • duration -1, 0, +N

Examples

 # Move 10 units up and 10 units right for 2 seconds
 shape.move([10, 10], 2)

 # Move 10 units left immediately
 shape.move([-10, 0], 0)

 # Set a velocity of +1 in the x direction per second
 shape.move([1, 0], -1)
 Move a shape in circle according to the parameters.

Parameters

  • dst_position 2D or 3D coordinate to rotate around
  • dst_y Y coordinate of point to move to
  • dst_z Z coordinate of point to move to

Examples

 # Move towards point 10, 10 for 2 seconds
 shape.move_to(10, 10, 0, 2)

Move a shape position over time to a destination point

Parameters

  • position 2D or 3D coordinate as array
  • duration time in seconds or 0

Examples

 target = [10, 10]

 # Move to 10, 10 over 2 seconds
 shape.move_to(target, 2)
 # Move to 10, 10 instantly
 shape.move_to(target, 0)

Set one normal. Lighting is currently disabled, check back later.

call-seq:

 c = Shape.circle([x, y], radius)
 c.pos = [40, 40] # Move to position 40, 40
Shape.pos_x → number

Returns the X component of the shape position.

Shape.pos_x = number

Sets the X component of the shape position.

Shape.pos_y → number

Returns the Y component of the shape position.

Shape.pos_y = number

Sets the Y component of the shape position.

Shape.pos_z → number

Returns the Z component of the shape position.

Shape.pos_z = number

Sets the Z component of the shape position.

Rotate a shape about the axis that passes through the camera with 2 parameters. Otherwise if all ijk vector components are specified rotate about i, j, k vectors by specified ammounts.

As with other animations -1 is infinite and treats the parameters as units/sec. Duration of 0 seconds is instant. Other durations will divide the ammount of rotation over the desired duration to arrive at the specified configuration when desired.

Parameters

  • x X component for 3D rotation
  • y Y component for 3D rotation
  • z Z component for 3D rotation
  • angle Angle in degrees to rotate
  • duration Duration of the rotation in seconds

Examples

 # In 2D
 rect = Shape.rect(100, 100, 50, 80)
 rect.rotate(45, 0) # instantly rotate 45 degrees
 rect.rotate(10, -1) # rotate 10 degrees a second forever
 rect.rotate(-45, 1) # rotate 45 degrees in 1 second

 # In 3D
 cube.rotate(10, 0, 0, 1) # rotate around the axis 10 deg in 1 second

Parameters

 +offset_x+  X offset from shape position in screen coords to show label
 +offset_y+  Y offset from shape position in screen coords to show label
 +string+    String value of label

Toggle visibility for a shape on.

Examples

 circle = Shape.circle(10, 10, 100)
 circle.hide()
 circle.show()

call-seq:

 c = Shape.circle([0, 0], 10)
 c.vel = [10, 10] # 10 units/sec in X, Y
shape.vel_x → number

Returns the current X component of the velocity.

shape.vel_x = number

Examples

 c = Shape.circle(0, 0, 10)
 c.vel_x = 10 # begin moving 10 units/sec in the positive X
shape.vel_y → number

Returns the current Y component of the velocity.

Examples

 c = Shape.circle(0, 0, 10)
 puts "Current velocity #{c.vel_x}, #{c.vel_y}, #{c.vel_z}"
shape.vel_y = number

Examples

 c = Shape.circle(0, 0, 10)
 c.vel_y = 10 # begin moving 10 units/sec in the positive Y
shape.vel_z → number

Returns the current Z component of the velocity.

Examples

 c = Shape.circle(0, 0, 10)
 puts "Current velocity #{c.vel_x}, #{c.vel_y}, #{c.vel_z}"
shape.vel_z = number

Examples

 c = Shape.circle(0, 0, 10)
 c.vel_z = 10 # begin moving 10 units/sec in the positive Z

Changes a single vertex by passing in the components of the new vertex.

Changes a single vertex by passing in a vertex tuple.

[Validate]