Sign in to follow this  
ElectroDruid

OpenGL Lighting and rotations

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
*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

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