Light moving with camera

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.

You need to make the call to glLightv() before calling gluLookAt().

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()

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.