# Looking at a Specified Point

• 03-31-2006
gpr1me
Looking at a Specified Point
In my little game i want to be able to look at a specific point in my 3d scene. If my camera is at (0, 0, 0) and i want to be able to look at (10, 0, 20) how would i do this.

I understand that i need to change the gluLookAt() function. Which basically sets the camera's (eye, center, up). The Eye is the location of the camera, center is the direction the camera is pointing and up is defining what up is. So would i have to do something like this?

gluLookAt(0.0, 0.0, 0.0, 10.0, 0.0, 20.0, 0.0, 1.0, 0.0);

This will Make
eye.x = 0.0, eye.y = 0.0, eye.z = 0.0
center.x = 10.0, center.y = 0.0, center.z = 20.0
up.x = 0.0, up.y = 1.0, up.z = 0.0

That means the camera will be at the origin and looking at the point (10.0, 0.0, 20.0). Am i correct?

So if i want to look at a specific point all i would have to do is change the center to that point?
• 03-31-2006
BobMcGee123
The eye point can only be a single unit away from the camera.

Code:

```Vector3 lookat = Vector3(10,0,20) - Camera.Position; //in this case (0,0,0) lookat.normalize(); Vector3 eye = Camera.Position + lookat; void Vector3::normalize() { float len = sqrt(x^2 + y^2 + z^2); if(len > .00001f) { len = 1.0f / len; x *= len; y *= len; z *= len; } }```