View Full Version : Spotlights

02-20-2001, 09:25 AM
I'm trying to put a spotlight and a sphere on screen so that the latter rotates independently while the former's focus stays on the same area of the sphere's surface. In theory, this should look like the sphere isn't even moving, but it isn't working out that way. There's obviously light coming from somewhere, but it seems like the source was rotating and moving randomly. I'm using the same variable for incrementing all angles, so the same phases repeat every 360 degrees, but I can't think of a reason for this undefined light trajectory.

I tried putting a cone at the same place where the light source is supposed to be, and it does stay motionless exactly like it's supposed to. Yet the light still moves, gradually shifting between lighting the whole sphere and showing only ambient light. The only thing I'm certain of is that the light source is not following the sphere's rotation in any way; lighting in the same areas changes. Here are some of the key areas of my code; I got exactly the same results without providing a direction for the spotlight, so that's the version I'm using here:


glTranslatef(0.8, 0.8, -2.0);

glTranslatef(-0.4, -0.4, -5.0);
glRotatef(turn, 0.2, 0.5, -0.3);
// "turn" grows by 2 every 50 ms.


glLightfv(FSource, GL_POSITION, @FLocation);
// FLocation: [0, 0, 0, 1.0]
glLightfv(FSource, GL_DIFFUSE, @FDiffuse);
glLightfv(FSource, GL_SPECULAR, @FSpecular);

02-20-2001, 07:02 PM
Lights are translated and rotated the same way as vertices. Not a very long answer but hopefully can it be of some help.

02-20-2001, 07:53 PM
Why do you update light's position each frame?
If you need static light you may do it once in initialization.


02-21-2001, 09:53 AM
I'm planning to make the light rotate after I get past this initial testing phase. Good idea, though... it just didn't work. :-(

Still no success. I tried stopping the rotation, and the light no longer followed, (it didn't show at all at this stage). But even if I could make the light show, I would still have to able to make the light move around later on.

I have a demo of this problem available at: http://www.netsonic.fi/~jade6/3Demo/LGDemo.exe . Please help, this gets frustrating. :-(

[This message has been edited by jade6 (edited 02-23-2001).]