PDA

View Full Version : Rotation independant objects



Maire Nicolas
09-07-2010, 12:42 AM
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 ?

Alfonse Reinheart
09-07-2010, 01:43 AM
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.

Maire Nicolas
09-07-2010, 05:44 AM
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 :




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

BionicBytes
09-07-2010, 12:48 PM
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.