Lines and polygons - Meshes overview

1Meshes and 3D shapes

Provided 3D rendering engines can draw 3D scenes that are described with lines and polygons.

To render polygons we have to perform some computations that need an efficient description of each polygon (3D face), particularly a perpendicular unit normal vector.

This normal vector indicates the face (polygon) orientation in the space and is mainly used for backface culling but also for Gouraud shading (light and color interpolation using values associated to vertices of polygons). It can be directly provided within the mesh list generated by a 3d modeler software or computed "on the fly" using the cross product.

If two vectors are almost parallel, cross product is small and a numerical inaccuracy may result. To avoid that bad point we can use the more robust Newell method. As I do not use this method, I will not discuss about it.

To compute a normal vector, perpendicular of a polygon, we need to define an ordered list of vertices. The order can be clockwise or counterclockwise and impacts on the resulting perpendicular vector.

To be correctly used, the normal vector must be normalized to obtain a unit vector whose length is 1 (the unit length).

 

1Mesh definition used in provided codes

The code has been optimized to render triangular faces. It can render faces with more vertices but this feature is internally used for clipping. Triangular faces are supported by most 3D modeler.

I use counterclockwise enumeration order for vetices declared in polygon meshes (collections of vertices, edges and faces defining the 3D shapes). The unit normal vector allowing face orientation is defined as shown below: