Advertisement

calculating normal vectors for a triangle strip / fan...

Started by April 04, 2003 07:23 AM
3 comments, last by James Trotter 21 years, 11 months ago
ok, I''m loading an MD2 model, and I''m taking advantage of the glCommands for speed, and my rendering code looks like this:
  
if (type == 0) {
	glBegin(GL_TRIANGLE_STRIP);	// Start a triangle strip

	for (loop = 0; loop < index; loop++) {	// Loop through the indices

		glTexCoord2f(vertexlist[loop].u, vertexlist[loop].v);	// Set the texture coordinates

		glVertex3fv(vertexlist[loop].vertex.v);	// And draw the vertex

	}
	glEnd();	// End the triangle strip

} else {
	glBegin(GL_TRIANGLE_FAN);	// Begin a triangle fan

		for (loop = 0; loop < index; loop++) {
			glTexCoord2f(vertexlist[loop].u, vertexlist[loop].v);	// Set the texture coordinates

			glVertex3fv(vertexlist[loop].vertex.v);	// And draw the vertex

		}
	glEnd();	// End the triangle fan

}
  
I''m wondering if anyone has some code that will calculate the normal vector of each of the surfaces, or vertices in the strip and/or fan. Thank you!!
You can calculate the normal for any surfact given 3 points on a plane (i.e. your surface).

Given vx where x is a vertex on the current face,

(v1 - v2) × (v2 - v3)

p.s. × is the cross product.

edit:
You'll also want to normalise the resulting vector. google will help you do that.

[edited by - Juicy on April 4, 2003 8:53:54 AM]
I like pie! - weebl.
Oneiric - Another graphics engine in the works.
Advertisement
Yes, I know how to calculate a normal based on 3 points, what I''m really wondering is which 3 points??
Aha! I have it working for surface normals. But does anyone have a good way to do it for every vertex?

Thanks
Sum up all face normals that use one vertex and then normalize it.

As a sidenote : glCommands in MD2 is not so usefull thing. It''s actualy much faster to connverta model to plain indexed triangle list[and use some kind of vertex cache optimization] and draw model in single call to vertex array.

You should never let your fears become the boundaries of your dreams.
You should never let your fears become the boundaries of your dreams.

This topic is closed to new replies.

Advertisement