glOrtho Rotation

Hello

I’m writing a 2D game project at the moment with the help of glOrtho(). I already implemented a class for primitive drawing like rectangles, pixels, lines, alpha blending and so on, and I’m really impressed what you can do when using the power of OpenGL for 2D effects.

Well, now I’m working at loading and drawing bitmaps, and all works nice. I use quads and put the bitmaps as a texture onto them - and now I tried to rotate such a quad around the Z-axis. It rotates, but not around itself, rather around some invisible point somewhere on the screen.

So my question: How to make a quad rotates around its own center?

As english is not my native language, I hope you understand what I mean. Maybe somebody had a similar problem.

Thank you.

Rotations in OpenGL always rotate around the origin of the current coordinate system. The matrix transformation functions (glTranslate/glRotate/glScale/etc) change the position, orientation and scale of this coordinate system. This means that every transformation affects all subsequent transformations.

An example:

``````glRotatei(45, 0, 0, 1);
glTranslatei(1, 0, 0);
drawObject();
``````

The call to glRotate will rotate the coordinate system 45 degrees around the z-axis. The glTranslate then moves the coordinate system 1 unit along its (rotated!) x-axis. The object ends up at position (0.7, 0.7, 0).

If you want to rotate the object around its own center, you have to switch the order of the two calls:

``````glTranslatei(1, 0, 0);
glRotatei(45, 0, 0, 1);
drawObject();
``````

This will first translate the coordinate system to (1, 0, 0) and then rotate it 45 degrees around its z-axis.

[ul][li]make sure your quad’s object coordinates are centered around (0, 0, 0)[/li] [*]apply the quad’s translation before the rotation[/ul]

Ho avuto un problema simile. dovevo far ruotare su se stessa una telecamera montata su un braccio metallico che invece deve restare fisso. Ti posto il codice, magari è d’aiuto.

ps. il punto invisibile di cui parli dovrebbe essere proprio l’asse Z
ciao

Display()
{
.
.
.
.
glPushMatrix();
//posizione telecamera nella scena
glTranslatef(4.33,1.102, -1.45);
// inclinazione della telecamera(e del braccio)
glRotatef(25.0,0.0,1.0,1.0);
// braccio metallico
glPushMatrix();
glTranslatef(0.1, 0.0, 0.0);
disegna_braccio();
glPopMatrix();
// braccio metallico
glPushMatrix();
glTranslatef(0.0, 0.04, 0.0);
glRotatef(angoloT1,0.0,0.0,ZrotT1);
disegna_telecamera();
glPopMatrix();
.
.
.
glFlush()
}

Thank you for your answer - I understood it and now everything works fine