Game Development Reference
In-Depth Information
Movement and positioning
One of the key characteristics of a computer game is the mechanics of the movement and animation.
Coming up with a natural and streamlined look and feel for a game is often as crucial as the basic concept
and art design. Indeed, some common categories of games such as “first-person shooter” or “platformer,”
for example, refer to these look-and-feel properties rather than other aspects of the game. This section
discusses in detail a few such topics implemented in CycleBlob.
Situating on a grid
In the 2D lightcycle game, situating the bike on the grid is simply a matter of moving the player model or
sprite to a point and rotating it around its axis in multiples of 90 degrees. Situating the bike on the 3D grid
is the base concept of CycleBlob and is a slightly more challenging task. The bike model now needs to be
moved in 3D space, to be rendered above an arbitrary point on the surface, and to be rotated in 3D to
create the illusion that it is actually driving on the surface. Luckily, there is a simple mathematical trick
called “coordinate base transformation” that allows doing this potentially complex rotation and translation in
only one step.
When drawing a model, we're sending sets of x, y, z coordinates to the graphics hardware and then telling
it to connect them with triangles. These x, y, z coordinates are relative to some axis origin, orientation, and
scale that define their coordinate system. The bike model from Figure 8-4, for example, has the following
coordinate system (see Figure 8-11a):
Its axis origin is centered at the exact middle of the model.
The positive Y-axis points towards the back of the bike.
The positive Z-axis points from bottom to top.
The positive X-axis points from the right of the bike to its left.
The height of the bike is about one unit and its length is about two units.
The square grid model has a similar coordinate system (see Figure 8-11b):
The axis origin is in the middle of the object.
The grid faces and the edges are aligned with the major axis.
The height, width, and length of each face are all approximately one unit.
If we were to draw the bike and the grid model using the same coordinate system without a coordinate
transformation between them, they would appear one inside the other, as in Figure 8-11c. That is clearly
not what we want to do. Instead, we scale the bike and apply the coordinate base transformation on its
coordinates before drawing it. The coordinate base transformation moves the scaled bike to the intended
point on the grid and rotates it in all three axes so that it appears upright on the grid and faces toward its
current forward direction (see Figure 8-11d).
 
Search WWH ::




Custom Search