PDA

View Full Version : Light moving with camera



gordon1
05-07-2007, 03:56 PM
hello,

The light is changing position when the camera moves.

Here is some code to give you an idea of what I'm doing.


glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,0,0, cameraDirection[0],cameraDirection[1],cameraDirection[2], 0,1,0);
glLightfv(GL_LIGHT1, GL_POSITION, lightPosition - cameraPosition);
render()


All objects render nicely in the scene, but the light source moves.

Can you tell me how to handle the glLight() function in this situation?

Thanks.

dpoon
05-07-2007, 04:23 PM
You need to make the call to glLightv() before calling gluLookAt().

gordon1
05-07-2007, 04:47 PM
Thanks, but that doesn't help. Even if I transform the light vector.

like so...


glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

v = lightPosition - cameraPosition
trans_vector(cameraSpace, v);
glLightfv(GL_LIGHT1, GL_POSITION, v);

gluLookAt(0,0,0, cameraDirection[0],cameraDirection[1],cameraDirection[2], 0,1,0);
render()

Korval
05-07-2007, 06:45 PM
glLightfv(GL_LIGHT1, GL_POSITION, lightPosition - cameraPosition);Don't do that. Well, not the subtraction.

What you want is to position the light in world-space. The call to gluLookAt already adjusted the MODELVIEW matrix into world-space. That is, any glVertex-equivalent calls will operate in world space at this point.