-
Notifications
You must be signed in to change notification settings - Fork 0
/
mupa.cpp
143 lines (123 loc) · 3.15 KB
/
mupa.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
#include <GL/glut.h>
#include <GL/freeglut.h>
#include <stdlib.h>
#include <math.h>
#include <fstream>
#include <time.h>
#include "glm/glm.hpp"
#include "glm/gtc/matrix_transform.hpp"
#include "glm/gtc/type_ptr.hpp"
GLuint texture_id[40];
// Direção da camera
float lx = 0.0f, lz = -1.0f;
float deltaAngle = 0.0f;
int xOrigin = -1;
// XZ posição
float x = 10.0f, z = 50.0f;
int mouseX, mouseY;
GLuint texture;
// Ângulos
float angle = 0.0f;
float door_angle = 0.0f;
float fovy = 70.0f;
float cam = 3.5f;
// Alturas
float floor2_thickness = 0.2f;
float floor1_height = 1.0f;
float wall_height = 0.2f;
float floor2_height = 0.2f;
GLUquadricObj *quadratic;
#include "Camera.h"
#include "Texture.h"
#include "DrawObjects.h"
#include "DrawWall.h"
#include "Draw.h"
#include "Lightning.h"
float currentFrame;
void init(void) {
quadratic = gluNewQuadric();
glClearColor(0.0, 0.7, 1.0, 1.0);
loadTextures();
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHT2);
glEnable(GL_LIGHT3);
glEnable(GL_LIGHT4);
glEnable(GL_LIGHT5);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
glShadeModel(GL_SMOOTH);
}
void changeSize(int w, int h) {
if (h == 0) h = 1;
float ratio = w * 1.0 / h;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, w, h);
gluPerspective(fovy, ratio, 0.1f, 1000.0f);
glMatrixMode(GL_MODELVIEW);
}
void renderScene(void) {
currentFrame = glutGet(GLUT_ELAPSED_TIME);
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
processCamera();
lightsSetup();
draw();
glFlush();
glutSwapBuffers();
}
void processSpecialKeys(int key, int xx, int yy) {
float fraction = 0.5f;
switch (key) {
case GLUT_KEY_LEFT :
angle -= 0.05f;
lx = sin(angle);
lz = -cos(angle);
break;
case GLUT_KEY_RIGHT :
angle += 0.05f;
lx = sin(angle);
lz = -cos(angle);
break;
case GLUT_KEY_UP :
x += lx * fraction;
z += lz * fraction;
break;
case GLUT_KEY_DOWN :
x -= lx * fraction;
z -= lz * fraction;
break;
case GLUT_KEY_PAGE_UP :
cam += 0.1;
break;
case GLUT_KEY_PAGE_DOWN :
cam -= 0.1;
break;
}
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA);
glutInitWindowPosition(50, 50);
glutInitWindowSize(800, 600);
glutCreateWindow("MUPA");
init();
glutDisplayFunc(renderScene);
glutReshapeFunc(changeSize);
glutIdleFunc(renderScene);
glutKeyboardFunc(processNormalKeys);
glutSpecialFunc(processSpecialKeys);
glutPassiveMotionFunc(mouseMovement);
glutMouseFunc(mouseButton);
glutMotionFunc(mouseMotion);
glutMainLoop();
return 1;
}