My problem is transformations. When I issue glTranslate or glRotate() either all scene rotates or object alone. How to rotate scene and objects independently? How to move objects inside scene before whole scene rotation?
(I had read FAQ and googled for examples)
I developing simple CAD-like program, plenty of balls/cylinders (modelling data entities). What I trying:
- Rotate, shift, pan and zoom scene with mouse (i.e. view it with camera).
- Rotate and move each object in already rotated scene independently with mouse (i.e. if dragging right, object should not go away if X axis away, but right) in other words there no top, side views, only 3d.
[considering fixed functionality…]
All transformations affects matrix on the top of the currently selected matrix-stack (set by glMatrixMode). To modify positions of the object in your scene, you should modify GL_MODELVIEW matrix. By issuing glTranslate/glRotate calls, you actually multiply the matrix on the top of the stack, and all vertices will be multiply by matrix that is currently on the top of the stack. To preserve current matrix and easily recover its value, you can use glPushMatrix/glPopMatrix functions. These functions enable making a hierarchy of objects. More detailed information about transformations can be found in the third chapter of the Red Book (OpenGL Programming Guide).
In short, transformations issued just in front of current object will change that object (and all object after it, if there is no glPopMatrix call). First transformation after selecting GL_MODELVIEW matrix-stack (and loading identity matrix to clean previous transformations) will change the camera position and orientation, since they transform the whole scene. This is why the transformations are called model-view. It is the same: moving camera, or the whole world in the opposite direction.