Transform

cjcliffe edited this page Oct 15, 2011 · 4 revisions

CubicVR.Transform

The Transform class is used in conjunction with renderObject and other mat4.* utility functions. It provides a implementation similar to the OpenGL fixed-functionality stack controller with additional cache optimizations and ability to clear the stack.

Constructor:

Transform( init_mat )

Parameters:

  • init_mat (optional) : An initial matrix for the transform, if not provided the identity matrix will be used.

Methods:

setIdentity()

Sets the current matrix in the stack to the identity matrix.

Returns:

Transform instance for chaining.

getIdentity()

Get an identity matrix.

Returns:

4x4 identity matrix in an array of 16 floats.

getResult()

Get the matrix for the current transformation.

Returns:

4x4 matrix in an array of 16 floats.

pushMatrix( mat )

Push the stack controller one level, similar to glPushMatrix().

Parameters:

  • mat (optional) : a 4x4 matrix of 16 floats to push to the stack at this level, identity matrix is assumed if not supplied.

Returns:

Transform instance for chaining.

popMatrix()

Pop a matrix off the stack controller one level, similar to glPopMatrix().

Returns:

Transform instance for chaining.

clearStack()

Clear the entire stack regardless of depth.

Returns:

Transform instance for chaining.

translate( trans_vec ) or translate( trans_x, trans_y, trans_z )

Apply a translation to the transform.

Parameters:

  • trans_vec : an vector format [ x, y, z ] to translate by.
  • trans_x : x value to translate.
  • trans_y : y value to translate.
  • trans_z : z value to translate.

Returns:

Transform instance for chaining.

scale( scale_vec ) or scale( scale_x, scale_y, scale_z )

Apply a scale to the transform.

Parameters:

  • scale_vec : an array format [ x, y, z ] to scale each component by.
  • scale_x : x value to scale.
  • scale_y : y value to scale.
  • scale_z : z value to scale.

Returns:

Transform instance for chaining.

rotate( rot_vec ) or rotate( ang, x, y, z )

Apply a rotation to the transform, follows the OpenGL fixed functionality syntax of glRotatef(angle, x, y, z); or by passing an array performs a standard X,Y,Z rotation of each component.

Parameters:

  • rot_vec : an array format [ ang_x, ang_y, ang_z ] to rotate each component by.
  • rot_x : amount to apply to the x-axis. i.e. trans.rotate(45, 1, 0, 0);
  • rot_y : amount to apply to the y-axis. i.e. trans.rotate(45, 0, 1, 0);
  • rot_z : amount to apply to the z-axis. i.e. trans.rotate(45, 0, 0, 1);

Returns:

Transform instance for chaining.