Game Development Reference
In-Depth Information
of points in 3D space with accompanying data that describes how these points are
organized into polygons and how the polygons should be rendered.
The points in 3D space are called vertices. They are stored as three floating-point
numbers that represent the location of the point (X,Y,Z) from the origin. Individual
triangles in this mesh are defined by three or more indices into the point list. Here
'
s
an example of the mesh for a cube that has been pushed around so that it isn
'
t sym-
metrical in any axis (a useful object you
'
ll use later in the 3D graphics chapter):
Vec3 TestObject::g_SquashedCubeVerts[] =
{
Vec3( 0.5,0.5,-0.25),
// Vertex 0.
Vec3(-0.5,0.5,-0.25),
// Vertex 1.
Vec3(-0.5,0.5,0.5),
// And so on.
Vec3(0.75,0.5,0.5),
Vec3(0.75,-0.5,-0.5),
Vec3(-0.5,-0.5,-0.5),
Vec3(-0.5,-0.3,0.5),
Vec3(0.5,-0.3,0.5)
};
WORD TestObject::g_TestObjectIndices[][3] =
{
{ 0,1,2 }, { 0,2,3 }, { 0,4,5 },
{ 0,5,1 }, { 1,5,6 }, { 1,6,2 },
{ 2,6,7 }, { 2,7,3 }, { 3,7,4 },
{ 3,4,0 }, { 4,7,6 }, { 4,6,5 }
};
Feel free to plot it out on graph paper if you want, or you can take my word for it.
The eight vertices are stored in an array, and the triangles are defined by groups of
three indices into that array. A cube has eight points in space and six faces, but those
faces are each comprised of two triangles. Twelve groups of three indices each are
needed to define twelve triangles that make a cube.
If you have some experience with 3D programming, you might know that there are
ways to save some space here. Instead of storing each triangle as a group of three
points, you can store a list of connected triangles with fewer indices. These data
structures are called triangle lists or triangle fans. Either of these stores the first trian-
gle with three indices and each following triangle with only one additional index.
This technique is a little like drawing a shape without picking up your pencil, since
each extra triangle requires only one additional vertex rather than an entire set of
Search WWH ::




Custom Search