View Full Version : Rotation within a rotation
04-10-2001, 11:25 AM
Basically I need a suggestion that would replicate the earth revolving around the sun. Simultaneously, the earth revolves around the sun and about its own center of gravity.
I have objects that need to rotate about their center of gravity (ie. earth) while also being rotated and translated about a local center of gravity (ie. sun).
I currently generate every object at the origin within its own list and translate each list to its initial position within a Draw routine.
04-10-2001, 12:22 PM
Consider sun to be at 0,0,0. (nice place)
Position of earth (X,Z plane only, not taking Y into account)
Earth.x = sin(EarthTime) * EarthDistFromSun.
Earth.z = cos(EarthTime) * EarthDistFromSun.
Where earthtime goes from 0 to 360.
fiddle about with some numbers, and rotate the earth before positioning it, and it should all be hunky dory.
repeat for all planets with their respective distances, and orbiting speeds etc. ..etc..
Add more detail until fully realistic.
I did a full blown solar system for an N64 game once.. Top it was!! http://www.opengl.org/discussion_boards/ubb/smile.gif
04-10-2001, 03:34 PM
Ok...here's what you do...
Starting at the center(origin) rotate the amount that you want the orbits position to be at, then translate out the orbit distance, then one final rotate for the planets rotation about its own axis. If you want a moon, you would then pop the planets rotation rotate off leaving you at the center of the planet. Then rotate the amount of the orbit for the moon, translate out the orbit distance, rotate the moons rotation amount and draw.
Hope that explains rotation within rotation. http://www.opengl.org/discussion_boards/ubb/smile.gif
Talk is cheap... here's some (GPLed) code http://www.opengl.org/discussion_boards/ubb/smile.gif
/* Draw the sun */
glRotatef(Sun.Hour, 0.0f, 1.0f, 0.0f);
/* Draw the planet */
glRotatef(Planet.Day, 0.0f, 1.0f, 0.0f);
/* Orbital radius of 3.0 units */
glTranslatef(3.0f, 0.0f, 0.0f);
glRotatef(Planet.Hour, 0.0f, 1.0f, 0.0f);
/* Draw moon */
glRotatef(30.0f, 0.0f, 0.0f, 1.0f); /* Orbital plane 30 deg. off equator */
glRotatef(Moon.Day, 0.0f, 1.0f, 0.0f);
glTranslatef(0.5f, 0.0f, 0.0f); /* Orbit radius of 0.5 units */
glRotatef(Moon.Hour, 0.0f, 1.0f, 0.0f);
Hope that helps.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.