Game Development Reference
In-Depth Information
A triangle is represented by three integers that index into the vertex
list. Usually, the order in which these vertices are listed is significant,
since we may consider faces to have “front” and “back” sides. We
adopt the left-handed convention that the vertices are listed in clock-
wise order when viewed from the front side. Other information may
also be stored at the triangle level, such as a precomputed normal of
the plane containing the triangle, surface properties (such as a texture
map), and so forth.
Listing 10.5 shows a highly simplified example of how an indexed trian-
gle mesh might be stored in C.
/ /
s t r u c t
V e r t e x
i s
t h e
i n f o r m a t i o n
we
s t o r e
a t
t h e
v e r t e x
l e v e l
s t r u c t
V e r t e x
{
/ /
3D p o s i t i o n
o f
t h e
v e r t e x
V e c t o r 3
po s ;
/ /
Other
i n f o r m a t i o n
c o u l d
i n c l u d e
/ /
t e x t u r e
mapping
c o o r d i n a t e s ,
a
/ /
s u r f a c e
normal ,
l i g h t i n g
v a l u e s ,
e t c .
} ;
/ /
s t r u c t
T r i a n g l e
i s
t h e
i n f o r m a t i o n
we
s t o r e
a t
t h e
t r i a n g l e
l e v e l
s t r u c t
T r i a n g l e
{
/ /
I n d i c e s
i n t o
t h e
v e r t e x
l i s t .
I n
p r a c t i c e ,
16 b i t
i n d i c e s
a r e
/ /
a l m o s t
a l w a y s
used
r a t h e r
t h a n 32 b i t ,
t o
s a v e
memory and
bandwidth .
i n t
v e r t e x I n d e x [ 3 ] ;
/ /
Other
i n f o r m a t i o n
c o u l d
i n c l u d e
/ /
a
normal ,
m a t e r i a l
i n f o r m a t i o n ,
e t c
} ;
/ /
s t r u c t
T r i a n g l e M e s h
s t o r e s
an
i n d e x e d
t r i a n g l e
mesh
s t r u c t
T r i a n g l e M e s h
{
/ /
The
v e r t i c e s
i n t
v e r t e x C o u n t ;
V e r t e x
v e r t e x L i s t ;
/ /
The
t r i a n g l e s
i n t
t r i a n g l e C o u n t ;
T r i a n g l e
t r i a n g l e L i s t ;
} ;
Listing 10.5
Indexed triangle mesh
Figure 10.11 shows how a cube and a pyramid might be represented as
a polygon mesh or a triangle mesh. Note that both objects are part of a
single mesh with 13 vertices. The lighter, thicker wires show the outlines
of polygons, and the thinner, dark green wires show one way to add edges
to triangulate the polygon mesh.
Search WWH ::




Custom Search