我有一个平面对象,我希望它能够向前移动和左右旋转。我希望飞机能够朝着它所面对的方向前进。OpenGL旋转和翻译问题
这是我的代码,但它不工作,我哪里错了?
directionX=sin(heading*M_PI/180.0);
directionZ=-cos(heading*M_PI/180.0);
if(keys['W']){
eyeX += directionX;
eyeZ += directionZ;
}
if(keys['S']){
eyeX -= directionX;
eyeZ -= directionZ;
}
if(keys[VK_LEFT])
heading -= 1;
if(keys[VK_RIGHT])
heading += 1;
飞机使用航向旋转,并且使用eyeX & EYEZ平移。
//Aircraft
glPushMatrix();
glRotatef(-heading, 0,1,0);
glTranslatef(eyeX,eyeY,eyeZ);
model.speedDisplayFaceNormals();
//model.drawBoundingBox();
//model.drawOctreeLeaves();
glPopMatrix();
你应该更清楚地描述它是如何工作的。描述你如何选择定位你的坐标轴也是有意义的。 – unwind
另外,请发布您的glRotate/glTranslate代码,或代码,这些东西实际上影响您的矩阵。 –
我添加了它如何使用它.. – user195257