View Full Version : Noobie rotation question

paradoxresolved

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();

paradoxresolved

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.

paradoxresolved

04-27-2007, 04:15 AM

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

x_trans -= mousemove_x*cos(second_rotation_in_radians) -mousemove_y*sin(second_rotation_in_radians)

y_trans += mousemove_y*cos(second_rotation_in_radians) + mousemove_x*sin(second_rotation_in_radians)

It took me some time to unravel it. Thanks for your help.

Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.