Jump to content
  • Advertisement
Sign in to follow this  
ElectroDruid

OpenGL Lighting and rotations

This topic is 4823 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Mmmkay, this is probably a total schoolboy error on my part. I'm looking for ideas about what I might have done wrong. I've got what basically amounts to a spinning cuboid, drawn in immediate mode, in front of a fixed camera. I'm using glRotatef to spin the object, and I'm using common or garden OpenGL lighting (one light source which for the purposes of my problem is in a fixed spot somewhere off to one side of the camera). I calculate the normals for the corners of the front face of the cube by various cunning means and I'm satisfied it works fine (at least until the front face spins out of view, after which I've not been able to check because the camera is in a fixed spot). The back face is parallel to the front face, so I just take each of the 4 normal vectors and negate them, applying them to the corresponding points on the back face. Hopefully that makes sense, if not I'll try again with some ASCII art. My problem is that when the cube rotates towards 180 degrees, the lighting on the back face seems the wrong way round, as if the light source is coming from (say) the top left as opposed to the bottom right. Does anyone know what could cause this? I've seen lights which appear to move with the camera before, and lights which appear to rotate with the model, but this doesn't seem to be either of those. Here's hoping I explained that well enough... :o)

Share this post


Link to post
Share on other sites
Advertisement
*youre only calculating the normals once in the model creation phase + not each frame
*your repositioning the lights every frame after u position the camera

try just one side of the vube
glNormal3f(0,0,1)
g;Vertex3f(-1,-1,1)
g;Vertex3f( 1,-1,1)
g;Vertex3f( 1, 1,1)
g;Vertex3f(-1, 1,1)

does it light cottrvtly when u spin it aroun (might need to turn on twosided lighting)

Share this post


Link to post
Share on other sites
I think I've got it fixed. Negating the normal vectors for the front face didn't quite work (my cube isn't exactly a cube: the normals for each vertex of the front face aren't parallel). I had to rotate each front face normal 180 degrees through the axis of rotation to get the back vectors, and do some weird compensating stuff depending on which axis I'm rotating around (the cube's local x or local y)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!