PDA

View Full Version : Normal Vector problem



hbkmad
01-20-2014, 02:42 PM
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 ?

Carmine
01-20-2014, 04:00 PM
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.

hbkmad
01-21-2014, 03:43 AM
Yes the problem looks like was in this "normalize". Thank you very much.