Reputation: 5
I have quite a lot of triangles with coordinates such as below. I want to get the normals of each vertex so I can use it for calculating light.
I have the code for a cube normals and understand that but don't really know how to go about converting(calculating) these to normals. I would just like some direction on where to go from here.
//TRIANGLE 1
0.0f, -0.774f, 0.49f, //6
0.0f, -1.0f, 0.51f, //7
0.156f, -0.982f, 0.47f, //8
Upvotes: 0
Views: 1715
Reputation: 2928
Calculating normals can be done using the Vector Cross Product. You take two vectors, and the cross product gives you a normal vector.
The two vectors can be obtained by taking the coordinates of your triangle, and subtracting one vertex coordinate from the other two vertices.
That is:
vec0 = vert2 - vert0
vec1 = vert1 - vert0
Which vertices you should subtract from one another depends on which direction the normal should point.
See the wikipedia article on how to compute the cross product. At the bottom of the section you'll see a matrix which shows how to calculate each component of the normal vector.
Upvotes: 1