Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Transformations: scene/object independent rotation

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2010
    Posts
    1

    Transformations: scene/object independent rotation

    Hello.
    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?

    P.S.
    (I had read FAQ and googled for examples)
    I developing simple CAD-like program, plenty of balls/cylinders (modelling data entities). What I trying:
    1. Rotate, shift, pan and zoom scene with mouse (i.e. view it with camera).
    2. 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.

  2. #2
    Advanced Member Frequent Contributor Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    945

    Re: Transformations: scene/object independent rotation

    [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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •