1
votes

I want to acheive translations/rotations as shown in following video -

http://www.youtube.com/watch?v=92h0xuV4Yrg

I know for independant translation and rotation, typical method is - first rotate the object and then translate.

As shown here:

PushMatrix();
LoadIdentity(); 
Translate(posx,posy,posz);     // Second, move the object to its final destination
Rotate();        // First, apply rotations (which rotate around object-origin
Draw();         
PopMatrix();

But my requirment is to rotate the object around world-coordinate and move it using mouse.

As seen in the video, the rotation is done around the world-origin not around object-origin.That means the logic should be opposite to above (first translate and then do the rotation)

PushMatrix();
LoadIdentity(); 
Rotate();        // Second, apply rotations (which rotate around world-origin)
Translate(posx,posy,posz);     // First, move the object to its final destination
Draw();         
PopMatrix();

But the,final translation in the video is done relative to final position after the rotations.(which is not same as the posx,posy,posz values I manipulate using mouse ).

How to achive this kind of translations

1
Is the final translation in world space or object space? If it's in object space then you can just push another matrix on the stack and move it. - Matt Lacey
all translations are in the world space. - Ashika Umanga Umagiliya
I can't follow your question, are you just trying to rotate an object around an arbitrary position? - cmannett85
simply,my question is how to implement user interactions as shown in the video. - Ashika Umanga Umagiliya

1 Answers

2
votes

To rotate an object around any point (x,y,z), you do the following:

translate (-x,-y,-z);
rotate (angle);
translate (x, y, z);

That point doesn't have to be a point on the object. It can be the origin, or any random value like (1000, 0.0023, 97.5). You may have to do an additional translation in your case. For example, if your object is defined at the origin, and the user has placed it at (x1,y1,z1) and you want to rotate it around (x,y,z), you'll need to add a:

translate (x1,y1,z1);

after the translate (x,y,z).