PDA

View Full Version : Noobie rotation question

04-25-2007, 03:02 PM
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 >
\ /
\ /
\ /
\ /
\ /
\ /
\ /
\ /
vand then rotate this about an arbitrary new origin . . .

^
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
< >
\ /
\ /
\ /
\ X /
\ /
\ /
\ /
\ /
vHow might I do this?

songho
04-26-2007, 08:32 AM
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();

04-26-2007, 03:05 PM
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.

firegun9
04-26-2007, 06:27 PM
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.