PDA

View Full Version : normals directions

yakovm
03-20-2010, 05:19 AM
I have a mesh with defined normals for each its surfaces. I want to know if there is some way(preferably OnenGL function) to know if the normals directions are inside or outside for each surface

strattonbrazil
03-20-2010, 07:05 AM
By surfaces you mean polygons? Are the polygons planar? One normal per polygon face? If that's the case, you can always compute a tempNormal of the face and dotting it against your stored normal. If it's positive, they're facing the same direction out. If it's negative, your stored normal is facing in.

For example, a triangle with vertices v1, v2, and v3. Make a vector 'a' which is v1->v2 and vector 'b' which is v1->v3. 'a' cross 'b' is new normal.

yakovm
03-20-2010, 08:19 AM
I don't know if my polygons are concave or convex .Also winding of faces is not known.
Please tell me what you mean by calculating a tempNormal.

strattonbrazil
03-20-2010, 02:23 PM
If you're doing flat shading (such that the lighting uses the same normal across the polygon), it shouldn't matter if they're concave or convex. If they're non-planar, that's a whole other issue that's non-trivial to work with.

If you don't know the winding of the polygon, it gets even more tricky. Where did you get the polygon info (just curious)? I'm not sure there's a perfect way to figure that out. Is the mesh closed? If so, you can grab a polygon, calculate a normal as I described and intersect it with other polygons. If you find one that doesn't hit another polygon, it must be going off into space and therefore facing out. You now know the winding of it and can compare the normals. You can then look at its neighbors. If a neighbor polygon shares two points, it should have the same winding.

ex.

polygon with known winding (v1,v2,v3)

neighbor polygon has (v2,v3,v4)

The counter-clockwise winding for the first is v1,v2,v3 so the second must be (v3,v2,v4). You can try it on paper.

yakovm
03-20-2010, 03:16 PM

The mesh is not closed.
-------------