# moving the camera using spherical coordinates

hello…

I am making a JOGL aplication, and would like to allow the user to move the camera in a way that the user is allways looking at the objects ( that are drawed at the origin.

I am trying to do that using the GLUlookAt function, transforming the spherical coordinates into cartesian coordinates:

``````myGLU.gluLookAt(raioCamera*Math.sin(tetaCamera)*Math.cos(fiCamera), raioCamera*Math.sin(tetaCamera)*Math.sin(fiCamera), raioCamera*Math.cos(tetaCamera), 0, 0, 0, 0, 1, 0);
``````

That way, the user would increment or decrement the value of raioCamera, tetaCamera and fiCamera (That represents the value of the 3 coordinates of the spherical system), and then the gluLookAt function would be called using those values, but frist been transformed to the cartesian system.

Changing the value of raioCamera and tetaCamera produces the desired results, but changing the value of fiCamera mess things up…

Anyone can help me with this?

PS. If u can’t understand what I wan’t to do or what my problem is please tell me that I will try to explain it better, since the text above seens a little confusing even to me

Here’s my configuration I’ve used some time ago:

Assuming R is the radius, Theta is the angle with the horizontal plane, and Phi is the “left-right” angle:

Y = R * sin(Theta)
X = R * cos(Theta) * cos(Phi)
Z = R * cos(Theta) * sin(Phi)

I’ve considered OpenGL coords. Let me know if this helps.

Cheers,
Cosmin.

The problem is the up-vector (7th to 9th parameter to gluLookAt).

As long as you rotate horizontally (by modifying the your Theta), the up-vector is still (0,1,0), but as soon as you rotate the camera up or down, the up-vector should change as well…