Normals to triangles

This is a discussion on Normals to triangles within the Game Programming forums, part of the General Programming Boards category; I wish to construct normals to a surface from triangles. I have the triangulation and can calculate the normals based ...

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    41

    Normals to triangles

    I wish to construct normals to a surface from triangles. I have the triangulation and can calculate the normals based on the cross product of the edges. However there is an issue with direction. I wish all the normals to point say in the case of a sphere outwards. How do programmers in reality ensure that these normals are in the same direction....

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Just be consistent with the direction you go around the triangle (clock-wise or counter clock-wise).

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    To be more specific: the cross product always give a right-handed system: if your thumb (on the right hand, of course!) goes along the first vector, and your index finger goes along the second, then the normal you get will be the direction the rest of your fingers point. This means that if you want to point outwards, you should go clockwise and to point inwards go counterclockwise.

  4. #4
    Registered User
    Join Date
    Jul 2005
    Posts
    41
    Sure you say there there is clockwise and counter-clockwise. But given a face, and its verticies the decision over the edges is arbritary? There is no rule governing this per se?? since I just have face information??

  5. #5
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Each graphics API has set conventions. In openGL for example, you can set which side is the face by using glFrontFace(). I think the default is counter clockwise (GL_CCW)

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    Most APIs default to CCW. Direct3D defaults to D3DCULL_CCW. All of my meshes use CCW. As long as you don't mix the winding order across meshes you will be ok. If you mix winding orders then your renderer is going to be a jumbled mess.

    In essence the normals of sphere vertices are their normalized model coordinates. Since spheres are extensions of a simple unit sphere around 0,0,0 then you have vectors going from 0,0,0 to the vertex in question. Since a vertex is also a vector you could just normalize the vector created by the translation from 0,0,0 to the vertex position and use that as the normal. Since any value minus 0 is itself then it follows that the sphere vertex positions are just extensions of their normals. To further smooth the normals you can do normal averaging across the sphere. But for a sphere there is no need to create 2 edge vectors, cross them, and then normalize for each triangle in the sphere.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 07-08-2009, 10:13 AM
  2. Drawing triangles in C#
    By John_L in forum C# Programming
    Replies: 2
    Last Post: 03-15-2008, 08:48 AM
  3. Replies: 6
    Last Post: 11-12-2005, 10:57 AM
  4. normals for triangle strips (oGL)
    By Perspective in forum Game Programming
    Replies: 8
    Last Post: 04-01-2003, 05:59 PM
  5. Equilateral Right Triangles
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-06-2002, 02:32 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21