I want create a global rotation matrix so that I can view the world from any angle by dragging the mouse. It is OK to just rotate about the origin (my world is a clipped unit cube centred on the origin and I just want to spin it to look at it from any direction).

I am almost there, but it doesn’t quite work. My code is

    gl.glRotated(gs.getLatitude(), 1.0f, 0.0f, 0.0f);
    gl.glRotated(gs.getLongitude(), 0.0f,

Math.sin(gs.getLatitude() * Math.PI / 180), Math.cos(gs.getLatitude() * Math.PI / 180));

Sorry half of the previous post got lost.

What happens with my current code is that the world moves around, and I can view it from various directions, but there are some viewpoints which can’t be reached.

I have seen software which allows this type of orbiting (eg some 3D graphs allow it), I just want it to work in a similar way - I’m not sure what type of rotation allows this?

Look at this small demo I wrote to demonstrate how to load and display textures and images. It has an earth in it which you can rotate the way you want (I think?).

Lat-Lon Rotations

Thanks for posting this, but I am not sure it does what I want. If I understand it correctly the animation rotates automatically around z, and key presses rotate it around x and y.

(I am actually working in Java with JOGL, so I am not set up to easily compile c++, although the OpenGL interface is near identical)

What I need, I think, is for mouse X to always rotate around the Y axis of the camera coords, and mouse Y to always rotate around the X axis of the camera coords. And of course the mouse can move X and Y at once.

Perhaps I need to create some kind of accumulated rotation matrix or something?

Some people call that ‘Screen Space’ rotations.
I have another demo that does that - actually it does screen and body space rotations.
The rotations are done with keyboard keys. You’ll have to put in the mouse stuff. The source is at -

  [Screen & Object Space Rotations](http://www.mfwweb.com/OpenGL/Special_Rotations/)