Sign in to follow this  
megatron244

Moving lightings

Recommended Posts

Hi, I'm rendering a scene with a positional light source. Is there a simple way to move the light source along with the entire environment. That is, suppose I'm rendering a few objects, and I move the camera around them. I want the light to stay in the same position _relative_ to the objects. Thanks in advance, Vince

Share this post


Link to post
Share on other sites
I think you have to put the light in same matrix as the world.
I'm not sure, since I'm just a beginner myself. So I'd like to know too. :)

Share this post


Link to post
Share on other sites
Yeah, I'm pretty sure that the light's position gets transformed using the current world matrix when the position is set.

Pseudo code
set matrix mode to modelview
update matrix in order to move model
set light position
draw model

Share this post


Link to post
Share on other sites
If you have defined your light position in an init routine of the scene and if you don't update the lights position, than it will stay fixed to the camera.

In order to have a light source that stays at a fixed position inside your world (not fixed to camera) you have to call

glLightfv(lightID, GL_POSITION, position);
glLightfv(lightID, GL_SPOT_DIRECTION, spotDirection);

after you set your camera position (using gluLookAt for example).
Best update the position (even if it is not changing!) before you start rendering your objects.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this