OpenGL: finding a normal, unitary vertex vector

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 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 only an array of three floats) from your polygon or triangle (indicated in the counterclockwise winding order). Note that this returned a normal vector, not necessarily a 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'm wondering how to get the function to work with the file in this format .

+1
source share
2 answers

Hmm, this format looks like OBJ-ish, but with colors and without normals and texture coords. This seems to be not a good choice! But if you really want to stick with this ...

My advice is not. 0:

Use a different format, seriously. :) The raw binary vertex dump (positions + normals + texture coordinates + colors + any) and then the indices are the easiest solution. And if you really * really want to use .off ...

My advice is not. 1:

  • import it into Blender (write an importer script in Python or use another tool to change the format)
  • The blender will calculate the normals for you (it will be good!),
  • export it to any format with normals.

( ) - , № 2. , :

  • , face-normal ( A,B,C, it (B-A)x(C-B)). = 1 - , ( ).
  • , , ( - - " " ), . , .
+2

, , .off, , , . , , . , .

0

Source: https://habr.com/ru/post/1777745/


All Articles