MAKING OBJECTS MOVE

 

WTK provides various function for incrementally rotating, translating, and transforming modes. These functions can be used to give and object visual behavior in the simulation. All of the following functions work on either transform or movable nodes. They also allow the user to specify the frame of reference in which the motion will occur.

 

Understanding a Nodes Frame of Reference

It is important that the user have a working knowledge of WTK reference frames. Lets take a moment and review some of these concepts. WTK incremental motion functions can operate in two of WTK’s reference frames namely, WTFRAME_LOCAL or WTFRAME_PARENT. An objects LOCAL reference frame follows the object through its rotations this can cause confusion to the user when initially rotating then translating object. Here’s and example. Let’s say you have a cube whose local X axis initially points to the right and local Y axis points down (it is aligned with the world coordinate system). You translate this object along its local -Y axis it would move upward. If I then rotate that object PI / 2 radians (90 degrees) in a positive direction around its X axis the local Y axis will end up pointing in and out of the screen. If at this time I translate the object along its local Y axis it would move into the screen (its local Y axis is maintained along the object Y extent). See figure 11.

Rotating in the parent reference of an object often is more intuitive for a user unless the parent objects reference frame is rotating. If the parent frame is not rotating the results of translations and rotations will always be along the parent’s axes. If the parent object rotates then the translations and rotations follow the parents reference frame once it has been rotated.

 

NOTE: The parent reference frame for an object that resides as a direct child of the root node is the World Coordinate System. If at all possible rotate and translate objects in this frame since the orientation of the WCS axes will never change.

 

 

figure 11

 

The local axes of an object follow the object when it is rotated

 

 

 

 

 

Rotating Nodes

A transform or movable node can be incrementally rotated using the following functions Unlike the WTnode_setrotation function where the 4x4 transformation matrix or parts there of are replaced these functions merely add to or subtract from the rotational component of the transformation matrix.

 

WTnode_rotate

Creates an incremental rotation to the existing transform node either in local (object) frame or in the nodes parent frame. Note that the order of rotation is reflected in the order in which the arguments are passed in namely rotation about the Y axis, then X, the Z. This function rotates the objects using Euler angles in radians

 

SYNTAX:

FLAG WTnode_rotate(WTnode *node, float y, float x, float z, int FRAME);

ARGUMENTS:

node -- A pointer to the node to rotate

y -- The amount in radians to rotate around the Y axis

x -- The amount in radians to rotate around the X axis

z -- The amount in radians to rotate around the Z axis

FRAME -- The reference frame in which the rotation will occur valid arguments are WTFRAME_LOCAL and

WTFRAME_PARENT

 

RETURN TYPE:

A flag indicating success or failure of the function

WTnode_rotateq

Creates an incremental rotation to the existing transform node either in local (object) frame or in the nodes parent frame. This function rotates an object using a quaternion to specify the incremental rotation.

SYNTAX:

FLAG WTnode_rotateq(WTnode *node, WTq quaternion, int FRAME);

ARGUMENTS:

node -- A pointer to the node to rotate

quaternion -- A quaternion specifying the incremental rotation

FRAME -- The reference frame in which the rotation will occur valid arguments are WTFRAME_LOCAL and

WTFRAME_PARENT

RETURN TYPE:

A flag indicating the success or failure of the function.

 

 

WTnode_rotatem3

Creates an incremental rotation to the existing transform node either in local (object) frame or in the nodes parent frame. This function

rotates an object using a 3x3 matrix to specify the incremental rotation.

SYNTAX:

FLAG WTnode_rotatem3(WTnode *node, WTm3 matrix, int FRAME);

ARGUMENTS:

node -- A pointer to the node to rotate

matrix -- A WTm3 (3x3 matrix) specifying the incremental rotation

FRAME -- The reference frame in which the rotation will occur valid arguments are WTFRAME_LOCAL and

WTFRAME_PARENT

RETURN TYPE:

A flag indicating success or failure of the function

 

WTnode_rotatem4

Creates an incremental rotation to the existing transform node either in local (object) frame or in the nodes parent frame. This function

rotates an object using a 4x4 matrix to specify the incremental rotation.

SYNTAX:

FLAG WTnode_rotatem4(WTnode *node, WTm4 matrix, int FRAME);

ARGUMENTS:

node -- A pointer to the node to rotate

matrix -- A WTm4 (4x4 matrix) specifying the incremental rotation

FRAME -- The reference frame in which the rotation will occur valid arguments are WTFRAME_LOCAL and

WTFRAME_PARENT

RETURN TYPE:

A flag indicating success or failure of the function

 

WTnode_rotateaxis

Creates an incremental rotation to the existing transform node either in local (object) frame or in the nodes parent frame. This function works by specifying the axis to rotate about and an angle in degrees to rotate. This is the only function that works with degrees instead of radians.

SYNTAX:

FLAG WTnode_rotateaxis(WTnode *node, int AXIS, int FRAME);

ARGUMENTS:

node -- A pointer to the node to rotate

AXIS -- one of the predefined constants X,Y. or Z

FRAME -- The reference frame in which the rotation will occur valid arguments are WTFRAME_LOCAL and

WTFRAME_PARENT

RETURN TYPE:

A flag indicating the success or failure of the function.

 

Translating Nodes

A transform or movable node can be incrementally translated along any of its axes (X, Y, or Z) in its local or parent reference frame with the function WTnode_translate. While there is only one function for the incremental translation of an object it may be a good idea to write your own function that can be passed 3 floating point numbers instead of creating an WTp3 everytime you want to translate an object. I find this saves programming time and trouble

 

WTnode_translate

This function incrementally translates a transformation node along a specified amount in a specified frame

SYNTAX:

FLAG WTnode_translate(WTnode *node, WTp3 translation, int FRAME);

ARGUMENTS:

node -- A pointer to the node to rotate

translation -- A WTp3 specifying the X, Y, Z translation

FRAME -- The reference frame in which the translation will occur valid arguments are WTFRAME_LOCAL and

WTFRAME_PARENT

RETURN TYPE:

A flag indicating the success or failure of the function.

Assignment 10

project definition: