Game Development Reference
In-Depth Information
A far more reliable way is to store the translation, rotation, and scale separately, and
calculate a fresh matrix for every frame. How this can be achieved is described in the
following sections.
Animating by translation
Our game class simply needs to maintain a position vector containing the current
world position of the object. We can move an in-game object around the world by
adding a velocity vector that indicates how far the game object has moved in this
frame and in what direction, with reference to the stored position vector.
To generate the final model matrix all we need to do is copy the position vector into
the translation part of the matrix. We normally do this as the last step, as the act of
multiplying matrices together when generating the rotation and scale will affect the
translation of the matrix.
// lTimeStep is the time elapsed since the last frame (here we're
// setting it to the time interval required to run at 30 frames
// per second).
float lTimeStep = 1.0f / 30.0f;
// Calculate how far we've moved this frame and update position
CIwFVec3 lVelocityStep = mVelocity * lTimeStep;
mPosition += lVelocityStep;
// Copy the position into the matrix used to render the model
mModelMatrix.t = mPosition;
Animating by rotation
The top left 3 x 3 section of the model matrix specifies the rotation at which we want
the model to be drawn. Our game object stores the required rotation and updates it
on a frame-by-frame basis. When it is time to render, we just use the stored rotation
to calculate the rotation matrix.
There are a number of ways in which the rotation of the object might be stored. Three
of the most common ways are shown in the following section.
Rotation using Euler angles
Euler angles consist of the required angle of rotation in the x, y, and z axes, which
we would normally store using a vector. If rotation is not desired around every axis,
you may choose to store only those rotation values that you require.
 
Search WWH ::




Custom Search