#103057 - Rajveer - Mon Sep 18, 2006 11:27 pm
hi guys. im applying a light onto a 3d object from a certain direction. now when i use glRotate to rotate my object, the lighting on the 3d object behaves as it should and shines in the right direction. however when i create my own matrix for rotations and push this into the objectview stack, lighting doesnt change. is this because i have to apply some changes to the texturestack matrix?
Last edited by Rajveer on Tue Sep 19, 2006 2:10 am; edited 1 time in total
#103079 - Rajveer - Tue Sep 19, 2006 1:46 am
to simplify, i should give an example:
say i have an object and light is shining on its right side. now with glRotate, if i rotate it 180 degrees in the y-axis then the left side faces the direction of the light and it shines properly. however if i do said rotation with my own rotation matrix, then it appears as if the light moves with the objects local space and gets moved with it.
#103080 - tepples - Tue Sep 19, 2006 1:50 am
Do you need a separate matrix to rotate the vertex normals? Can you look up glRotate() in the libnds source code to see how it works?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#103081 - Rajveer - Tue Sep 19, 2006 2:04 am
figured it out (kind of):
originally i was applying light to all objects near the beginning of the main loop (and before calling glMatrixMode(Texture...)). then during creating my scene i pushed the identity matrix into the modelview stack, multiplied this by my own matrix and then drew my object.
now i moved the glLight line in between pushing the identity into modelview and multiplying it by my own matrix: i think glLight gets multiplied by the modelview? not really sure, it works now, but id like to know why :-D
EDIT: it needs to be applied after a glLookAt call (makes sense now!) i was applying it one line before multiplying the identity by my own matrix, and one line after calling glLookAt (and 2 lines before pushing the identity into modelview...sorry if im confusing, its 2am here and i have the flu :S)