Archived

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

sandy

Rotation around a point.

Recommended Posts

I have been having trouble with making an object rotate around a given point, like an orbit. I have seen plenty of tutorials that show you how to make an object (such as a cube) rotate on the spot, but I don''t want a cube that rotates. I want one that orbits a given point. Can anyone help me?

Share this post


Link to post
Share on other sites
i would use the same idea as rotating on a point, but instead of centering it on that point, position it as far away as the radius of the orbit.


i.e. instead of making a square (less points )
1, 1
1, -1
-1, 1
-1, -1

make it

16, 16
16, 14
14, 16
14, 14

and that way it will rotate in an obit 14 from the center.

-------------------------------------------------
Don''t take life too seriously, you''''ll never get out of it alive. -Bugs Bunny

Share this post


Link to post
Share on other sites
obj.rotate(deg);
obj.trans(direction);

gl commands
glRotatef( deg, axis.x, axis.y, axis.z );
glTranslatef( direction.x, direction.y, direction.z );


enjoy

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You can find the excellent tutorials of andy pike at:

http://www.andypike.com/tutorials/directx8/

Share this post


Link to post
Share on other sites
Try having a variable that has the current angle, and then one that has the distance from the object. Every frame, increment the current angle. The formula would be something like:

x = sin(curAngle) * distance
y = cos(curAngle) * distance

Something like that...

Hope that helps

Simon

Share this post


Link to post
Share on other sites
Hey there,

For any object you should generally keep it''s own coordinates relative. Meaning, always have it centered around the origin. Then, you can rotate the object around it''s own local coords. From there you can move the object (translate) it from the orgin to another point (similar to bones). After that translation is preformed, you can rotate the object again. This will cause the object to rotate around the origin from that offset. So on and so forth.

Matrices:
R1 (rotation around orbit point)
T0 (the offset distance to orbit)
R0 (rotation around itself)

R1 * T0 * R0 == orbit

...that should be what you''re looking for.

-tim

Share this post


Link to post
Share on other sites
I made this to rotate one way:
EX and EZ are the Eye position, BX and BZ is the Look at position.

D = D - 10
If D > 360 Then D = 1
BX = EX + (Sin((D * pi) / 180))
BZ = EZ + (Sin(((D + 90) * pi) / 180))

And to turn the other way...

D = D + 10
If D < 1 Then D = 360
BX = EX + (Sin((D * pi) / 180))
BZ = EZ + (Sin(((D + 90) * pi) / 180))

I hope it helps?
Matt

Share this post


Link to post
Share on other sites