PDA

View Full Version : Focusing the "camera" on an object ??!



TheBlob
05-07-2002, 06:19 AM
Hi!
I have a working camera, I can adjust with the mouse to look around.
But now, I want the camera to be focused on one object all the time, no matter where the camera is.
I use glRotatef on my whole scene to make a "camera"...



glRotatef(cAngle_x,1.0f,0.0f,0.0f);
glRotatef(cAngle_z,0.0f,0.0f,1.0f);

But how do I calculate cAngle_x and cAngle_z for my focused camera, if I have the postion of my Camera (x,y,z) and my Object(x,y,z)??
Anybody an idea???
Thanks in advance!

Stef
05-07-2002, 09:40 AM
How about something like this?

o_c(x) means distance between camera and object on the x-axis e.g. o_c (y)...

tan (angle_z) = o_c (x)/o_c(y)

tan (angle_x) = o_c(z)/o_c (xy)

o_c(xy) =
squareroot of (o_c(x)*o_c(x) + o_c(y)*o_c(y))

Maybe it works...but I'm not sure

Korval
05-07-2002, 11:05 AM
Replace those glRotatef calls with a single call to gluLookAt. That way, you can simply pass in the x,y,z coordinates of the object you want to track.

nexusone
05-07-2002, 11:08 AM
Do you want one side of this object to always face the camera?
Or do you want the camera to rotate around the object as if you where walking around the object looking at it?

http://www.opengl.org/discussion_boards/ubb/smile.gif



Originally posted by TheBlob:
Hi!
I have a working camera, I can adjust with the mouse to look around.
But now, I want the camera to be focused on one object all the time, no matter where the camera is.
I use glRotatef on my whole scene to make a "camera"...



glRotatef(cAngle_x,1.0f,0.0f,0.0f);
glRotatef(cAngle_z,0.0f,0.0f,1.0f);

But how do I calculate cAngle_x and cAngle_z for my focused camera, if I have the postion of my Camera (x,y,z) and my Object(x,y,z)??
Anybody an idea???
Thanks in advance!

Evil-Dog
05-07-2002, 06:33 PM
I agree with Korval
Simply use the x,y,z of the object you want to focus in the centerX, centerY, centerZ parameters of gluLookAt.
it works just fine.

-----------------------------------------
Evil-Dog
*Let's have a funny day*