I've been causing myself some confusion lately with regards to vertex winding in a mesh class that i'm writing.
Currently, the mesh contains the appropriate structures for:
- vertices (vector3)
- indices (vector3 - actually a custom struct of 3 ints)
- normals (vector3)
- colors (vector4)
Starting out simple, i'm trying to model a cuboid with 24 vertices and 12 indices. What is causing me confusion at the moment is how vertex winding is determined for each face. OpenGL-ES seems to be set to counter clockwise winding by default (which can be changed) but i'm really not sure how CCW is determined in 3 dimensions?
It was my understanding that the "front" and "back" of an object would be defined by the direction of the vector for each vertices normal, rather than the ordering of each vertex that defines a "face". It would seem however that this isn't true. Either that, or (more likely) my code isn't entirely correct.
If this isn't the case, how is CCW defined in 3 dimensions? How does this translate for the 6 faces of a cuboid? If I use the same logic for the back face of the cuboid as the front face, surely one of the faces would point inwards?
I'm really struggling to get my head around this when manually defining vertices for my mesh. The confusion really kicks in when I try to work out how vertex data is stored in a model/mesh file created by MAYA or Blender etc. Are all faces oriented outwards when an object is exported?
Or perhaps my original assumption was correct whereby the normals define what is to be determined as the front of each face, but then why does OpenGL have a flag for specifying the vertex winding order?
Also, considering the three vectors A, B and C; surely the same winding (regardless of orientation) could be achieved in three different ways, i.e: A->B->C or B->C->A or C->A->B?
Is there a simple way for determining such things or have I completely missed the mark somewhere?