Displaying Mesh Triangle Normals
We will begin this chapter by adding some extra functionality to the normal drawing in Chapter 10, Getting Acquainted with Lines, Rays, and Normals. At the time, we restricted the drawing of these normals to the center of the cube being drawn. This technique won’t work with more complicated meshes. More ideally, it would work better if each normal for a plane were emitted from the center point of the triangle, which is called the centroid. The centroid can be found using the medians of the vectors that make up its sides. Take, for example, the triangle in Figure 11.1:
Figure 11.1: The centroid of a triangle
The centroid can be found by finding a point halfway along any of the sides, connecting that point with the opposite corner, and then moving along the vector from the corner to the halfway point by two-thirds. In this example, that means if you find the vector from corner A to B and then travel halfway along it to...