Skip to main content
GameDev.net gamedev.net
🔒 Locked

spotlight

Started by baris david ekinci Feb 24, 2005 at 7:55 AM 1 replies 1k views
Original Post
baris david ekinci
baris david ekinci
Hi, i have problem modeling a spotlight that tracks the camera. I want the spotlight to be always at the same position and facing the same direction as the camera. for this i tried te following: 1.process input and update the camera position/orientation. 2.spotlightposition = cameraposition (then i call glLightfv(GL_LIGHT0,GL_POSITION,Position); ) 3.spotlightdirection = cameradirection ( calculated with lookat-position) (then i call glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,direction); ) the position part seems to be working properly but the direction stuff seems to be inverted: when the camera rotates left, the spotlight seems to be rotating right, etc. i suspect the problem is with the way spotlight direction vector is passed in glLightfv(...) but can't seem to figure it out. if needed, i can post the code as well.
baris david ekinci
baris david ekinci
At first, didn't have a clue what you were saying ( i'm still new to OGL ), but with a bit of research i think i get what you mean. I think the vector you mentioned is the current z-direction vector of the camera. So,

GLfloat matrix[16];
glGetFloatv(GL_MODEL_VIEW_MATRIX, matrix);

then,
matrix[2][0] matrix[2][1] matrix[2][2]

or,
matrix[0][2] matrix[1][2] matrix[2][2]

should give me the current z-orientation of the camera. I will try this ( I'm currently away from my computer )

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.