Jump to content
  • Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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(...).

Thank you in advance!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!