I am creating a program to draw 3D terrain. I draw individual contours at different heights and use a list of GL_TRIANGLES to join the contours and make the 3D terrain. I am having difficulty calculating the normals for the triangle list however and am getting some very weird effects.
Currently the was I calculate the normals is to take two lines of the triangle
Math looks correct to me.
You could put the vertices into triangle strips, or a vertex array: then for every vertex you’ll want to add all normals from triangles that share the vertex and normalize the result. Otherwise the surafce will look blocky.
I used to have much trouble with calculating normals, until i made Vector a class and overloaded operators. Now i do (V1-V2)*(V2-V3) and thats all. Try it.
I haven’t tried it with just a couple of polygons as I’ve been developing the program for a while builing it up from wireframe, so I already had a fairly complex program when I came to lighting the solid model.
I have ordered the triangles so that the co-ordinates are always listed in anti-clockwise order. Is this what you mean by “the right hand rule” ?
Yes, glEnable(GL_NORMALIZE) will normalize the normals. So, that shouldn’t be the problem, either.
Could you post a link so we can see what weird effects you are getting or email a screenshot to me? Maybe it doesn’t look as good because the normals are basically per surface (in a sense) rather than per vertex as your cross product will return the same direction vector for each vertex of the triangle. Thereby it does not look as continuous and seems to have sharper edges than you want.