Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Void Int Int: "Toroide" "Esfera" "Cono" "Cubo" "Puntos" "Lineas" "Relleno"

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

siete.

c 11/6/2020 11:21

1
2 void redimensionado(int anchop, int altop) {
3 glViewport(0,0,anchop,altop);
4 glMatrixMode(GL_PROJECTION);
5 glLoadIdentity();
6 gluPerspective(60.0f,(GLfloat)ancho/(GLfloat)alto,0.1,profund
7 gluLookAt(0,0,profundidad/1.2,0,0,0,0,1,0);
8 glMatrixMode(GL_MODELVIEW);
9 glLoadIdentity();
10 }
11
12
13 void luces() {
14 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, material_ambient)
15 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, material_diffuse)
16 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material_specula
17 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50.0f);
18 glLightfv(GL_LIGHT0, GL_AMBIENT, luz_ambient);
19 glLightfv(GL_LIGHT0, GL_DIFFUSE, luz_diffuse);
20 glLightfv(GL_LIGHT0, GL_SPECULAR, luz_specular);
21 glLightfv(GL_LIGHT0, GL_POSITION, luz_position);
22 glEnable(GL_DEPTH_TEST);
23 glEnable(GL_LIGHT0);
24 }
25
26 void crear_menu() {
27 int submenupoligono, submenutipo;
28 submenupoligono = glutCreateMenu(menupoligono);
29 glutAddMenuEntry("Toroide", 0);
30 glutAddMenuEntry("Esfera", 1);
31 glutAddMenuEntry("Cono", 2);
32 glutAddMenuEntry("Cubo", 3);
33 submenutipo = glutCreateMenu(menutipo);
34 glutAddMenuEntry("Puntos", 0);
35 glutAddMenuEntry("Lineas", 1);
36 glutAddMenuEntry("Relleno", 2);
37 glutCreateMenu(menu);

Page 1 of 6
siete.c 11/6/2020 11:21

38 glutAddSubMenu("Poligono", submenupoligono);
39 glutAddSubMenu("Tipo", submenutipo);
40 glutAddMenuEntry("Alternar Movimiento", 1);
41 glutAddMenuEntry("Alternar Pantalla", 2);
42 glutAddMenuEntry("------------------", 999);
43 glutAddMenuEntry("Salir", 3);
44 glutAttachMenu(GLUT_RIGHT_BUTTON);
45 }
46
47 void menu(int opcion) {
48 switch (opcion) {
49 case 1: alterna_movimiento();break;
50 case 2: alterna_pantalla();break;
51 case 3: exit(0);break;
52 default: break;
53 }
54 }
55
56 void menupoligono(int opcion) {
57 switch (opcion) {
58 case 0 : figura=1;break;
59 case 1 : figura=2;break;
60 case 2 : figura=3;break;
61 case 3 : figura=4;break;
62 default: break;
63 }
64 }
65
66
67 void mouse(int bouton,int estado,int x,int y);
68 void movimiento_mouse(int x,int y);
69 void texto_terminal(char *cmd);
70
71 int posx=0, posy=0;
72 float angulo=0;
73 float esc=1;
74 unsigned int figura=1;

Page 2 of 6
siete.c 11/6/2020 11:21

75 GLfloat material_ambient[] = {0.05, 0.05, 0.05, 1.0f};


