Lighting & Transformations

Hi all…
Ok. Here’s my problem:
I’m doing sort of a game whice includes space flight, asteroids, starships, space station etc… Anyway, I’m got my asteroids and my camera (pseudo code soon to come) and I’m trying to add a directional light but it rotates according to the asteroids which is quite annoying… What I want is to have the light at a fixed direction and the rest - rotating (btw: the camera can also move…).

so here’s the code (of the drawing routine);

glRotate(camera rotation (x,y,z));
glTranslate(-camera position);
glLightfv(LightPosition) //which is 1,0,0,0
for(i=0 i<number_of_asteroids i++)
glTranslate(asteroid position);
glRotate(asteroid rotation (x,y,z));

thanks in advance

The light’s position is transfomed by the modelview matrix like a vertex.
Do this and the light position is fixed:
glRotate(camera rotation (x,y,z));
glTranslate(-camera position);

I’ve tried it already… It simply won’t work The asteroids rotate and the light also rotates with them instead of staying fixed. Probably because the light is multiplied by the Matrix when the actual drawing occurs ??? (a wild theory…)
Still I’m stuck.

Take little steps and try it with a simple working example (e.g. from the redbook samples) to figure it out.
If that’s working on your implementation, than do it the same way in your program and all is well.

If you don’t be that patient, just check all places where you put the light position into your program and fix the matrix at that point to contain the identity. If that’s not making the light completely static, than something else is broken in your program.