我的太阳系出了问题

problem with my Solar System

本文关键字:问题 太阳系 我的太阳 我的      更新时间:2023-10-16

所以,这是我的问题。我应该建立一个以太阳为中心,行星围绕太阳旋转的太阳系;每个行星都应该有自己的卫星。

所以,我做了所有的,但我不能做地球自转。。。地球绕太阳旋转,月球绕地球旋转。。。我怎么能让地球自转呢?当我在代码中输入另一个"glrotating"命令时,月球从地球上坠落或发生了一些奇怪的事情。。。

下面是我的代码。。。

// 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();
}

将地球更改为此

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

天文学注意事项:地球实际上比金星略大。到目前为止,你们所有的轨道都是共面的。此外,地球自转轴相对于轨道平面(称为黄道)倾斜约23°。月球的轨道再次相对于黄道倾斜约5°。当然,行星绕太阳公转并不是完美的,而是椭圆曲线。

月球绕地球的公转与地球绕其自身轴线的自转无关(至少出于渲染目的)

所以你应该推矩阵旋转地球,弹出并使用你的月球逻辑。此外,如果你只是把地球画成一个实心球体,即使它绕着自己旋转,它也不会在你的应用程序中出现,除非你有一个漂亮的纹理

如果你想准确地做到这一点,坦率地说,你所做的是错误的。

这些行星并不完全围绕太阳运行。它们围绕太阳系重心运行,而太阳系重心恰好位于太阳表面之外。月球的质量约为地球的0.0123,这意味着你最好将地球和月球建模为绕其共同质心运行,而不是月球绕地球运行。

冥王星和卡戎也是如此,但嘿,冥王星已经不是一颗行星了,谁在乎呢?