Game Development Reference
In-Depth Information
Marmalade's default coordinate system when rendering in 3D has the x axis positive
direction running from left to right across the screen, while the z axis positive
direction runs into the screen. However, the positive y axis runs in a direction from
the top of the screen to the bottom, which may not be what you initially expect. We
are used to thinking about the height above the ground as a positive number, but in
Marmalade it would be negative.
Once we have a view matrix, we can call the function IwGxSetViewMatrix with a
const pointer to the matrix.
The model matrix
The model matrix is used to position our 3D model in the world and allow it to
be rotated or scaled as desired. As with the view matrix, the model matrix can be
specified using a CIwFMat instance.
For our spinning cube we will create a matrix that spins the cube around the x and
y axes. We do this by creating two matrices, one for x axis rotation and another for
y axis rotation, which we then multiply together. We will be positioning our cube at
the world origin.
CIwFMat lModelMatrix;
lModelMatrix.SetRotY(lRotationY);
CIwFMat lRotX;
lRotX.SetRotX(lRotationX);
lModelMatrix.PreMult(lRotX);
The code shown declares two instances of CIwFMat and uses the methods SetRotY
and SetRotX to generate the rotation matrices around the y and x axes respectively.
The rotation angles are provided by two variables lRotationY and lRotationX ,
which are both of the type float and represent an angle (in radians) to rotate by. If
we increase the values of these two variables with each iteration of the main game
loop, it will change the orientation of the cube and make it appear to rotate when
rendered.
Be careful when using the SetRotX , SetRotY , and SetRotZ methods
of the matrix classes. These methods take two further bool parameters
that allow the translation part of the matrix and any elements of the 3 x 3
rotation part of the matrix that are not used in the rotation to be zeroed.
Both of these parameters default to true ; so, in particular, if you set up
a translation in the matrix before calling one of these methods, it will get
lost unless you specify false as the second parameter.
 
Search WWH ::




Custom Search