76 GLfloat material_diffuse[] = { 0.8, 0.0, 0.0, 1.0f};
77 GLfloat material_specular[] = {0.9, 0.8, 0.8, 1.0f};
78 GLfloat luz_ambient[] = { 0.75, 0.75, 0.75, 0.0 };
79 GLfloat luz_diffuse[] = { 1.0, 1.0, 1.0, 0.0 };
80 GLfloat luz_specular[] = { 1.0, 1.0, 1.0, 0.0 };
81 GLfloat luz_position[] = { 1.0, 1.0, 1.0, 0.0 };
82 unsigned int luz=1;
83 unsigned int movimiento=0;
84 unsigned int pantalla=0;
85 char presionado;
86 int angulox=0,anguloy=0,x,y,xold,yold;
87
88 void tecladoEspecial(int tecla, int x, int y) {
89 switch(tecla) {
90 case GLUT_KEY_UP : posy++;break;
91 case GLUT_KEY_DOWN : posy--;break;
92 case GLUT_KEY_RIGHT : posx++;break;
93 case GLUT_KEY_LEFT : posx--;break;
94 case GLUT_KEY_PAGE_UP : esc=esc*1.01;break;
95 case GLUT_KEY_PAGE_DOWN : esc=esc*0.99;break;
96 case GLUT_KEY_F1 : figura=1;break;
97 case GLUT_KEY_F2 : figura=2;break;
98 case GLUT_KEY_F3 : figura=3;break;
99 case GLUT_KEY_F4 : figura=4;break;
100 case GLUT_KEY_F5 : alterna_movimiento();break;
101 case GLUT_KEY_F6 : alterna_pantalla();break;
102 case GLUT_KEY_F9 : luz=0;glPolygonMode(GL_FRONT_AND_BACK,G
103 case GLUT_KEY_F10 : luz=0;glPolygonMode(GL_FRONT_AND_BACK,
104 case GLUT_KEY_F11 : luz=1;glPolygonMode(GL_FRONT_AND_BACK,
105 }
106 glutPostRedisplay();
107 }
108
109 void texto(int x, int y, char *palabra) {
110 int i;
111 glColor3f(0,0,0);

Page 3 of 6
siete.c 11/6/2020 11:21

112 glRasterPos2f(x, y);


113 for (i = 0; palabra[i]; i++)
114 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, palabra[i]);
115 }
116
117 void desocupado() {
118 if (movimiento==1) {
119 angulo=angulo+0.3;
120 if (angulo>=360)
121 angulo=0;
122 glutPostRedisplay();
123 }
124 }
125
126 int main(int argc, char** argv) {
127 int i;
128 for (i=1;i<argc;i++) {
129 if (strstr(argv[i],"-h") != NULL)
130 texto_terminal(argv[0]);
131 if (strstr(argv[i],"-m") != NULL)
132 movimiento=1;
133 if (strstr(argv[i],"-f") != NULL) {
134 if (i+1 >= argc)
135 texto_terminal(argv[0]);
136 switch(atoi(argv[i+1])) {
137 case 1: figura=1;break;
138 case 2: figura=2;break;
139 case 3: figura=3;break;
140 case 4: figura=4;break;
141 default: figura=5;break;
142 }
143 }
144 }
145 glutInitDisplayMode(GLUT_STENCIL | GLUT_DOUBLE | GLUT_DEPTH);
146 glutInitWindowPosition(100, 0);
147 glutInitWindowSize(ancho, alto);
148 glutCreateWindow("Mouse");

Page 4 of 6
siete.c 11/6/2020 11:21

149 glOrtho(-(ancho/2), (ancho/2), -(alto/2), (alto/2), -profundi


150 glClearColor(1, 1, 1, 0);
151 crear_menu();
152 glutDisplayFunc(dibuja);
153 glutKeyboardFunc(tecladoNormal);
154 glutSpecialFunc(tecladoEspecial);
155 glutIdleFunc(desocupado);
156 glutReshapeFunc(redimensionado);
157 glutMouseFunc(mouse);
158 glutMotionFunc(movimiento_mouse);
159 glutMainLoop();
160 return 0;
161 }
162
163 void dibuja() {
164 glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_DEPT
165 ejes();
166 luces();
167 glPushMatrix();
168 glTranslatef(posx, posy, 0);
169 glRotatef(anguloy,1.0,0.0,0.0);
170 glRotatef(angulox,0.0,1.0,0.0);
171 glRotatef(angulo, 1, 0, 0);
172 glRotatef(angulo, 0, 1, 0);
173 glRotatef(angulo, 0, 0, 1);
174 glScalef(esc, esc, esc);
175 glColor3f(1, 0, 0);
176 if(luz==1)
177 glEnable(GL_LIGHTING);
178 switch(figura) {
179 case 1: glutSolidTorus(20, 80, 18, 18);break;
180 case 2: glutSolidSphere(100, 18, 18);break;
181 case 3: glutSolidCone(50, 200, 18, 18);break;
182 case 4: glutSolidCube(100); break;
183 case 5: glutSolidTeapot(120);break;
184 }
185 glDisable(GL_LIGHTING);

Page 5 of 6
siete.c 11/6/2020 11:21

186 glPopMatrix();
187 glutSwapBuffers();
188 }
189
190 void ejes() {
191 glColor3f(0.9, 0.9, 0.9);
192 glBegin(GL_LINES);
193 glVertex3f(-ancho/2, 0, 0);
194 glVertex3f(ancho/2, 0, 0);
195 glVertex3f(0, alto/2, 0);
196 glVertex3f(0, -alto/2, 0);
197 glEnd();
198 }
199
200 void tecladoNormal(unsigned char tecla, int x, int y) {
201 switch(tecla) {
202 case 27: exit(0);break;
203 }
204 }
205

Page 6 of 6

You might also like