所以,这是我的问题。我应该做一个以太阳为中心,行星围绕旋转的太阳系;每个行星都应该有自己的卫星。
所以,我都做了,但我做不到地球自转...地球绕太阳自转,月球绕地球自转...我怎么能让地球自转?当我在代码中放置另一个“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/