Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: How to autogenerate Normals?

  1. #1
    Guest

    How to autogenerate Normals?

    I've read through the docs and manuals i've found and they say something about autogenerating normals for better lighting - but where is this doc, manual or tutorial? Or does anyone have code for autogenerating normals? (glNormal3f...)
    Ls

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Dec 2007
    Posts
    1,077

    Re: How to autogenerate Normals?

    I think glEnable(GL_AUTO_NORMAL) that is. Building normals isn't too complicated though, if you just want normals for a face, the normal is simply a normalized cross-product of two edges-vectors (?).

  3. #3
    Senior Member Regular Contributor
    Join Date
    Nov 2000
    Location
    Dunblane, Scotland
    Posts
    333

    Re: How to autogenerate Normals?

    if you just want normals for a face, the normal is simply a normalized cross-product of two edges-vectors
    What I want to know is that the two edge vertices form a plane, lets say a horizontal plane, the normal could point up or down so how does the cross product calculate which direction?



    [This message has been edited by Tim Stirling (edited 11-28-2000).]
    Reality is for idiots only the best over come it!

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: How to autogenerate Normals?

    It depends on the order you specify the edges. Say you have a function that takes 3 vertices and determines the face normal. If you call the function like so GetNormal(v1, v2, v3); the normal will face one direction, but if you call it using GetNormal(v2,v1,v3) it'll point in the opposite direction. The pseudo-code for the GetNormal function would look something like so...

    Code :
    Vector GetNormal(Vector v1, Vector v2, Vector v3)
    {
        Vector temp1, temp2;
        Vector normal;
     
        temp1 = v1 - v2;
        temp2 = v2 - v3;
     
        // assume * represents cross-product
        normal = temp1 * temp2;  
        normal.Normalize();
     
        return normal;
    }


    [This message has been edited by Deiussum (edited 11-29-2000).]
    Deiussum
    Software Engineer and OpenGL enthusiast

  5. #5
    Member Contributor
    Join Date
    Aug 2000
    Location
    Epinay sur Seine, France
    Posts
    67

    Re: How to autogenerate Normals?

    Note that use glEnable(GL_AUTO_NORMAL) is not a good idea : it may eat lots of CPU/GPU cycles....
    Use it for test/debug stuff to see how openGL works with normals then use normals table.
    One life for hate , one eternity for love [img]/forum/images/%%GRAEMLIN_URL%%/smile.gif[/img]

  6. #6
    Guest

    Re: How to autogenerate Normals?

    What do you mean with normals table?

  7. #7
    Guest

    Re: How to autogenerate Normals?

    the comment in the snippet of code is wrong. it is not a dot product it should be cross product.

  8. #8
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: How to autogenerate Normals?

    Originally posted by hneed:
    the comment in the snippet of code is wrong. it is not a dot product it should be cross product.
    Oops. Fixed now. Not sure where my brain was when I typed that in.
    Deiussum
    Software Engineer and OpenGL enthusiast

  9. #9
    Senior Member OpenGL Pro
    Join Date
    Dec 2007
    Posts
    1,077

    Re: How to autogenerate Normals?

    If you stored the poly counterclockwise, take the crossproduct of to vectors that start at one vertex of it, and it will point towards the direction opengl also uses.

  10. #10
    Junior Member Newbie
    Join Date
    Oct 2000
    Posts
    13

    Re: How to autogenerate Normals?

    glEnable(GL_AUTO_NORMAL); doesn't work.
    Is there anything else to do for autogenerated normals ?

    And what's with the glNormal(); calls?

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 6
    Last Post: 04-14-2004, 10:07 PM
  2. vertex normals or face normals
    By infinitecmdz in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-20-2004, 09:35 AM
  3. Replies: 0
    Last Post: 07-26-2002, 03:10 PM
  4. is it possible to have vertex normals or even face normals using triangle strips nt
    By wildeyedboyfromfreecloud in forum OpenGL: Advanced Coding
    Replies: 63
    Last Post: 03-19-2002, 11:42 PM
  5. Face Normals vs. Vertex Normals
    By detzel in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 03-05-2001, 10:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean