Simple schooling visualization. Fish are represented by simplified polygon models that can be rendered quickly. Individual orientations are stored and recorded as quaternion values to allow for easy interpolation during playback.
RHTgrQuaternion
The quaternion object stores, manipulates and returns orientation information. Quaternions extend the concept of rotation in 3 dimensions to rotation in 4 dimensions eliminating "gimbal-lock" allowing for smooth and continuous rotation. An added advantage quaternions have over the Euler angle system is that quaternions can easily be interpolated. RHTgrCamera is dependent upon this object and this object is also useful for interpolating actor orientations in key framed animations.
Download
RHTgrQuaternion is included in the RHTgrCamera package and is available individually below.
RHTgrQuaternion__Define.pro
Calling Sequence
oQuaternion = Obj_New("RHTgrQuaternion", [, PITCH{Get, Set}=value{0 to 360}] [, YAW{Get, Set}=value{0 to 360}] [, ROLL{Get, Set}=value{0 to 360}])
Keywords
pitch
Set this keyword to a scalar defining the initial orientation about the X axis in degrees.
Default: 0.
yaw
Set this keyword to a scalar defining the initial orientation about the Y axis in degrees.
Default: 0.
roll
Set this keyword to a scalar defining the initial orientation about the Z axis in degrees.
Default: 0.
Methods
GetCTM
This function method returns a 4x4 transformation matrix representing the quaternion orientation.
matrix = FLTARR(4,4) matrix = oQuaternion -> GetCTM()
GetDirectionVector
This function method returns a unit vector representing the object's current orientation as a 3 element float [X,Y,Z].
vector = FLTARR(3) vector = oQuaternion -> GetDirectionVector()
GetPYR
This function method returns the object's current orientation as a 3 element vector [pitch,yaw,roll] (as defined in the keywords section above).
pyr = FLTARR(3) pyr = oQuaternion -> GetPYR()
GetQuat
This function method returns the object's value as a 4 element float. The values returned are in the form [w,x,y,z]
q = DBLARR(4) q = oQuaternion -> GetQuat()
GetDirectionVector
This function method returns a unit vector representing the object's current orientation as a 3 element float [X,Y,Z].
vector = fltarr(3) vector = oQuaternion -> GetDirectionVector()
Interpolate
This function method returns a quaternion in the form [w,x,y,z] which represents a spherically interpolated orientation based on the object's value, a "to" value, and a blend value ranging from 0.0 to 1.0. A blend of 0.0 will return this object's value and a blend of 1.0 will return the "to" value.
quat_one = OBJ_NEW('RHTgrQuaternion', PITCH=20.) quat_two = OBJ_NEW('RHTgrQuaternion', YAW=235.) ; get a quaternion with orientation halfway between ; quat_one and quat_two q=DBLARR(4) q=quat_one->Interpolate(quat_two->GetQuat(),0.5)
Reset
This procedure method resets the quaternion to it's initial orientation.
oQuaternion -> Reset
Set
This procedure method will set the current orientation to the provided pitch, yaw, and roll values.
oQuaternion -> Set, 15., 90., 0.
SetQuat
This procedure method sets the object's value to the given value. The value must be in the form: [w,x,y,z].
quat_one = OBJ_NEW('RHTgrQuaternion') quat_two = OBJ_NEW('RHTgrQuaternion') ; <do something to quat_one> ;set quat_two equal to quat_one quat_two -> SetQuat, quat_one -> GetQuat()