   RotPosScalePathInterpolator

The RotPosScalePathInterpolator is the most flexible of all the PathInterpolators. As its name suggests, it allows the rotation, position, and scale of a TransformGroup to be modified.

Rotations, positions, and scales are specified at a series of Alpha values (or knots). The rotation, position, and scale defines a pose that, along with the time information, allows the Interpolator to linearly interpolate between poses based on the Alpha value and the defined knots.

As the name knots implies, a useful way to visualize the interpolator is as a string stretched taut between a number of points. Each point is called a knot, and as well as having an Alpha value (time) when the interpolator is to reach the knot it also possesses position, scale, and rotation information (a pose). The distance between knots defines the speed at which the interpolation between values must occur.

Knots are specified using float values between 0 and 1, where 0 is the knot used at Alpha value 0 and 1 is the knot used at Alpha time 1. The array of knot values defines a mapping from Alpha value to pose information. The knot values must increase from 0 to 1 in the knot array.

//define the knots array that map from Alpha to pose index float[] knots = {0.0f, 0.1f, 0.2f, 0.3f, 0.4f,

0.6f, 0.8f, 0.9f, 1.0f};

//create array with 9 poses: containing rotation, position

//and scale values

Quat4f[] quats = new Quat4f; Point3f[] positions = new Point3f;

float[] scales = {0.2f, 0.5f, 0.8f, 2.3f, 5.4f,

0.6f, 0.4f, 0.2f, 0.1f};

//define the rotation values for each of the 9 poses quats = new Quat4f(0.3f, 1.0f, 1.0f, 0.0f); quats = new Quat4f(1.0f, 0.0f, 0.0f, 0.3f); quats = new Quat4f(0.2f, 1.0f, 0.0f, 0.0f); quats = new Quat4f(0.0f, 0.2f, 1.0f, 0.0f); quats = new Quat4f(1.0f, 0.0f, 0.4f, 0.0f); quats = new Quat4f(0.0f, 1.0f, 1.0f, 0.2f); quats = new Quat4f(0.3f, 0.3f, 0.0f, 0.0f); quats = new Quat4f(1.0f, 0.0f, 1.0f, 1.0f); quats = quats;

//define the positions for each of the 9 poses positions= new Point3f(0.0f, 0.0f, −1.0f); positions= new Point3f(1.0f, −2.0f, −2.0f); positions= new Point3f(−2.0f, 2.0f, −3.0f); positions= new Point3f(1.0f, 1.0f, −4.0f); positions= new Point3f(−4.0f, −2.0f, −5.0f); positions= new Point3f(2.0f, 0.3f, −6.0f); positions= new Point3f(−4.0f, 0.5f, −7.0f); positions= new Point3f(0.0f, −1.5f, −4.0f); positions= positions;

//create the interpolator and pass Alpha, TransformGroup,

//knots, and pose information

RotPosScalePathInterpolator rotPosScalePathInterplator = new RotPosScalePathInterpolator( alpha,

tg,

new Transform3D(), knots,

quats, positions, scales );

As you can see, the rotation angles are specified using the Quat4f class. The Quat4f class specifies a rotation as a quaternion. The following is a description of quaternions, taken from the excellent “Matrix and Quaternion FAQ.” The FAQ can be found online and it currently maintained by Andreas Junghanns at
http://www.cs.ualberta.ca/~andreas/math/matrfaq_latest.php
.

“Quaternions extend the concept of rotation in three dimensions to rotation in four dimensions. This avoids the problem of “gimbal−lock” and allows for the implementation of smooth and continuous rotation. In effect,

they may be considered to add an additional rotation angle to spherical coordinates: longitude, latitude, and rotation angles. A Quaternion is defined using four floating point values |x y z w|. These are calculated from the combination of the three coordinates of the rotation axis and the rotation angle.”

Unfortunately most people do not think readily in quaternions, so the following two conversion functions are useful to help create quaternions from axis or Euler angles. The algorithms for the functions were taken from the “Matrix and Quaternion FAQ.” I encourage you to check the FAQ for updates, optimizations and corrections to this code.

 Impressum und Datenschutz    Copyright ©2018 eir.me Siebel Articles Python Perl 5 Documentation Manuel PHP7 français Java Das PHP7 Handbuch PHP7 Manual English Linux and Unix Jobs