-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLab 4 Rotation Task
More file actions
174 lines (132 loc) · 2.67 KB
/
Copy pathLab 4 Rotation Task
File metadata and controls
174 lines (132 loc) · 2.67 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include <GL/glut.h>
#include <stdlib.h>
#include <stdlib.h>
#include <math.h>
static GLfloat spin = 0.0;
static float tx = 0.0;
static float ty = 0.0;
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(spin, 0.0, 0.0, 1.0);
glColor3f(1.0, 1.0, 1.0);
glTranslatef(tx,ty,0);
//right
glColor3f(.80, .90, 90);
glRectf(25.0, 10.0, 50.0, -10.0);
//left
glColor3f(.80, .90, .90);
glRectf(-25.0, 10.0, -50.0, -10.0);
//right square
glColor3f(.10, .90, 0);
glRectf(50.0, 20.0, 90.0, -20.0);
//left square
glColor3f(.10, .90, 0);
glRectf(-50.0, 20.0, -90.0, -20.0);
glPopMatrix();
//top box
glColor3f(1.0, 1.0, .0);
glRectf(-25.0, -25.0, 25.0, 25.0);
//stand
glColor3f(.40, .90, .50);
glRectf(-11.0, -25.0, 11.0, -80.0);
//bottom
glColor3f(.10, .70, 1.0);
glRectf(-19.0, -105.0, 19.0, -80.0);
glFlush();
}
void spinDisplay_left(void)
{
spin = spin + 1;
if (spin > 360.0)
spin = spin - 360.0;
glutPostRedisplay();
}
void spinDisplay_right(void)
{
spin = spin - 1;
if (spin > 360.0)
spin = spin - 360.0;
glutPostRedisplay();
}
void init(void)
{
glClearColor (.60, 0.20, 0.0, 0.0);
glOrtho(-100.0, 100.0, -110.0, 110.0, -1.0, 1.0);
}
void my_keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 'l':
spinDisplay_left();
break;
case 'r':
spinDisplay_right();
break;
case 's':
glutIdleFunc(NULL);
break;
default:
break;
}
}
void spe_key(int key, int x, int y)
{
switch (key) {
case GLUT_KEY_LEFT:
tx -=5;
glutPostRedisplay();
break;
//spinDisplay_left();
//break;
case GLUT_KEY_RIGHT:
tx +=5;
glutPostRedisplay();
break;
//spinDisplay_right();
//break;
/*case GLUT_KEY_DOWN:
ty -=5;
glutPostRedisplay();
break;
//spinDisplay_left();
//break;
case GLUT_KEY_UP:
ty +=5;
glutPostRedisplay();
break;*/
default:
break;
}
}
void my_mouse(int button, int state, int x, int y)
{
switch (button) {
case GLUT_LEFT_BUTTON:
if (state == GLUT_DOWN)
glutIdleFunc(spinDisplay_left);
break;
case GLUT_MIDDLE_BUTTON:
case GLUT_RIGHT_BUTTON:
if (state == GLUT_DOWN)
glutIdleFunc(spinDisplay_right);
break;
default:
break;
}
}
int main()
{
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (600, 600);
glutInitWindowPosition (100, 100);
glutCreateWindow ("Spinnig: **Nagordola**");
init();
glutDisplayFunc(display);
glutKeyboardFunc(my_keyboard);
glutSpecialFunc(spe_key);
glutMouseFunc(my_mouse);
glutMainLoop();
return 0;
}