opengl transformations

Hi people.
I need help.

I want to build a 2d transformation veiwer like this:

global rot; // rotation value
global tr; // transition value in x direction

glut keybord:
every time the user press some key we make a rotation or translation.
All trans’ relative to coord system in the mid point of the object.

Once the object is rotated their coordinate system is rotated as well
and making a translation will move the object in the direction of it’s
own X direction (that changes after doing rotation).

How can I do it using only glTranslate(),glRotate() functions
(without matrix staff) ??
I want to start with identity matrix for each call.

Thank you.
Best Wishes.

Hi

In fact I don’t undersand your problem : why don’t you just call glTranslate/glRotate ? That’s simple :

Before drawing an object at position x,y,z, just call :
glLoadIdentity ();
glTranslatef (x, y, z);

then draw your object.

If you want to perform a rotation of angle a (in degrees) around the vector (x, y, z), just call
glRotatef (a,x,y,z);
Remember that you must rotate before you translate.

If you have any problems with that, just look for a tutorial on http://nehe.gamedev.net

Hope that helps

[This message has been edited by Morglum (edited 12-17-2001).]

Remember that you must rotate before you translate.

And who says it’s forbidden to rotate after translation? What if I want that effect, will OpenGL stop me from doing that?

The objects “new” x-axis is IN your rotation matrix. Remember that a matrix is the 3 unit vectors that make up the transformed coord system.

Start with the identity matrix,
Rotate it.
Get the 3 values out of the matrix that are the objects x-axis (either m[0], m[1], m[2] or m[0], m[4], m[8] - can’t remember).
translatef by that vector and you’re done.

Hope that helps, i’m not too good at explaining fings.

Originally posted by Bob:

And who says it’s forbidden to rotate after translation? What if I want that effect, will OpenGL stop me from doing that?

Of course not (as you know very well) !
I was just assuming that he wanted the rotation to spin the object, without changing its position. As you know, it is very common, and I was assuming that he was a beginner, so he would do only very common things…

Thank you guys for all the answears.
Now Help me again (the same question)
in “Transforms” topic please.

Thank’s.
Lev.