🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Lighting Position Difficulties

Started by
1 comment, last by zippo 24 years, 1 month ago
I''m trying to change the position of a diffuse light using keyboard controls. For example, if you hit "8", the light will move positive on the Y axis, "6" to move positive on the "X" axis, etc. (just look at the numpad, it''s obvious what I''m trying to do). I create three GLfloat variables; lx, ly, and lz, which hold the location on the x, y, and z axis the light is on. The light is set like this... GLfloat lx = 0.0f; GLfloat ly = 0.0f; GLfloat lz = 2.0f; GLfloat LightPosition[]= { 0.0f, 0.0f, 2.0f, 1.0f }; ...then in the InitGL function, I position the light... glLightfv(GL_LIGHT1, GL_POSITION,LightPosition); ...then, in WinMain, when the user presses "8", the position is changed thusly... if (keys[''8'']) { ly += 0.0001f; GLfloat LightPosition[]= { lx, ly, lz, 1.0f }; glLightfv(GL_LIGHT1, GL_POSITION,LightPosition); } ...as far as I can see, it should all work out properly. I set the increment/decrement of the light to one-millionths because it is made to increase/decrease while the user is holding down the key, so it''s slow enough for the user to see it happening, and not zip past the screen. However, I run it and weird things happen when I try using the keys. Like if I hit "8", which was supposed to increment the light on the Y axis just a smidge, it would jump to what appears to be the upper-left corner of the screen (keep in mind the light begins at the center of the screen). I''m really lost on this, and am not sure what''s happening. It increments/decrements much more than it should, and it seems to be moving along more than one axis at a time. I really don''t know what''s causing this. Any input would be appreciated. If you need more information, let me know. Thanks! zippo P.S.- Also, what do I use to make the key-pressed check work for the numbers on the numpad? With keys[''8''] it checks for the 8 above the letters, not the 8 on the numpad. Thanks!
Advertisement
I think you have to put
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);
in the drawglscene function and not in winmain, so your lightposition is updated every frame.

(this works for me)

Quo
I did that, but also had to put LightPosition into the DrawGLScene function as well. Works like a gem now, thanks!

zippo

This topic is closed to new replies.

Advertisement