# Focusing the "camera" on an object ??!

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???

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

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.

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?

Originally posted by TheBlob:
[b]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”…

[quote]

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???