所以,这是我的问题.我应该制造一个太阳系,太阳位于中心,行星围绕着旋转; 每个星球都应该有自己的卫星.
所以,我做到了这一切,但我无法让地球自行旋转......地球围绕太阳旋转,月球围绕地球旋转......我怎样才能让地球自行旋转?当我在代码中放入另一个"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();
}
Run Code Online (Sandbox Code Playgroud)
改变地球
glPushMatrix();
glRotatef(earth_rotation);
glutSolidSphere(0.28, 20, 10); //draw Earth: more or less, the Earth has got the same dimension of Venus.
glPopMatrix();
Run Code Online (Sandbox Code Playgroud)
一些天文学笔记:地球实际上比金星略大.到目前为止,你所有的轨道都是共面的.此外,地球旋转轴相对于轨道平面(称为黄道)倾斜约23°.月球的轨道再次向黄道倾斜约5°.当然,行星不是在完美的圆形旋转中绕太阳运行,而是在椭圆形曲线中.