Results 1 to 4 of 4

Thread: simple question about normals

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2002
    Posts
    20

    simple question about normals

    i have some trouble with normals.

    i have an application drawing lot of quads, for each quads i needs its normal.

    so for each quad i have a loop that sounds like this :

    glBegin(GL_QUADS);

    glNormal3f(n0,n1,n2);
    glVertex3f(i,random,j);
    glVertex3f(i+1,random,j);
    glVertex3f(i+1,random,j+1);
    glVertex3f(i,random,j+1);

    glEnd();

    it is not exactly like this but it is the meaning .

    the problem is that the values of normal is always 0.

    what is wrong ?

    talking of math i know that a normal for a surface is :

    (v0-v1) x (v1-v2)

    where v0,v1,v2 are 3 vertices of the surfaces.
    in my case they are 3 vertices of my quad.

  2. #2
    Member Contributor
    Join Date
    Jan 2003
    Location
    UK
    Posts
    51

    Re: simple question about normals

    I recommend calculating the normal as:

    N = (v1 - v0) x (v2 - v0)

    where 'x' means the cross product.

  3. #3
    Senior Member Regular Contributor
    Join Date
    Oct 2002
    Location
    King George, Virginia
    Posts
    132

    Re: simple question about normals

    yes, your normal calculation is incorrect. use the right hand rule to remember which vectors to cross for a normal. point fingers of right hand along first vector, curl fingers toward second vector and thumb is your normal. vertices must be in counter-clockwise order for this to work.

    EDIT: this was meant for the thread creator, not you T

    jebus

    [This message has been edited by jebus (edited 01-10-2003).]

  4. #4
    Guest

    Re: simple question about normals

    You can use this function:

    void calcNormal(float v[3][3],float out[3])
    { int x,y;
    x=0;y=1;z=2;

    v1[x]=v[0][x]-v[1][x];
    v1[y]=v[0][y]-v[1][y];
    v1[z]=v[0][z]-v[1][z];

    v2[x]=v[1][x]-v[2][x];
    v2[y]=v[1][y]-v[2][y];
    v2[z]=v[1][z]-v[2][z];

    out[x]=v1[y]*v2[z]-v1[z]*v2[y];
    out[y]=v1[z]*v2[x]-v1[x]*v2[z];
    out[z]=v1[x]*v2[y]-v1[y]*v2[x];
    }

Similar Threads

  1. Question about normals calculation
    By Lefteris in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 11-21-2011, 05:19 PM
  2. Problems with simple cube and normals
    By imported_icepic1984 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-05-2011, 10:36 AM
  3. question about normals and shading
    By chronophile in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 02-22-2010, 03:03 AM
  4. simple question about vertex normals
    By airseb in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 02-01-2005, 02:17 PM
  5. Normals question
    By dabeav in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 03-29-2002, 07:55 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