PDA

View Full Version : Lighting with gluLookAt



laprej
04-14-2004, 08:57 PM
Hey all,

This is the first time I've had lighting on while calling gluLookAt, and I got some weird results. I know gluLookAt messes with the model-view matrix, I'm not exactly sure what it does, though. I wanted a directional light (the sun) at (1,1,1). It would come down over my right shoulder. It did before I put the gluLookAt in there. Is there any way to determine what the location should be if I want the same/similar lighting effect?

plasmonster
04-15-2004, 08:58 PM
Just remember that when you specify a light posiion, it is multiplied by the model view matrix. So, if you want your light vector unmodified, load an identity matrix before you set the position:

glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glLoadIdentity();
//set light position...
glPopMatrix();

mikeman
04-17-2004, 06:48 AM
Originally posted by RadicalHumility:
Just remember that when you specify a light posiion, it is multiplied by the model view matrix. So, if you want your light vector unmodified, load an identity matrix before you set the position:

glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glLoadIdentity();
//set light position...
glPopMatrix();Well,the light vector will be unmodified,but the whole scene will be rotated around the camera,thus the lighting will change when the camera pos/orientation change.What you must do is this:

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

SetCameraPos();//Use gluLookAt,glRotate,anything
SetLightPos();

glPushMatrix();
glTranslatef(objx,objy,objz);
DrawAnObject();
glPopMatrix();