Rotation around a point.
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?
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
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
obj.rotate(deg);
obj.trans(direction);
gl commands
glRotatef( deg, axis.x, axis.y, axis.z );
glTranslatef( direction.x, direction.y, direction.z );
enjoy
obj.trans(direction);
gl commands
glRotatef( deg, axis.x, axis.y, axis.z );
glTranslatef( direction.x, direction.y, direction.z );
enjoy
Andy Pike tutorial 9. very cool, you can remove the cones and cylinders though.
If love is illusion and hate is real, I would rather be crazy
If love is illusion and hate is real, I would rather be crazy
I see where your coming from, but there''s one problem. The thing I want to have in orbit is actually a light. I should have mentioned that before.
You can find the excellent tutorials of andy pike at:
http://www.andypike.com/tutorials/directx8/
http://www.andypike.com/tutorials/directx8/
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
x = sin(curAngle) * distance
y = cos(curAngle) * distance
Something like that...
Hope that helps
Simon
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
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
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement