-1
我正在編寫一個程序,當用戶按下對應的鍵時,必須翻譯屏幕上的線立方體。主要問題發生在翻譯多維數據集時,製作多個副本,生成某種路徑。這裏的代碼:翻譯線立方體的問題
#include <iostream>
#include "GL/glut.h"
#include "GL/gl.h"
#include "GL/glu.h"
#include "math.h"
#define LARGURA 600
#define ALTURA 500
using namespace std;
const GLfloat INCREMENT = 2.0f;
const GLfloat CUBE_SIZE = 2.0f;
GLfloat X, Y, Z = 0.0f;
void myReshape(int largura, int altura)
{
largura = LARGURA;
altura = ALTURA;
glViewport(0, 0, largura, altura);
glMatrixMode(GL_PROJECTION);
glOrtho(-5.0, 5.0, -5.0, 5.0, -5.0, 5.0);
gluPerspective(25.0, largura/altura, 0.1, 500);
glMatrixMode(GL_MODELVIEW);
}
void myDisplay()
{
glClear(GL_DEPTH_BUFFER_BIT);
glPushMatrix();
gluLookAt(-2.7, 2.0, 5.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0);
glColor3f(0.0, 1.0, 1.0);
glTranslatef(X, Y, Z);
glutWireCube(CUBE_SIZE);
glutPostRedisplay();
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void myKeyboard(int key, int x, int y)
{
switch (key)
{
case GLUT_KEY_RIGHT:
X += INCREMENT;
break;
case GLUT_KEY_LEFT:
X -= INCREMENT;
break;
case GLUT_KEY_UP:
Y += INCREMENT;
glutPostRedisplay();
break;
case GLUT_KEY_DOWN:
Y -= INCREMENT;
glutPostRedisplay();
break;
case GLUT_KEY_INSERT:
Z += INCREMENT;
glutPostRedisplay();
break;
case GLUT_KEY_HOME:
Z -= INCREMENT;
glutPostRedisplay();
break;
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(LARGURA, ALTURA);
glutInitWindowPosition(400,50);
glutCreateWindow("Movendo Cubo");
glutDisplayFunc(myDisplay);
glutReshapeFunc(myReshape);
glutSpecialFunc(myKeyboard);
glutMainLoop();
return 0;
}
我已經做了一切,我可以做,以弄清楚發生了什麼事情...你能幫忙嗎?