GL_PROJECTION vs GL_MODELVIEW, and a little rotation problem

Allright, first; How do I convert my mouse coordinates (i.e x = 400 & y = 300) to gl float coordinates (i.e x = 0.0f & y = 0.0f).

Second; I’ve compiled a few objects, let me use a simple cube (2f * 2f * 2f) for this example. It’s drawn centered at 0f, 0f, 0f (seemed locigal), and compiled into a glList. Now, when I want to draw this cube, I do like this;

gl.glLoadIdentity();
gl.glTranslatef( /* whatever x, y and z coordinates I’d like to use */ );
gl.glCallList(CUBE); //Integer containing memory slot for this particular item

Okay, this works fine. I also tried to rotate the cube a little around it’s own axis. Also worked fine. Now; here’s my problem:

What shall I do in order to rotate this cube around an axis far away from the centre of the cube? Like, the cube is drawn at 2f,2f,-10f, and I want to rotate it around an axis at 0f,0f,-10f.

You get what I mean?

  1. The easiest way is by using gluUnProject.
  2. To rotate around an arbitrary point you have to combine a few operations
  • translate to get the arbitrary point to the origin
  • perform rotation you want to perform
  • translate back

In other words

int x, y, z; // arbitrary point
glTranslate(-x, -y, -z);
glRotate(xRot, yRot, zRot);
glTranslate(x, y, z);