View Full Version : Moving Lights
12-05-2005, 05:47 PM
Now heres a question.
I have a light source which I have position at 50,-100,50
Now everything worked fine until I implemented my camera system. Now I am calculating my normals manually. And when I rotate the camera(scene) the lighting effects the objects differently. Darkening and lightening the shadows. But I wan't the shadows to remain static as they are as the light is not supposed to be moving.
How would I position my light source? Will I have to position to according to the cameras current position and work it out from there? Because I am calling the lighting after the camera, I would have expected it to have already moved accordingly.
12-06-2005, 05:52 AM
The light's position is stored in eye coordinates, that is, relative to your camera/view. If you move your camera, but want the light to be static with respect to your world/objects, the light's position relative to the eye obviously isn't static anymore. You have to re-position the light once every frame.
You also have to set the light's position after applying the camera's modelview transformation, so the coordinates are correctly seen as world-space coordinates (as opposed to view-space coordinates).
it is not sufficent to set their positions once, in the beginning of your app, maybe outside the rendering loop, in case you have it.
the reason is they get transformed by the modelview matrix, just like any other vertex.
think to light position as the common GL vertex entity: since you pass verts (even if they don't change) every frame, you should pass lights positions too.
12-06-2005, 09:23 PM
I am positioning the lights after the camera class's modelview transformation which is why I was wondering as to why the movement of the camera appears to change that of the light when the light should appear as static. So instead of setting a static position for the light, I will give it a go of setting it to a position relative to the camera.
If that does not work. Then I will be back ;)
12-10-2005, 05:22 AM
Ok, so I have found out that it is not a problem with the lights actual position. It is when I rotate everything that the light changes on them. I am currently displaying a heightfield and I cant have a light constantly changing the normals when I rotate the 'camera' (world). How can I position the light in accordance the the rotation of the world. I can't rotate ambient/diffuse lights can I?
12-10-2005, 06:33 AM
Both the position and the direction of the light are affected by translation/rotation (current MODELVIEW matrix). They are then stored (now in coordinates relative to the eye) until the next time you reset them. So if you change the camera position and not reset the light's position, it will simply move along with the camera.
1) You have to issue the glLight(GL_LIGHTi, GL_POSITION, ...) call once per frame.
2) As the light's position and direction (as passed to glLight()) are transformed by the MODELVIEW matrix (just like vertices and normals), you have to issue the glLight calls with the correct MODELVIEW matrix in place.
if you want to have a light wich position and/or heading is fixed in relation to your geometry, then specify its parameters WITH your geometry...
i mean, once the mv matrix is set for the geometry, tell gl your lights.
instead, if you want your lights to be bound to the observer like say, a headlight, specify them when the mv matrix is set to identity.
otherwise, if you're confident you're doing it right already, then inspect the way you calculate normals: since they are vital for correct lighting, mayb you've inverted some vector magnitude, or some coordinate... remember opengl reference frame is right-handed.
is also useful to directly render your normals, as lines, arrows... it's up to you.
if your heightfield is not dynamic, then you don't have the need to recalc your normals...
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.