Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: normals directions

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    16

    normals directions

    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

  2. #2
    Member Regular Contributor strattonbrazil's Avatar
    Join Date
    Jun 2007
    Location
    Los Angeles, CA
    Posts
    306

    Re: normals directions

    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.

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    16

    Re: normals directions

    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.

  4. #4
    Member Regular Contributor strattonbrazil's Avatar
    Join Date
    Jun 2007
    Location
    Los Angeles, CA
    Posts
    306

    Re: normals directions

    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.

  5. #5
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    16

    Re: normals directions

    thank you for reply

    The mesh is not closed.
    -------------
    It is an academic project

  6. #6
    Member Regular Contributor
    Join Date
    Mar 2003
    Location
    Los Angeles
    Posts
    386

    Re: normals directions

    Quote Originally Posted by yakovm
    The mesh is not closed.
    If the mesh is not closed how do you even define 'inside' and 'outside'? If you can answer that question clearly in words, we (or you) should be able to do it mathematicaly.
    Am I doing your homework for you?

  7. #7
    Member Regular Contributor strattonbrazil's Avatar
    Join Date
    Jun 2007
    Location
    Los Angeles, CA
    Posts
    306

    Re: normals directions

    Heh, when you say it's an academic project, are you referring to me asking about it being closed? I meant does it have any holes? Can you move from one side of a face around to the other side?

    For example, a quad is not closed because from one point on the outside to the same point facing the other way. With a cube that is closed, if I pick a point facing outwards, I can't move around until I'm inside it. I'm sure there are better descriptions out there.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •