How do I change a lights position during runtime?

Started by
3 comments, last by bigbrother2000 19 years, 3 months ago
Hi, I have a light in my 3d scene, however i want it to remain at the players position, using variables such as playerx,playery,playerz when initialising the light i set it to these values, although i need to reposition the light each render which is why the light is not moving with the player, i tried adding these lines of code into the render loop but wasn't sucessful, any ideas? d3dLight.Position.x = playerx; d3dLight.Position.y = playery; d3dLight.Position.z = playerz;
Advertisement
If I remember correctly, you must disable the light, update it, and then enable it again, Im sorry I cant give you an example, Im not in home right now.
Thanks for your help, i made d3dlight2 global so they work in the render function now, although changing the values on the position doesn't seem to change the position of the light.


I tried this in response to your suggestion but with no effect.

m_pD3DDevice->LightEnable(1, FALSE);
d3dLight2.Position.x = 10.0;
d3dLight2.Position.y = 50.0;
d3dLight2.Position.z = 10.0;
m_pD3DDevice->LightEnable(1, TRUE);


Any ideas on how to get the light positioned by a variable that can change during render?
Check the 'SetLight' function in the DX API documentation. You must call that function each time you change a property on the light structure.

- Kasper
thats brillant mate, works great now, thanks

This topic is closed to new replies.

Advertisement