Rotate with respect to a distant point

Started by
18 comments, last by Fier 20 years ago
I am trying to rotate an object, say sphere, with respect to a distant point. Bascially, it''s like the distant point is the center of a circle, and the object is travel on the circle''s edge. This has to be done in 3D. If anyone can show me how to do, I would be very very very very thankful.
Advertisement
translate to point you want to rotate around, rotate on correct axis, translate to final object position.
No, I tried that already, this would just make the object rotate around the distant point''s axis, not the distant point itself.
If the object you want to rotate around is at 0,0,0 and the object that must rotated around is ten units away, then first move to 0,0,0. Next rotate however much you want. Next translate 10 units away and draw orbiting. This certainly -should- work.
-Ostsol
ok, i set move to the rotate point at (0,0,0). Rotate (degree+changingX), where changeX is constatntly incrase 1 degree per frame, with respect to z axis. Then translate to the piont at (3,3,3). What happens is the object is rotateing around (0,0,0)''s z axis instead of the point (0,0,0) itself. So it''s not working.
transform your object into the other object''s world-space (i.e. NOT to it''s position but make your coordinates offsets of the other objects center). then do your rotate around the other object''s axis. then re-transform back to world coordinates. just a couple of simple matrix operations.

-me
Dear Palidine, can you please be a little more specific. Thanks a lot.
Please correct me if I am wrong. I think what you saying is:

//move to distant point
glTranslatef(0,0,0);
//save position
glPushMatrix();
//rotate angle, constantly increasing
glRotatef(changingXY, 0,0,1);
glRotatef(changingZY, 0,1,0);
//move the the distant obj
glTranslatef(distant obj''s position - distant point);
DrawObject;
//restore to world view
glPopMatrix();

Did I understant correctly?
no.

the first step is wrong. you need to transform your model into the local coordinate system of the distant object. this is NOT the same as moving it to that location.

say i have a point at 1,1,1 and another point at 3,3,3. the first step is to transform 3,3,3 into (1,1,1)'s worldspace. from the perspective of (1,1,1), (3,3,3) is really (2,2,2). make sense? you basically just subtract (1,1,1) from (3,3,3) to get (3,3,3)'s relative position with respect to (1,1,1).

THEN do your rotation.

then transform back to world space (mult by the inverse [is that the right word?] of the first matrix you multiplied by i believe).

offhand i can't tell you which matrix you use for that first part as matrices are currently not my strong point

-me

[edited by - Palidine on March 30, 2004 2:36:35 PM]
ok, What I want to do is rotate an object(say at 3,3,3) around a point(say at 1,1,1). I think what you saying is this.

//save current position
glPushMatrix();
//move to point
glTranslatef(1,1,1);
//save position again;
glPushMatrix();
//Find out the relative position
newPosition = 3,3,3 - 1,1,1;
glTranslatef(newposition);
//go back to the point
glPopMatrix();
//rotate the point
glRotatef(angle, 0,0,1);
glRotatef(angle, 0,1,0);
glRotatef(angle, 1,0,0);
//restore to original position
glPopMatrx();


Is it right or I screwed up again?
I understand the relative position part. I draw those no problem. I think the hard part is to get the object to rotate aroudn the point and control what direction the object is oging to rotate.

sincerely
quote:Original post by Fier
Is it right or I screwed up again?


i don''t know, does it work? ;P

anyway, i think this is unnecessary:
//move to point
glTranslatef(1,1,1);

but i''m not really the guy to help you out anymore since we''re at the boundaries of my practical knowledge.

anyway,

This topic is closed to new replies.

Advertisement