Game Development Reference
In-Depth Information
The following code snippet shows how you can build up a complete rotation matrix
for Euler angles applied in the order XYZ:
CIwFMat lMatXYZ;
lMatXYZ.SetRotX(xAngle);
lMatXYZ.PostRotateY(yAngle);
lMatXYZ.PostRotateZ(zAngle);
All angles used in Marmalade are specified in radians, not degrees.
Rotation using axis-angle pairs
The axis-angle method of representing a rotation requires a direction vector and an
angle of rotation to be stored. The vector represents the direction in which we want
an object to be orientated, while the angle allows the object to be rotated around
that axis.
We might find this way of specifying a rotation useful when dealing with player
characters. For example, to orient a human character we might specify the direction
vector as being the positive y axis, which then allows the angle of rotation to be used
to change the heading of the character.
Marmalade allows us to convert an axis-angle pair into a matrix for rendering,
as follows:
CIwFVec3 lDir(0.0f, 1.0f, 0.0f);
float lAngle = PI / 2.0f;
CIwFMat lMat;
lMat.SetAxisAngle(lDir, lAngle);
Rotation using quaternions
A quaternion is yet another method of representing three-dimensional rotations, and
is a concept that, when you first come across it, seems a little mind-blowing. Instead
of going on about four dimensional hyperspheres and making parts of your brain
melt, I'm just going to provide a quick guide to what you need to know in order
to use quaternions. If you want to learn more about them, I suggest you search for
"quaternions" on Google!
A quaternion consists of four components: x, y, z, and w. A 3D rotation is
represented as a unit quaternion , which, in a similar manner to vectors, just
means that the magnitude of the sum of the squares of all four components is one.
 
Search WWH ::




Custom Search