Oh so I need to update all three co ords even though I only want to move in the x axis, or Z axis or Y axis at one at a time.
It depends on whether you are trying to move the object along the screen X axis or the world X axis. These are not the same axis once you rotate your view. If you rotate the view, then moving along the screen X axis could be moving along the world Y axis, or along some crazy direction that is not on any world axis. From your description, I was assuming you wanted the object to follow the mouse screen position. To make the object appear to move along a screen axis, you’ll have to move in a different world direction.
If you really just want to move along a world axis, just adjust the corresponding object coordinate directly (and maybe hide the mouse pointer).
do I have to do anything special when I rotate my scene with glrotatef when getting the model view matrix etc.
When you unproject, you need the modelview matrix to include any “view” transformations, but not “model” transformations. Basically, include only those transformations you consider to be “moving the camera around”.
So if your glRotate is just rotating the object (like turning an apple around in your hand), then don’t include it.
But if your glRotate is like having the apple sitting on a table, and you walk around to look at it from a different angle, then do include it.
When transforming the object during drawing, you include both model and view transformations.
This rule applies for all transformations (not just glRotate).
More details:
Conceptually, your vertices start in “object coordinates”. Then you multiply by a “model matrix” to transform the vertices into “world coordinates”. In world coordinates, everything has a common scale, a common reference origin, and common axes (like you plotted everything out on graph paper).
After that, you multiply by a “view matrix” to tranform the vertices into “eye coordinates” (aka camera coordinates). This moves the world to put your eye point at some world coordinate. In eye coordinates, the eye is always at (0,0,0), by definition.
OpenGL combines these two steps together as the “modelview matrix”. Multiplying your object vertices by the “modelview matrix” transforms them directly from object coordinates to eye coordinates, with no stop in-between for world coordinates.
But you can arrange for this intermediate stopping point by loading the modelview matrix with only the “view” transforms. This isn’t very useful for drawing, but it should be helpful for unprojecting. The “view” transforms are the first ones you do (if you do any).
This might sound like overkill, but to get very far in OpenGL, you’ll need to get used to thinking in different coordinate spaces, and understanding what matrices convert between these spaces.
The OpenGL “Red Book” could be helpful here, and there are lots of other published books, and web tutorials. Just look for ones that have real concept information, not just code. Draw your own diagrams to help yourself understand how points in virtual 3D space are projected to the screen.