C++ about arrow control

Write your question here.
Hey I need to change y = down , x = up , 2 = ... what ever
become to the arrow control left = left , right = right , down = down , up = up
so help me to get my help to this code please
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
 #include <stdlib.h>
#include <stdio.h>
#include <GL\glut.h>

#define ESCAPE 27
GLfloat xt = 1.0, yt = 1.0 ;
GLint window;

void init (void)
{
	glClearColor (1.0, 1.0, 1.0, 0.0);
	glLineWidth(2.0);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0.0, 500.0, 0.0, 500.0);

}

void myDisplay(void)
{
	glClear(GL_COLOR_BUFFER_BIT);

	glPushMatrix();
	glTranslatef(xt, yt, 0.0);
	glBegin(GL_POLYGON);
		glColor3f(1.0,0.0,0.0);
		glVertex2f(75.0,50.0);
		glVertex2f(125.0,50.0);
		glVertex2f(150.0,100.0);
		glVertex2f(100.0,125.0);
		glVertex2f(50.0,100.0);
	glEnd();
	glPopMatrix();
	glutSwapBuffers();

	glFlush();
}

void KeyboardAssign(GLubyte key, GLint x, GLint y)
{
	switch(key)
	{
	case ESCAPE :
		printf ("escape pressed. exit. \n");
		glutDestroyWindow(window);
		exit(0);
	break;
	case 'x' :
		xt += 10.0; 
		glutPostRedisplay();
	break;
	case 'z' : 
		xt -= 10.0;
		glutPostRedisplay();
	break;
	case 'y' : 
		xt -= 10.0;
		glutPostRedisplay();
	break;
	case 't' : 
		xt -= 10.0;
		glutPostRedisplay();
	break;
	case '2' : 
		xt *= 2.0;
		yt *= 2.0;
		glutPostRedisplay();
	break;
	case '3' : 
		xt *= 3.0;
		yt *= 3.0;
		glutPostRedisplay();
	break;

defalut:
	break;

	}
}

void main (int argc, char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutInitWindowPosition(50,50);
	glutInitWindowSize(500,500);
	glutCreateWindow("Translation : x=right, z=left, y=up, y=down, 2=double, 3=triple");
	init();
	glutDisplayFunc(myDisplay);
	glutIdleFunc(myDisplay);
	glutKeyboardFunc(KeyboardAssign);
	glutMainLoop();
}
Try changing yt instead of xt under case 'y'.
Think about how increasing xt moves right and decreasing moves left.
Same with yt except the motion is up and down.
Last edited on
Topic archived. No new replies allowed.