I have a very simple program with my introductor OpenGL stuff. I have 3d vertex on the screen and the whole system is being rotated along y axis.
float rotation =0;
//update function
rotation = rotation +1;
The draw function looks something like this:
glPushMatrix();
glTranslatef(500,390,0);
glRotatef(rotation,0.0,1.0,0.0);
glVertex3d(365,50,0);
glPopMatrix();
When the glVertex is being rotated, its position on the screen is changing obviously. But the coordinates of the point itself are not. How do I get the current coordinates of the point on the screen which has been rotated by glRotatef, when their ‘actual’ coordinates are stationary?
You have to mimick the OpenGL transformation pipeline. Since you’re using old-and-dusted fixed function OpenGL, I’m going to show you how to do this with old-and-dusted GLU:
First we need the current viewport and projection matrix
at this point the modelview matrix holds the modelview transform applied so get this one, too.
Now we have everything to project it.
There you go. I recommend looking at the sourcecode of gluProject as provided by MesaGL. But basically it’s these steps: