# Camera Using Spherical Coordinates

This topic is 662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all,

I am trying to make a camera using spherical coordinates, as the title implies. I believe I have a problem with the up vector, but here is the code anyways:

        float theta = (gs.theta * (float) PI)/180;
float phi = (gs.phi * (float) PI)/180;
float eyeX = gs.vDist * ( (float) cos(gs.theta) ) * ( (float) sin(gs.phi) );
float eyeY = gs.vDist * ( (float) sin(gs.theta) ) * ( (float) cos(gs.phi) );
float eyeZ = gs.vDist * ((float) cos(gs.phi));

eye = new Vector(eyeX, eyeY, eyeZ);
center = gs.cnt;

Vector V = eye.subtract(center).normalized();

up = new Vector( (float) cos(gs.theta), (float) sin(gs.theta), 1);

gs is a Global State variable that houses all the required information.
gs.theta is the angle between the point projection on the vertical plane and the x-axis, and gs.phi is the angle with z-axis. gs.vDist is the distance between the origin and the point on the sphere (radius).

The camera should be able to move in any direction using left click drag. I understand that in order to do that, z coordinate of the up vector cannot be 1, but should be adjusted accordingly. I just don't know what it should be.

What changes should I make in order for it to work?

Just as the side note, all the parameters are later added to gluLookAt(...).

1. 1
Rutin
45
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 11
• 13
• 10
• 12
• 10
• ### Forum Statistics

• Total Topics
633002
• Total Posts
3009822
• ### Who's Online (See full list)

There are no registered users currently online

×