Game Development Reference
In-Depth Information
Describing 3D space
First let's imagine a small box lying on the floor of a simple room (Figure
How can we create a dataset that
describes the position of the box? One
method is to use a tape measure to find
out the distance of the box from each
wall. But which wall? We need to have a
frame of reference to work from.
Figure 1.2 shows the same room, only
this time there are three perpendicular
axes overlaid on the picture. The point
where the three axes meet is called the
origin. The use of these three axes
allows you as a programmer to specify
any position in the room using three
numerical values.
In Figure 1.2, the two marked lines
perpendicular to the axes give an indica-
tion of the scale we intend to use. Each
slash on these lines represents 10 cm.
Counting the slashes gives the box as 6
along the x -axis and 8 along the z -axis.
The box is lying on the floor, so the value
along the y -axis is 0. To define the
position of the box with respect to the
frame of reference we use a vector ,
Figure 1.1 A simplified room
showing a small box.
[6, 0, 8]
In this topic, all vectors are of the form
[ x , y , z ].
The direction of the axes is the
scheme used throughout this topic. The y -axis points up, the x -axis points
to the right and the z -axis points out of the screen. We use this scheme
because it is the same as that used by the OpenGL graphics library.
Figure 1.2 A simplified room
with overlaid axes.
Transforming the box
To move the box around the room we can create a vector that gives the
distance in the x , y and z directions that you intend to move the box. That
Search Nedrilad ::

Custom Search