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 4 of 4

Thread: Rotation independant objects

  1. #1
    Intern Newbie
    Join Date
    Feb 2010
    Location
    France
    Posts
    46

    Rotation independant objects

    Hello

    I would like to have some of the objects of my scene always facing the camera (2D effects).

    I managed this before by using opposite calls to glRotate, since my camera was only set up with glRotate and glTranslate.
    I'm using gluLookAt now, is there any way to do the same with a sort of "counterGluLookAt" before rendering 2D objects ?

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,723

    Re: Rotation independant objects

    I would like to have some of the objects of my scene always facing the camera (2D effects).
    Since you're still using the fixed-function pipeline, just use the matrix stack. After you use gluLookAt, push the matrix. Anything you want to render that faces the camera should be rendered at this location in the matrix stack. You can apply translations and scales, but don't apply a rotation before you render.

  3. #3
    Intern Newbie
    Join Date
    Feb 2010
    Location
    France
    Posts
    46

    Re: Rotation independant objects

    Thank you for your reply

    The problem is, my gluLookAt is not the same at every scene rendering. I'm using its UpVector and "ForwardVector" to rotate my camera, I'm not applying rotations to objects individually.

    I would like to have something like this in my code :

    Code :
     
    glPushMatrix;
      glLoadIdentity;
     
      gluLookAt(...);  // Setup the camera
     
      // Render Objects fully affected by the camera
     
      // Object 1
      glPushMatrix;
        ... // Object 1 transformations
        ... // Render Object
      glPopMatrix;
     
    ...
     
      // Object N
      glPushMatrix;
        ... // Object N transformations
        ... // Render Object
      glPopMatrix;
     
     
     
      // Render Objects that always face the camera
     
      // Object 1
      glPushMatrix;
        ... // Object 1 transformations
        ... // Reverse the camera rotation
        ... // Render Object
      glPopMatrix;
     
    ...
     
     
      // Object N
      glPushMatrix;
        ... // Object N transformations
        ... // Reverse the camera rotation
        ... // Render Object
      glPopMatrix;
     
     
    glPopMatrix;

    Is it possible to do it this way ? I only do not know what to put at the line "...// Reverse the camera rotation".

  4. #4
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171

    Re: Rotation independant objects

    Basically yes. You build a modified modelview matrix and use this to render your quads. These quads are just 4 points which may as well be the translate position. In your shaded you access each vertex and add to it the modified view matrix. I'll post some code to help.

Posting Permissions

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