开发者

problem with my Solar System

So, this is my problem. I should make a Solar System with the Sun in the center and the planets rotating around; each planet should have its own moons.

So, I did it all but I'm not able to do the Earth rotating on itself... The Earth rotates around the Sun, the Moon rotates around the Earth... How can I let the Earth rotating on itself? When I put another "glrotating" command inside the code, the Moon falls down the Earth or h开发者_C百科appens something strange...

Here follows my code...

// EARTH
// INFO: 1) it's 3rd planet from the Sun;
//       2) it's 5th largest planet in the Solar System, with an equatorial radius of 6378.388km;
//       3) it's 3rd fastest planet, because its orbital period is of 365 earth-days (1 year).
void Earth(void)
{
    DrawOrbit(5.5, 1);
    glRotatef((GLfloat) year*6.2, 0.0, 1.0, 0.0); //orbital movement for the Earth around the Sun
    glTranslatef(5.5, 0.0, 0.0);
    glColor3f(0.0, 0.3, 1.0);
    glutSolidSphere(0.28, 20, 10); //draw Earth: more or less, the Earth has got the same dimension of Venus.

    // The Earth has got one natural satellites: the Moon. Let's draw it:
    glPushMatrix();
    glRotatef((GLfloat) day*2, 0.0, 1.0, 0.0); //rotate for the moon
    glTranslatef(0.5, 0.0, 0.0);
    glColor3f(1.0f, 1.0f, 1.0f);
    glutSolidSphere(0.05, 5, 4); //draw moon: its diameter is about a quarter the diameter of Earth 
    glPopMatrix();

}


Change earth to this

glPushMatrix();
glRotatef(earth_rotation);
glutSolidSphere(0.28, 20, 10); //draw Earth: more or less, the Earth has got the same dimension of Venus.
glPopMatrix();

A few astronomy notes: The earth is actually slightly larger than Venus. Also so far all your orbits are coplanar. Further the earth rotaton axis is tilted by about 23° against the orbital plane (called ecliptic). The moon's orbit again is tilted by about 5° against the ecliptic. And of course the planets don't orbit the sun in a perfect circular revolution, but in a elliptic curve.


The moon's revolution around the earth's is independent of earth's rotation about its own axis ( at least for rendering purposes)

So you should pushmatrix rotate the earth and pop and use your moon's logic. Also if you just draw earth as a solid sphere even if it rotates about itself it will not appear so in your application unless you have a nice texture on it


If you want to do this accurately, what you are doing is, to be blunt, wrong.

The planets don't quite orbit the Sun. They orbit the solar system barycenter, which is located just outside the surface of the Sun. The mass of the Moon is about 0.0123 that of Earth, and this means you had better model the Earth and Moon as orbiting about their common center of mass rather than the Moon orbiting about the Earth.

The same goes for Pluto and Charon, but hey, Pluto isn't a planet anymore, so who cares?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