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

1. ## 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"...
Code :
```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???

2. ## Re: Focusing the "camera" on an object ??!

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

3. ## Re: Focusing the "camera" on an object ??!

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.

4. ## Re: Focusing the "camera" on an object ??!

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:
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"...
Code :
```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???

5. ## Re: Focusing the "camera" on an object ??!

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*

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•