# Thread: Spherical Lookat()

1. ## Spherical Lookat()

I need some help implementing an app that will allow the use of the arrow keys to move the "camara" aroung a object (located at the origin) in a spherical manner. That is, the camara is always positioned on the sphere shell defined by equation X^2 + Y^2 + Z^2 = R, (where R is the radius of the sphere).

2. ## Re: Spherical Lookat()

What u have to do is (in pseudo code):

translate u'r camera to the center of the sphere
Rotate around two axes with two angles
Translate inverse from the center of the sphere

Was it clear?

3. ## Re: Spherical Lookat()

I've just read myself and i was really no clear

So second chance:

Translate the camera to the center of the sphere
The camera is looking to its -Z axis.

So rotate around its X axis and around its Y Axis.
Now u have the good orientation but u are still centered in the sphere.

So you just have to do the inverse translation.

exemple:

glTranslatef(0.f, 0.f, -Distance_Camera_CenterOfTheSphere);
glRotatef(AroundYAngle, 0.f, 1.f, 0.f);
glRotatef(AroundXAngle, 1.f, 0.f, 0.f);
glTranslatef(0.f, 0.f, Distance_Camera_CenterOfTheSphere);

Hope that helped...

4. ## Re: Spherical Lookat()

Do you want to have the camera on ther surface of a sphere, looking at the origin?

If this is the case then you could use polar coordinates, where R is fixed, and use the arrows to change the two angles to set the camera position. As for looking at the origin, and since you already have the position of the camera, using gluLookAt you can set the look at point to be the origin.

Antonio www.fatech.com/tech

#### Posting Permissions

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