c++ - 我的太阳系有问题

标签 c++ opengl

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

所以,我都做了,但我做不到地球自转...地球绕太阳自转,月球绕地球自转...我怎么能让地球自转?当我在代码中放置另一个“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°。当然,行星不会以完美的圆形公转方式围绕太阳公转,而是以椭圆曲线公转。

关于c++ - 我的太阳系有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6161818/

相关文章:

c++ - 有没有办法在 xcode 上使用 c++0x?我想使用 gcc 4.4 或更高版本

c++ - 描述原始指针(指向对象)的概念的正确实现是什么?

java - OpenGL (LWJGL) - 获取纹理的像素颜色

c++ - 添加到 OpenGL 中的部分图像而不是完全重绘?

C++:Ray Tracer 输出中的非确定性行为

c++ - 为什么下面程序的输出是 12 字节,而总大小只有 6 位?

c++ - 如何解决--------undefined reference to `__chkstk_ms' --------on mingw

python - "Look at"函数返回前向位置错误的 View 矩阵? (Python实现)

c++ - 在 opengl 中绘制环面

c++ - 不打开窗口的 OpenGL 上下文 - 当使用由 GetDesktopWindow 制作的 HWND 时,wglMakeCurrent 因 HDC 和 HGLRC 而失败