Sign in to follow this  

Camera Using Spherical Coordinates

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this