-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrincipal.cpp
287 lines (228 loc) · 8.53 KB
/
Principal.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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#include "DesenhaTanque.h"
#include "LeituraArquivo.h"
#include "imageloader.h"
bool lido = true;
bool lido2 = true;
GLuint chao;
GLuint tijolo;
GLuint teto;
GLuint teleporte;
GLuint LoadTextureRAW( const char * filename );
void DisplayChao(GLuint texture)
{
GLfloat materialEmission[] = { 1.0, 1.0, 1.0, 1};
GLfloat materialColorA[] = { 0.2, 0.2, 0.2, 1};
GLfloat materialColorD[] = { 1.0, 1.0, 1.0, 1};
GLfloat mat_specular[] = { 1.0, 0.0, 0.0, 1};
GLfloat mat_shininess[] = { 100.0 };
glColor3f(1,1,1);
glMaterialfv(GL_FRONT, GL_EMISSION, materialEmission);
glMaterialfv(GL_FRONT, GL_AMBIENT, materialColorA);
glMaterialfv(GL_FRONT, GL_DIFFUSE, materialColorD);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glBindTexture (GL_TEXTURE_2D, texture);
double textureS = 1;
glBegin (GL_QUADS);
glNormal3f(0,1,0);
glTexCoord2f (0, 0);
glVertex3f (0, 0, -1);
glNormal3f(0,1,0);
glTexCoord2f (0, textureS);
glVertex3f (0, altura, -1);
glNormal3f(0,1,0);
glTexCoord2f (textureS, textureS);
glVertex3f (largura, altura, -1);
glNormal3f(0,1,0);
glTexCoord2f (textureS, 0);
glVertex3f (largura, 0, -1);
glEnd();
}
void DisplayTeto(GLuint texture)
{
GLfloat materialEmission[] = { 1.0, 1.0, 1.0, 1};
GLfloat materialColorA[] = { 0.2, 0.2, 0.2, 1};
GLfloat materialColorD[] = { 1.0, 1.0, 1.0, 1};
GLfloat mat_specular[] = { 1.0, 0.0, 0.0, 1};
GLfloat mat_shininess[] = { 100.0 };
glColor3f(1,1,1);
glMaterialfv(GL_FRONT, GL_EMISSION, materialEmission);
glMaterialfv(GL_FRONT, GL_AMBIENT, materialColorA);
glMaterialfv(GL_FRONT, GL_DIFFUSE, materialColorD);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
// glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
// glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
glBindTexture (GL_TEXTURE_2D, texture);
double textureS = 1;
glBegin (GL_QUADS);
glNormal3f(0,1,0);
glTexCoord2f (0, 0);
glVertex3f (0, 0, 33);
glNormal3f(0,1,0);
glTexCoord2f (0, textureS);
glVertex3f (0, altura, 33);
glNormal3f(0,1,0);
glTexCoord2f (textureS, textureS);
glVertex3f (largura, altura, 33);
glNormal3f(0,1,0);
glTexCoord2f (textureS, 0);
glVertex3f (largura, 0, 33);
glEnd();
}
void desenha2d()
{
for (int iterador = 0; iterador <= vetorCirculos.size() - 1; iterador++)
{
teletransporte(vetorRetangulos[indice_tlp].altura, vetorRetangulos[indice_tlp].largura, vetorRetangulos[indice_tlp].ponto_x, vetorRetangulos[indice_tlp].ponto_y, vetorRetangulos[indice_tlp2].ponto_x, vetorRetangulos[indice_tlp2].ponto_y, &(vetorTanques[iterador]));
DesenhaTanque2d(&vetorTanques[iterador]);
}
for (int iterador = 0; iterador <= vetorRetangulos.size() - 1; iterador++)
if(indice_tlp != iterador && indice_tlp2 != iterador)
desenhaRetangulo2d(vetorRetangulos[iterador]);
desenhaRetangulo2d(vetorRetangulos[indice_tlp]);
desenhaRetangulo2d(vetorRetangulos[indice_tlp2]);
}
void desenha()
{
DisplayChao(chao);
DisplayTeto(teto);
for (int iterador = 0; iterador <= vetorCirculos.size() - 1; iterador++)
{
teletransporte(vetorRetangulos[indice_tlp].altura, vetorRetangulos[indice_tlp].largura, vetorRetangulos[indice_tlp].ponto_x, vetorRetangulos[indice_tlp].ponto_y, vetorRetangulos[indice_tlp2].ponto_x, vetorRetangulos[indice_tlp2].ponto_y, &(vetorTanques[iterador]));
DesenhaTanque(&vetorTanques[iterador]);
}
for (int iterador = 0; iterador <= vetorRetangulos.size() - 1; iterador++)
if(indice_tlp != iterador && indice_tlp2 != iterador)
desenhaRetangulo(vetorRetangulos[iterador], tijolo, teleporte);
desenhaRetangulo(vetorRetangulos[indice_tlp], tijolo, teleporte);
desenhaRetangulo(vetorRetangulos[indice_tlp2], tijolo, teleporte);
}
void DesenhaCena()
{
GLfloat materialEmission[] = { 0.0, 0.0, 0.0, 1};
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1};
GLfloat mat_shininess[] = { 100.0 };
glMaterialfv(GL_FRONT, GL_EMISSION, materialEmission);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
idle();
glMatrixMode(GL_PROJECTION);
atualizaCamera();
desenha();
atualizaCamera2();
desenha();
atualizaCamera3();
desenha2d();
glEnable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
glutSwapBuffers();
}
void idle1()
{
glutPostRedisplay();
}
void init(void)
{
ResetKeyStatus();
glShadeModel (GL_SMOOTH);
glEnable(GL_LIGHTING); //DEIXA TUDO BRANCO BRANCO
glEnable(GL_DEPTH_TEST);
glEnable (GL_LINE_SMOOTH);
glEnable( GL_TEXTURE_2D );
glLineWidth (1.5);
chao = LoadTextureRAW( "chao.bmp" );
tijolo = LoadTextureRAW( "mario.bmp" );
teto = LoadTextureRAW( "ceu.bmp" );
teleporte = LoadTextureRAW( "goku.bmp" );
glEnable(GL_LIGHT0);
//DIRECIONAL
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess[] = { 50.0 };
GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_SMOOTH);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
//SPOT
GLfloat light1_ambient[] = { 0.2, 0.2, 0.2, 1.0 };
GLfloat light1_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light1_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light1_position[] = { -2.0, 2.0, 1.0, 1.0 };
GLfloat spot_direction[] = { -1.0, -1.0, 0.0 };
glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_diffuse);
glLightfv(GL_LIGHT1, GL_SPECULAR, light1_specular);
glLightfv(GL_LIGHT1, GL_POSITION, light1_position);
glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 1.5);
glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.5);
glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.2);
glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 45.0);
glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, spot_direction);
glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 2.0);
glEnable(GL_LIGHT1);
}
int main(int argc, char *argv[])
{
if(lido)
{
arquivo_XML();
arquivo_SVG();
arquivo_PGM();
arquivo2_PGM();
menorMaior();
indice_tanque = tanque_jogador;
lido = false;
for (int iterador = 0; iterador <= vetorCirculos.size() - 1; iterador++)
{
if(iterador == tanque_jogador)
inicializa_tanque(vetorCirculos[iterador].centro_x, vetorCirculos[iterador].centro_y, vetorCirculos[iterador].raio, true);
else
inicializa_tanque(vetorCirculos[iterador].centro_x, vetorCirculos[iterador].centro_y, vetorCirculos[iterador].raio, false);
}
}
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500, 700);
glutInitWindowPosition(0,0);
glutCreateWindow("TRABALHO CURTO 4");
glutDisplayFunc(idle1);
glutKeyboardFunc(keyPress);
glutIdleFunc(DesenhaCena);
glutKeyboardUpFunc(keyup);
glutPassiveMotionFunc(MoveCanhao);
glutMotionFunc(mouse_camera);
glutMouseFunc(GerenciaMouse);
glutTimerFunc(10000, tiro_adversario, 0);
init();
glutMainLoop();
return 0;
}
GLuint LoadTextureRAW( const char * filename )
{
GLuint texture;
Image* image = loadBMP(filename);
glGenTextures( 1, &texture );
glBindTexture( GL_TEXTURE_2D, texture );
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_MODULATE );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR );
glTexImage2D(GL_TEXTURE_2D, //Always GL_TEXTURE_2D
0, //0 for now
GL_RGB, //Format OpenGL uses for image
image->width, image->height, //Width and height
0, //The border of the image
GL_RGB, //GL_RGB, because pixels are stored in RGB format
GL_UNSIGNED_BYTE, //GL_UNSIGNED_BYTE, because pixels are stored
//as unsigned numbers
image->pixels); //The actual pixel data
delete image;
return texture;
}