Рисуется координатная плоскость и куб, необходимо обеспечить перемещение куба. Но в данной ситуации перемещается как куб, так и координатная плоскость. Что нужно добавить?
#include <glut.h>
void Reshape(int w, int h);
void Display();
void ProcessNormalKeys(unsigned char key, int x, int y);
void ProcessSpecialKeys(int key, int x, int y);
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(800, 600);
glutReshapeFunc(Reshape);
glutDisplayFunc(Display);
glutKeyboardFunc(ProcessNormalKeys);
glutSpecialFunc(ProcessSpecialKeys);
glutMainLoop();
return 0;
}
void Reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1000, 1000, -1000, 1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void Display()
{
glClearColor(1, 1, 1, 0);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 1.0);
glVertex2i(350, 550);
glColor3f(0.0, 0.0, 1.0);
glVertex2i(350, 150);
glColor3f(0.0, 1.0, 0.0);
glVertex2i(650, 150);
glColor3f(1.0, 0.0, 0.0);
glVertex2i(650, 550);
glEnd();
glBegin(GL_LINES);
glColor3f(0, 0, 0);
glVertex2i(-10000, 0);
glVertex2i(10000, 0);
glVertex2i(0, -10000);
glVertex2i(0, 10000);
glEnd();
glutSwapBuffers();
}
void ProcessNormalKeys(unsigned char key, int x, int y)
{
if (key == 27)
{
exit(0);
}
if (key == 65)
{
glMatrixMode(GL_MODELVIEW);
glTranslated(80, 80, 0);
Display();
}
}
void ProcessSpecialKeys(int key, int x, int y)
{
switch (key)
{
case GLUT_KEY_UP:
glMatrixMode(GL_MODELVIEW);
glTranslated(0, 80, 0);
Display();
break;
case GLUT_KEY_DOWN:
glMatrixMode(GL_MODELVIEW);
glTranslated(0, -80, 0);
Display();
break;
case GLUT_KEY_LEFT:
glMatrixMode(GL_MODELVIEW);
glTranslated(-80, 0, 0);
Display();
break;
case GLUT_KEY_RIGHT:
glMatrixMode(GL_MODELVIEW);
glTranslated(80, 0, 0);
Display();
break;
}
}