Results 1 to 2 of 2

Thread: Averaging normals

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2000
    Location
    albuquerque, new mexico, usa
    Posts
    1

    Averaging normals

    I simply cannot get normal averaging to work. I was under the impression that normal averaging in triangle strips occurs automatically. glShadeModel = GL_SMOOTH, and that's how it was explained to me.

    I was thinking perhaps this is not something GL does automatically? If so, how do I average normals mathematically at an intersection of 2 or 4 vertices?

    Here is my display-list for my object. If anyone has suggestions, please email efesar@nmia.com. Eternally grateful.

    ---

    //////////////////////////////////////////////////////////////////
    // MyGLbackplane()
    // Our cyan backplane display list
    //////////////////////////////////////////////////////////////////
    void CMyGL::MyGLbackplane()
    {
    float specref[] = {1.0f,1.0f,1.0f,1.0f};
    float amref[] = {0.5f,0.5f,0.5f,1.0f};

    float ellX = 1.1f;
    float ellY = 0.75f;

    glNewList(backplane,GL_COMPILE);

    glPushAttrib(GL_ENABLE_BIT );
    glDisable(GL_CULL_FACE);
    glShadeModel(GL_SMOOTH);

    // set the material for our backplane
    glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,specref );
    glMateriali(GL_FRONT_AND_BACK,GL_SHININESS,64);
    glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFF USE,amref);

    float jinc = 5.0f;

    // a grid of 66x66 little quads (for specularity)
    for (float ii=0.0f;ii < 32.0f; ii++)
    {
    glBegin(GL_TRIANGLE_STRIP);
    for (float jj=0.0f;jj<=360.0f; jj=jj+jinc)
    {
    float v1[3][3],v2[3][3];
    float out[3];

    v1[0][0] = ellX*(float)cos( DegToRad(jj) ) * ii;
    v1[0][1] = ellY*(float)sin( DegToRad(jj) ) * ii;
    v1[0][2] = 100.0f -(float)cos( DegToRad(ii) ) * 100.0f;

    v1[2][0] = ellX*(float)cos( DegToRad(jj+jinc) ) * (ii);
    v1[2][1] = ellY*(float)sin( DegToRad(jj+jinc) ) * (ii);
    v1[2][2] = 100.0f - (float)cos( DegToRad(ii) ) * 100.0f;

    v1[1][0] = ellX*(float)cos( DegToRad(jj) ) * (ii+1.0f);
    v1[1][1] = ellY*(float)sin( DegToRad(jj) ) * (ii+1.0f);
    v1[1][2] = 100.0f - (float)cos( DegToRad(ii+1.0f) ) * 100.0f;

    v2[0][0] = v1[0][0];
    v2[0][1] = v1[0][1];
    v2[0][2] = v1[0][2];

    v2[1][0] = v1[1][0];
    v2[1][1] = v1[1][1];
    v2[1][2] = v1[1][2];

    v2[2][0] = ellX*(float)cos( DegToRad(jj+jinc) ) * (ii+1.0f);
    v2[2][1] = ellY*(float)sin( DegToRad(jj+jinc) ) * (ii+1.0f);
    v2[2][2] = 100.0f - (float)cos( DegToRad(ii+1) ) * 100.0f;

    CalcNormal(v1,out);

    glColor3f(0.7647f,0.4353f,0.1059f);

    glNormal3fv(out);
    glVertex3fv(v1[0]);

    glNormal3fv(out);
    glVertex3fv(v1[1]);

    glNormal3fv(out);
    glVertex3fv(v1[2]);

    CalcNormal(v2,out);

    glNormal3fv(out);
    glVertex3fv(v2[2]);

    }
    glEnd();
    }

    glPopAttrib();

    glEndList();
    }

  2. #2
    Senior Member OpenGL Guru Humus's Avatar
    Join Date
    Mar 2000
    Location
    Stockholm, Sweden
    Posts
    2,342

    Re: Averaging normals

    GL_SMOOTH tells OpenGL to interpolate between colors, it has nothing to do with normals. If you would use GL_FLAT instead you would get an constant color.

    To get an average of the normalvectors you just need to add them together and normalize.

    Pseudo:
    AvarageNormal = (Normal1 + Normal2 + Normal3) / length(Normal1 + Normal2 + Normal3);

Similar Threads

  1. Averaging normal vectors for TORUS
    By Bert De Craene in forum OpenGL: Basic Coding
    Replies: 11
    Last Post: 08-01-2006, 07:04 AM
  2. normal averaging
    By Julio in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 06-16-2003, 01:05 PM
  3. 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
  4. Averaging normals
    By Questions Burner in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 01-06-2002, 08:49 PM
  5. averaging face normals
    By in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 02-23-2000, 11:48 PM

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