Beginning OpenGL... first problem encountered!
I've been learning OpenGL, made my own 3D graphics format and have started my own engine. No problems until now, every mesh I load has flipped normals... if I flip them back, it is still wrong in the game. My 3DS loading code (got from someone's website) said that one of the bugs is that it mis-calculates normals. The rest is working fine. I don't know where to start, can someone help me figure out what a normal is and how to calculate it or how I can retrieve it from a 3ds file for the converter. My file format has no problems, I think it is the converter's fault but don't know where to start.
This has been holding me up... well, that and school.
Thanks in advance~ John DiSanti
NeHe's tutorials are a good intro to normals NeHe Tutorial 7.
A normal is a vector (made out of an x,y, and z) that points in the direction the polygon is facing. You could think of your nose as a normal to your face. Generally each face will have a seperate normal. If you want to calculate normals, start by researching "Cross-Products."
A normal is a vector (made out of an x,y, and z) that points in the direction the polygon is facing. You could think of your nose as a normal to your face. Generally each face will have a seperate normal. If you want to calculate normals, start by researching "Cross-Products."
A normal is simply a vector that describes the orientation of a surface. Face normals are used to describe the orientation of a face (triangle, quad, whatever; as long as it lies on a plane) while a vertex normal is used to describe the orientation of a vertex.
For face normals, the calculation is simple. If you have 3 points of the face, p0, p1 and p2, you can calculate the face normal as the cross product of the vectors forming 2 of the sides of the triangle formed by p0, p1 and p2.
See here for a description of the cross product.
Note that you must normalize the vector to unit length before you can use it as a normal. This means to calculate the length (sqrt(x^2 + y^2 + z^2)) then divide each component (x,y,z) by this length.
Now, where normal flipping comes into play is this: each plane can be defined by 2 normals, which are inverses of each other. If you calculate the normal as side1 x side2 you end up with one normal orientation and with side2 x side1 you end up with the other. The cross product follows what is called the Left Hand Rule (google it).
To calculate a normal for a specific vertex, rather than a face, you need to calculate the normals for all of the faces that share the vertex, then calculate the average of these normals. Sum all of the components (x,y,z) and divide each by the number of faces. Remember to re-normalize to unit length before you use it. As long as the face normals are outward-pointing, the vertex normal should be outward pointing. If your normals are flipped, you can simply multiply each component by -1 or change the order in which you calculate the cross product.
As far as the 3DS format, I honestly can't help you there.
For face normals, the calculation is simple. If you have 3 points of the face, p0, p1 and p2, you can calculate the face normal as the cross product of the vectors forming 2 of the sides of the triangle formed by p0, p1 and p2.
side1 = p2-p0side2 = p1-p0normal = side1 x side 2
See here for a description of the cross product.
Note that you must normalize the vector to unit length before you can use it as a normal. This means to calculate the length (sqrt(x^2 + y^2 + z^2)) then divide each component (x,y,z) by this length.
Now, where normal flipping comes into play is this: each plane can be defined by 2 normals, which are inverses of each other. If you calculate the normal as side1 x side2 you end up with one normal orientation and with side2 x side1 you end up with the other. The cross product follows what is called the Left Hand Rule (google it).
To calculate a normal for a specific vertex, rather than a face, you need to calculate the normals for all of the faces that share the vertex, then calculate the average of these normals. Sum all of the components (x,y,z) and divide each by the number of faces. Remember to re-normalize to unit length before you use it. As long as the face normals are outward-pointing, the vertex normal should be outward pointing. If your normals are flipped, you can simply multiply each component by -1 or change the order in which you calculate the cross product.
As far as the 3DS format, I honestly can't help you there.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement