I have an object on which I want to apply lighting. It is described in a text file with its vertex coordinates.
I read the following in the the OpenGL Superbible:
void m3dFindNormal(M3DVector3f vNormal, const M3DVector3f vP1, const M3DVector3f vP2, const M3DVector3f vP3);
To use this function, pass it a vector
to store the normal, and three vectors
(each just an array of three floats)
from your polygon or triangle
(specified in counterclockwise winding
order). Note that this returned normal
vector is not necessarily unit length
(normalized).
I understand that the order in which I pass the vertices (clockwise or counterclockwise) determines the orientation of the normal vector, so I wonder how can I make the function work with a file of this format.
Hmm, this format looks kind of OBJ-ish, but with colors and without normals and texture coords. Seems like it’s not really a good choice! But if you really want to stick with it…
My piece of advice no. 0 is:
Use another format, seriously. 🙂 Raw binary dump of vertices (positions+normals+texture coords+colors+whatever) and then indices is the simplest solution usually. And if you really *really* want to use .off…
My piece of advice no. 1 is:
If you don’t want to (or can’t) do that for any reason, there’s piece of advice no 2. on how to generate normals yourself:
A,B,C, it’s(B-A)x(C-B)). Don’t rescale it to length=1 – the bigger the face’s area, the longer the resulting normal vector will be and that’s what we want (for now).