Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Fier

Rotate with respect to a distant point

This topic is 5291 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
No, I tried that already, this would just make the object rotate around the distant point''s axis, not the distant point itself.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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,

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!