Game Development Reference
In-Depth Information
As we are using triangle strips, the order of the vertices actually alternates between
anti-clockwise and clockwise. Normally we don't have to worry about this too
much since the natural order of the vertices in the strip takes care of it, but it can
cause problems when you try to join together triangle strips that contain an odd
number of vertices.
The general rule for joining triangle strips with degenerate triangles is
that a strip with an odd number of points will require the order of the
points in the next strip to be reversed. For example, if your first triangle
strip contains an odd number of points, the first triangle of the next
strip will need to be specified in clockwise rather than anti-clockwise
order; otherwise it will not be culled correctly.
The view matrix
When rendering 3D graphics, we need to be able to provide a position and
direction that we want to view our game world from. We do this by supplying
a view or camera matrix; in Marmalade this can be done using an instance of
the CIwFMat class.
The CIwFMat class represents a 4 x 4 matrix using a 3 x 3 array of float for the
rotation part, and CIwFVec3 for the translation part. The remaining elements of the
4 x 4 matrix (that is, the right-most column of numbers) are fixed to be the same as
the identity matrix (0, 0, 0, and 1 from top to bottom of the column). These values
never have any influence on normal 3D transformations; so by leaving them out we
save memory, and also the matrix multiplication code can be made slightly more
efficient by not having to perform multiplications for these parts of the matrix.
Time to create a suitable view matrix. For the purposes of our spinning cube, it
would be good if we could specify a position for the camera and then calculate the
correct rotation for the matrix to view our cube. Luckily the matrix classes have a
method called LookAt that makes this easy to do:
CIwFMat vm;
vm.t.x = 0.0f; vm.t.y = 0.0f; vm.t.z = -400.0f;
vm.LookAt(vm.t, CIwFVec3::g_Zero, CIwFVec3::g_AxisY);
The previous code declares a new CIwMat instance and sets its translation to (0, 0,
-400). We then call the LookAt method, which is passed the position we want the
camera to be placed at, the point in space we want it to be orientated towards, and
a unit vector in the vertically up direction.
 
Search WWH ::




Custom Search