【发布时间】:2014-12-28 02:09:11
【问题描述】:
我正在尝试模拟太阳系,需要让月球绕着绕太阳运行的行星运行
我目前正在使用以下代码来旋转行星
glPushMatrix();
glRotated((GLdouble)(spin*earth.speed), 0.0, 0.0, 1.0);
glTranslated(earth.xPos, earth.yPos, earth.zPos);
earth.draw();
glPopMatrix();
我正在尝试使用下面的代码使我的月球绕地球运行,但是目前我所能做的就是围绕特定点旋转。
glPushMatrix();
//define one time only start location
bool start = true;
if (start)
{
glTranslated(earthMoon.xPos, earthMoon.yPos, earthMoon.zPos);
start = false;
}
//orbit earths start point
//perfectly fits around earth
glTranslatef(-0.1, -0.1, 0);
glRotatef(spin*10, 0, 0, 1);
glTranslatef(0.1, 0.1, 0);
// need translation vector to follow earth
//glTranslated(earthMoon.xPos, earthMoon.yPos, earthMoon.zPos);
earthMoon.draw();
glPopMatrix();
我认为我需要做的是从 rotatef 函数中找到一些了解地球位置的方法。
我有一个具有以下属性和方法的行星类:
float radius;
float xPos;
float yPos;
float zPos;
float speed;
planet(float r, float x, float y, float z, float speed);
~planet();
void draw(void)
{
glPushMatrix();
glColor3f(0.0, 1.0, 1.0);
glutSolidSphere(radius, 20, 10);
glPopMatrix();
}
行星旋转时类的坐标不会更新
有谁知道如何让它工作?
【问题讨论】: