-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
220 lines (185 loc) · 5.52 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
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
/*
Greetings Fegemo !
Francisco Abreu :D
Marco Túlio Siqueira da Mata :P
CG (2019.2) Prof. Flávio Coutinho
Eng. Comp
CEFET_MG
*/
#include <GL/glew.h>
#include <GL/freeglut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <SOIL/SOIL.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include "Controles.h"
#include "DesenhaGeral.h"
enum { MENU,PLAYING,OPTIONS,PAUSE};
int gameMode; //sem tempo de implementar
GLfloat cor[] = { 0.2, 0.2, 0.3 };//para o fog
void inicilizaLuzes(){
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
glEnable(GL_COLOR_MATERIAL);
glShadeModel (GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mShininess);
glLightfv(GL_LIGHT0, GL_SPECULAR, white);
glLightfv(GL_LIGHT0, GL_AMBIENT, luzSol);
glLightfv(GL_LIGHT0, GL_DIFFUSE, luzSol);
}
void inicilizaValores(){
cam.posx = 0;
cam.posy = 50;
cam.posz = 100;
cam.lx = 1;
cam.ly = 0;
cam.lz = 0;
cam.teta = 0;
cam.phi = PI / 2;
cam.mode = PANORAMICA;
cam.vel = 0.5;// passos curtos para suaavidade
mouse.scroll = 50;//0 a 100
gameMode = PLAYING; //Mudar para menu na versao fina
isDay=1;
lightOn=1;
fogOn=1;
phisol=PI/2;//começa de manha
}
void inicializa() {
glClearColor(0, .5, 1, 1);//azul bebe do fundo que depois sera modificado
inicilizaValores();
glEnable(GL_DEPTH_TEST);
glEnable( GL_BLEND );
glFogi(GL_FOG_MODE, GL_EXP2);
glFogfv(GL_FOG_COLOR, cor);
glFogf(GL_FOG_DENSITY, .005);
glHint(GL_FOG_HINT, GL_NICEST);
glFogf(GL_FOG_START, 60.f);
glFogf(GL_FOG_END, 100.0f);
glEnable(GL_FOG); // inicialmente ligado
glClearDepth(1);
inicilizaLuzes();
}
void setLookAt() {
cam.lx = 100 * ((double)mouse.scroll / 100) * sin(cam.phi) * cos(cam.teta);
cam.lz = 100 * ((double)mouse.scroll / 100) * sin(cam.phi) * sin(cam.teta);
cam.ly = 100 * ((double)mouse.scroll / 100) * cos(cam.phi);
switch (cam.mode)//melhor parte ever
{
case stPerson: {
gluLookAt(
cam.posx, cam.posy, cam.posz,
cam.posx+cam.lx, cam.posy+cam.ly, cam.posz+cam.lz,
0, 1, 0
);
break;
}
case sphericCam: {
gluLookAt(
cam.posx + cam.lx, cam.posy + cam.ly, cam.posz + cam.lz,
cam.posx, cam.posy, cam.posz,
0, 1, 0
);
break;
}
case PANORAMICA: {
gluLookAt(200*cos(angulocamera),100,100+200*sin(angulocamera),0,30,100, 0, 1, 0);
break;
}
case AMPLIADA: {
switch(visaoBrinquedos){//visao da entrada do parque na perspectiva de um visitante
case -1:
gluLookAt(0,50,100,-50,30,10*10,0,1,0);
break;
case 0:
gluLookAt(-1,5,5,-1,5,15,0,1,0);
break;
case 1:
gluLookAt(-2,5,10,5,5,10,0,1,0);
break;
}
break;
}
case centroParque:{
switch(visaoBrinquedos){//visao da entrada do parque na perspectiva de um visitante
case -1:
gluLookAt(-10,30,110,-10+1,30,110,0,1,0);
break;
case 0:
gluLookAt(-10,30,110,-10-1,30,110,0,1,0);
break;
case 1:
gluLookAt(-10,30,110,-10,30,110+1,0,1,0);
break;
}
break;
}
}
}
void desenhaCena() {
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glPushMatrix();
{
setLookAt();
if(lightOn){
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
}else{
glDisable(GL_LIGHTING);
glDisable(GL_LIGHT0);
glDisable(GL_LIGHT1);
}
if(fogOn){
glEnable(GL_FOG);
}else{
glDisable(GL_FOG);
}
glScalef(10,10,10);//estava muito pequeno
desenhaCenario();//esta na desenhaGeral
desenhaBrinquedos();//idem
}
glPopMatrix();
glutSwapBuffers();
}
void redesenha(int tempo){
glutPostRedisplay();
glutTimerFunc(1000/60,redesenha,0);
}
void redimensiona(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(cam.mode==stPerson?fov:75,(float)(w)/h, 1, 1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc, char* argv[]) {
glutInit(&argc, argv);
glutInitContextVersion(2, 1);
glutInitContextProfile(GLUT_COMPATIBILITY_PROFILE);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(w_width, w_height);
glutCreateWindow("Magnificent SimpleForms World");//logo, é obviamente explicito que se trata de um parque tematico :xx
glutFullScreen();
glutReshapeFunc(redimensiona);
glutDisplayFunc(desenhaCena);
glutKeyboardFunc(teclado);
glutSetCursor(GLUT_CURSOR_NONE);//o mouse reseta sempra para o meio, mas vc nao o ve :D
glutMouseFunc(mousesao);//para clicks
glutPassiveMotionFunc(mousesaoDinamico);//para efeito hover
glutTimerFunc(1000/60,redesenha,0);
glutTimerFunc(1000/60,rotacao,0);
glutTimerFunc(1000/60,mov_camera,0);
glutTimerFunc(1000/60,dayLightCycle,0);
inicializa();
glutMainLoop();
return 0;
}