# Noobie rotation question

I would like to rotate my rectangle about the origin, say 45 degrees around z, so that this. . .

``````___________________
|                 |
|                 |
|                 |
|        X        |
|                 |
|                 |
___________________
``````

becomes this . . . (use your imagination)

``````         ^
/ \
/   \
/     \
/       \
/         \
/           \
/             \
/               \
<        x        >
\               /
\             /
\           /
\         /
\       /
\     /
\   /
\ /
v
``````

and then rotate this about an arbitrary new origin . . .

``````         ^
/ \
/   \
/     \
/       \
/         \
/           \
/             \
/               \
<                 >
\               /
\             /
\           /
\       X /
\       /
\     /
\   /
\ /
v
``````

How might I do this?

You need to rotate it first, and then translate it to the new origin, for example;

glTranslatef(x, y, z);
glRotatef(45, 0,0,1);
drawMyModel();

Sorry, I was not very clear about my question. The part you have listed I have already. I need to rotate it once more around the ‘X’ in the last picture

``````         ^
/ \
/   \
/     \
/       \
/         \
/           \
/             \
/               \
<                 >
\               /
\             /
\           /
\       X /
\       /
\     /
\   /
\ /
v
``````

. . . rotates about the ‘X’ to give this. . .

``````

___________________
|       X         |
|                 |
|                 |
|                 |
|                 |
|                 |
___________________
``````

So, 1 rotation about the z axis. 1 translation to a new origin, and then 1 rotation around the new origin. I’ve tried this but I can’t seem to get it to work.

The third part is also a rotation.
Suppose the first X is X1, the new X is X2.

glRotatef(amount, 0, 0, 1); ->3rd part
glTranslatef(x(X2-X1), y(X2-X1), 0);
glRotatef(amount, 0, 0, 1);
Render();

x(X2-X1) means x part in the vector.
y(X2-X1) means y part in the vector.

Well, ultimately that did the trick. My translation is done by dragging the mouse. Unfortunately, after the second rotation, further dragging of the mouse causes the direction of the mouse drags to be skewed. I eventually figured it out though. Under OnMouseMove, I had to put:

//pseudocode