-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
147 lines (126 loc) · 2.59 KB
/
main.cpp
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
#include <Windows.h>
#include <GL/glu.h>
#include <GL/glut.h>
float angle = 0.10;
float d = 0;
float s = 1;
const GLfloat light_position[] = { 1.0f, 5.0f, 5.0f, 0.05f };
void draw(void){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glRotatef(angle, 0.0, 0.0, 1.0);
// Mango
glPushMatrix();
glColor3f(1.0,0.523,0.0);
glTranslatef(7.0,4.7,0.0);
glRotatef(90.0,1.0,0.0,0.0);
glutSolidTorus(5.0, 0.8, 50.0, 50.0);
glPopMatrix();
// Vanilla
glPushMatrix();
glColor3f(1.0,1.0,1.0);
glTranslatef(0.0,11.0,0.0);
glRotatef(90.0,1.0,0.0,0.0);
glutSolidTorus(5.0, 0.8, 50.0, 50.0);
glPopMatrix();
// Blue berry
glPushMatrix();
glColor3f(0.556863,0.137255, 0.419608);
glTranslatef(-7.0,4.5,0.0);
glRotatef(90.0,1.0,0.0,0.0);
glutSolidTorus(5.0, 0.8, 50.0, 50.0);
glPopMatrix();
// chocolate
glPushMatrix();
glColor3f(0.12,0.052,0.0);
glTranslatef(0.0,4.0,0.0);
glRotatef(90.0,1.0,0.0,0.0);
glutSolidTorus(5.0, 0.8, 50.0, 50.0);
glPopMatrix();
// Cone
glPushMatrix();
glColor3f(0.72,0.45,0.20);
glTranslatef(0.0,0.0,0.0);
glRotatef(90.0,1.0,0.0,0.0);
glutSolidCone(9.5,27.0,50.0,50.0);
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void keyboard(unsigned char key, int x, int y){
switch (key){
case 'e':
case 'E':
exit(0);
break;
case 't':
case 'T':
{
d=d+0.5;
glTranslatef(d,0,0);
}
break;
case 's':
case 'S':
{
s=s+0.1;
glScalef(s,s,s);
}
break;
case 'r':
case 'R':
glRotatef(90,1,0,0);
break;
}
}
void mouse(int btn, int state, int x, int y){
if (state == GLUT_DOWN){
if (btn == GLUT_LEFT_BUTTON)
angle = angle + 0.01f;
else
angle = 0;
}
}
void Special_Keys(int key, int x, int y){
switch (key){
case GLUT_KEY_LEFT:
angle = angle + 1.0;
break;
case GLUT_KEY_RIGHT:
angle = angle - 1.0;
break;
case GLUT_KEY_UP:
d++;
glTranslatef(d,0,0); break;
case GLUT_KEY_DOWN:
d--;
glTranslatef(d, 0, 0);
break;
}
}
void init(){
glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-30.0, 30.0, -30.0, 30.0, -30.0, 30.0);
}
int main(int argc, char **argv){
glutInit(&argc, argv);
glutInitWindowSize(500, 500);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutCreateWindow("Ice Cream Cone");
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard);
glutSpecialFunc(Special_Keys);
glutDisplayFunc(draw);
glutIdleFunc(draw);
init();
//Lighting and shade
/*glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);*/
glutMainLoop();
return(0);
}