rotation in a spherical manner in global axis


My problem is this… I have a cube in my world situated at the origin. I hope to rotate my camera about a global axis such that the camera travels in a sphere-like manner(surrounding the cube). I want my camera to always look at the cube while it is rotating.

When the user press the up/down arrow key, the camera will rotate about the x-axis of the global axis, rotating in a spherical manner. Likewise, when the user press the left/right arrow key, the camera will rotate about y-axis of the global axis. I do not want rotations to be built on top of each other’s local axis.

However, i have other functions like zoom in, zoom out, move the cube vertical or horizontally across the screen that depends on the local axis of the cube.
This means after i rotate in the global axis, i might need to do a zoom or a move in local axis after the cube has been rotated.

This local/global thing has been confusing…but what i need to know is how to accomplish the sperical rotation i have specified above in global axis? i think part of the difficulty is that the camera must always look at the cube while it is rotating.

can i know how to do that using gluLookAt or other functions? I am quite a novice … Can anyone help me? Thanks!

monk :slight_smile:

Hi !

You can do it with gluLookAt but then you will have to calculate the “camera” position yourself, you also need to be careful with the up vector when you move the camera up or down.

But you can also just use a glTranslate(…); glRotate(…); to do the same thing.

If you want to zoom in or out you should use the field of view parameter (gluPerspective), increase to zoom in and deccrease value to zoom out.


thanks for replying!
actually my problem is that i do not know how to calculate the camera position and the Up vector… can you give me an example using some figures?

actually my camera is of gluLookAt(150,150,150,-1,-1,-1,0,1,0) at the setup with the cube centres at the origin.


Hi !

Well, then as I said you might consider using:

glTranslate( 0,0, dist);
glRotate( …);

Then you do not have to bother with the calculations.