McBob
McBob

Reputation: 219

Retrieve Edges from Normal Vector

Im reading a Wavefront .obj file where the normals are provided. And I wish to calculate the tangent manually.

Is there any way I could retrieve the edge1 and edge2 that create the normal vector?

Upvotes: 0

Views: 191

Answers (2)

Calvin1602
Calvin1602

Reputation: 9547

See http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-13-normal-mapping/ for an introduction on tangent and bitangents; they are also additional references at the bottom of you want more details.

However, your question is about the normal.

OBJ is an indexed format, with one index for the positions, and one (different) index for the normals (and so on for all attributes).

So if you have a line like this :

f 0/10 1/11 2/12

, you have a Face that is a triangle (3 indices); the position indices are 0,1,2 (depends on your obj file, it's described in the header of the file). To get the positions, index the position array :

vec3 vertexPos1 = positions[0]; // or more generically, positions[faceIndices[i++]]
vec3 vertexPos2 = positions[1];
vec3 vertexPos2 = positions[2];

egdes are the deltas of the positions :

vec3 edge1 = vertexPos2 - vertexPos1; // order is important
vec3 edge2 = vertexPos3 - vertexPos1;

normal is the cross product of these edges :

vec3 normal = cross(edge1,edge2); // order important too
normalize(normal);

Upvotes: 0

egbutter
egbutter

Reputation: 790

If you have a single normal vector, there are an infinite number of choices for your two perpendicular edges -- any combination of vectors whose cross product gives you that normal vector.

You need to constrain your question by deciding what direction you want your tangent vector(s) to go. This http://support.microsoft.com/kb/131130 might help you backtrack your way there. HTH,

Upvotes: 3

Related Questions