PDA

View Full Version : How can I get the vector from camera to object?



BigShooter
11-04-2003, 12:24 PM
I'd like to implement a simple shader that will color my triangles based on the angle between the gaze axisi of the camera and surface normal. I know how to do the normals and get angle between two vectors, but how can I knwo the 'gaze axis' of camera vector? Also how can I querry the current position of opengl camera?

Thank you,
Luke

11-07-2003, 12:01 PM
void gluUnProject(x,y,z,modelview,
projection,viewport,px,py,pz);

mogumbo
11-07-2003, 01:54 PM
You can usually use the inverse of your modelview matrix to get the gaze axis and the camera position.

mvi = inverse modelview matrix
camera pos = {mvi[12], mvi[13], mvi[14]}
gaze axis = {mvi[8], mvi[9], mvi[10]}