作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我可以让地球绕着太阳和它自己的轴自转,但我不能让月球绕着地球自转。 (我只是想让它绕着它循环,我不需要计算重力或类似的东西。)
这是我的代码:
double earth_x = 50.0 * cos(orbit / 180.0 * Math::Constants<double>::pi);
double earth_y = 45.0 * sin(orbit / 180.0 * Math::Constants<double>::pi);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
//sun
glMaterialAmbientAndDiffuse(GLMaterialEnums::FRONT,GLColor<GLfloat,4>(1.5f,1.0f,0.0f));
glTranslate(0.0f, 0.0f, 0.0f);
glRotate(0.0, 0.0, 0.0, 00.0);
drawEllipsoid(10.0, 1.0, 4, 4);
//Earth
glPushMatrix();
glTranslate(earth_x, earth_y, 0.0);
glMaterialAmbientAndDiffuse(GLMaterialEnums::FRONT,GLColor<GLfloat,4>(0.2f,50.0f,50.5f));
glRotatef(110,0.0,23.0,110.0f);
glRotatef(orbit2, 0.0f, 0.0f,1.0f);
drawPlanetGrid(5, 1, 20, 20, 1.5);
glPopMatrix();
glMaterialAmbientAndDiffuse(GLMaterialEnums::FRONT,GLColor<GLfloat,4>(50.2f,50.0f,50.5f));
//Moon
glTranslate(earth_x+10, earth_y+10, 0.0);
glRotate(moonOrb, 0.0, 0.0, 1.0);
drawEllipsoid(1, 1, 9, 9);
moonOrb += .5;
if (moonOrb > 360)
moonOrb = 0.0;
orbit += .9;
if (orbit > 360)
{
orbit = 0;
}
orbit2 += 6.5;
if (orbit2 > 360)
{
orbit2 = 0;
}
知道我的代码有什么问题吗?截至目前,我的对象上没有纹理,所以这就是代码中缺少它的原因。在我对大小、轨道形状和类似的东西做出任何改变之前,我真的只是想了解太阳系是如何工作的。
最佳答案
假设您按照我在 https://stackoverflow.com/a/16594168/252687 中的建议进行操作,您所要做的就是为月球再次复制代码。由于天体不受严格约束,独立计算它们的轨道比嵌套它们的引用系更明智。
地球的位置是:
earth_x = 30.0 * cos(earth_orbit / 180.0 * PI)
earth_y = 30.0 * sin(earth_orbit / 180.0 * PI)
月亮的位置是:
moon_x = earth_x + 15.0 * cos(moon_orbit / 180.0 * PI)
moon_y = earth_y + 15.0 * sin(moon_orbit / 180.0 * PI)
代码应该是这样的:
drawTheSun();
glPushMatrix(); // enter the Earth's frame of reference
glTranslate(earth_x, earth_y, 0.0); // move to the position of the Earth
glRotate(110, 0.0, 23.0, 110.0f); // earth-local transformations
drawTheEarth();
glPopMatrix(); // exit the Earth's frame of reference
glPushMatrix(); // enter the Moon's frame of reference
glTranslate(moon_x, moon_y, 0.0); // move to the position of the Moon
glRotate(110, 0.0, 23.0, 110.0f); // moon-local transformations
drawTheMoon();
glPopMatrix(); // exit the Moon's frame of reference
关于c++ - 月球轨道相对于太阳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16594194/
我注意到 eclipse 有不同的版本控制系统。它有一个数字系统以及火星、月球等系统。 是一样的吗? Mars 和 Eclipse 7 一样吗? 最佳答案 Mars 和 Luna 是代号。版本不仅通过
我是一名优秀的程序员,十分优秀!