Lighting and rotations

Started by
1 comment, last by ElectroDruid 18 years, 10 months ago
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)
"We two, the World and I, are stubborn fellows at loggerheads, and naturally whichever has the thinner skull will get it broken" - Richard Wagner
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)
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)
"We two, the World and I, are stubborn fellows at loggerheads, and naturally whichever has the thinner skull will get it broken" - Richard Wagner

This topic is closed to new replies.

Advertisement