Results 1 to 3 of 3

Thread: Normal Vector problem

  1. #1
    Newbie Newbie
    Join Date
    Jan 2014
    Posts
    3

    Normal Vector problem

    Hello, I want to make a pyramid and light it properly. I use this code for the pyramid:
    void drawUnitPyramid()
    {
    glBegin(GL_POLYGON);
    glNormal3f(0,0,-1);
    glVertex3f(-0.5, -0.5,0);
    glVertex3f(-0.5, 0.5,0);
    glVertex3f( 0.5, 0.5,0);
    glVertex3f( 0.5, -0.5,0);
    glEnd();

    glBegin(GL_POLYGON);
    glNormal3f(2,0,-1);
    glVertex3f(-0.5, -0.5,0);
    glVertex3f(-0.5, 0.5,0);
    glVertex3f( 0, 0, 1);
    glEnd();

    glBegin(GL_POLYGON);
    glNormal3f(-2, 0, -1);
    glVertex3f( 0.5, 0.5,0);
    glVertex3f( 0.5, -0.5,0);
    glVertex3f( 0, 0, 1);
    glEnd();

    glBegin(GL_POLYGON);
    glNormal3f(0,-2,-1);
    glVertex3f(-0.5, 0.5,0);
    glVertex3f( 0.5, 0.5,0);
    glVertex3f( 0, 0, 1);
    glEnd();

    glBegin(GL_POLYGON);
    glNormal3f(0,2,-1);
    glVertex3f( 0.5, -0.5,0);
    glVertex3f( -0.5, -0.5,0);
    glVertex3f( 0, 0, 1);
    glEnd();
    }
    I use glEnable( GL_LIGHTING );
    glEnable( GL_COLOR_MATERIAL );
    glEnable( GL_LIGHT0 ); to enable the light but I doesn't light it good. I guess I have problem with the normal vectors but I made the math like 100 times and I think they are right. With other object like a cube it works properly. Could you help me please ?

  2. #2
    Senior Member Regular Contributor
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    394
    It's hard to help you without seeing all of your code, particularly the code that sets up the lighting. I notice that your normal vectors are not unit vectors. This is o.k. if you do a 'glEnable (GL_NORMALIZE)' before calling the 'draw' routine. Also, it would help if you posted picture(s) of the problem.

  3. #3
    Newbie Newbie
    Join Date
    Jan 2014
    Posts
    3
    Yes the problem looks like was in this "normalize". Thank you very much.

Similar Threads

  1. Normal Vector
    By trin82 in forum OpenGL: General
    Replies: 6
    Last Post: 11-19-2010, 08:14 AM
  2. Normal Vector Calculation
    By Phinehas in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 10-06-2010, 10:26 PM
  3. normal vector to a plane
    By Andy Suma in forum OpenGL: General
    Replies: 1
    Last Post: 08-25-2008, 06:22 PM
  4. Bidirectional Normal Vector
    By Asura in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-08-2006, 04:58 AM
  5. Normal and Vector of a line
    By Andrew Davey in forum OpenGL: General
    Replies: 4
    Last Post: 04-24-2004, 03:08 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