Game Development Reference
In-Depth Information
Taking a cross product of the vectors induced by two edges of a triangle gives the direction of its normal
(shown in Figure 8-12). For a triangle stretched between vertices a, b, and c, the normal would be:
N = normalize( (b - a) × (c - a) ) = (b - a) × (c - a) / |(b - a) × (c - a)|
Figure 8-12. Extracting a normal from a triangle.
The length of the cross-product vector is equal to twice the area of the triangle, so we normalize it to a size
of 1 by dividing it by its own length.
A consistent orientation of normals means that all normals of the mesh consistently point either to the
inside or to the outside of the mesh. The orientation of the normal vector is determined by the order of the
elements in the cross product, so to get a consistent orientation, the order of the vertices of the triangle is
important. An often-used convention is that when you look at the mesh from outside, all the polygons
should be specified in clockwise order. For the triangle shown in Figure 8-12, the order should be (a,b,c)
and not, for instance, (c,a,b).
With a normal for each triangle, the normal of a vertex is calculated as the average of the normals of the
triangles that touch it. Figure 8-13 exemplifies this.
 
Search WWH ::




Custom Search