-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
159 lines (122 loc) · 3.57 KB
/
Main.cpp
File metadata and controls
159 lines (122 loc) · 3.57 KB
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
#include <GLFW/glfw3.h>
#include <cmath>
#include <iostream>
#include <SOIL.h>
using namespace std;
#include "windowConfig.h"
#include "glUtils.h"
#include "ShapeDrawer.h"
#include "LabirinthDrawer.h"
#include "Camera.h"
#include "Labirinth.h"
#include "Character.h"
Camera *camera;
LabirinthDrawer *labirinthDrawer;
Labirinth *labirinth;
Character *character;
double currentFrame, deltaTime, lastFrame, t = 0;
bool thirdPerson = false;
bool minimap = false;
int aim;
float spin = 0;
void configuraLuz(){
glShadeModel (GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}
void setLuz(){
GLfloat position[] = { 0.0, 0.0, -3, 1.0 };
glPushMatrix ();
glTranslatef (0.0, 0.0, position[2]);
glPushMatrix ();
glLightfv (GL_LIGHT0, GL_POSITION, position);
glTranslated (0.0, 0.0, position[2]);
glDisable (GL_LIGHTING);
glColor3f (1.0, 1.0, 1.0);
glPushMatrix();
glScaled(0.1,0.1,0.1);
ShapeDrawer::cube(aim);
glPopMatrix();
glEnable (GL_LIGHTING);
glPopMatrix ();
}
void controls(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if(action == GLFW_PRESS){
if(key == GLFW_KEY_ESCAPE)
glfwSetWindowShouldClose(window, GL_TRUE);
if(key == GLFW_KEY_3){
thirdPerson = !thirdPerson;
}
if(key == GLFW_KEY_M){
minimap = !minimap;
}
/* if(key == GLFW_KEY_B){
bp = !bp;
}*/
}
}
void display( GLFWwindow* window )
{
float ratio;
static float angle = 0;
glfwSetInputMode(window, GLFW_STICKY_KEYS, 1);
float position[] = {0,0,0};
int pi, pj;
configuraLuz();
while(!glfwWindowShouldClose(window))
{
currentFrame = glfwGetTime();
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
// Scale to window size
GLint windowWidth, windowHeight;
glfwGetFramebufferSize(window, &windowWidth, &windowHeight);
// printf("w %d, h %d\n", windowWidth, windowHeight);
glViewport(0, 0, windowWidth, windowHeight);
ratio = windowWidth / (float) windowHeight;
// printf("ratio: %f\n", ratio);
// Draw stuff
glClearColor(0.0, 0.8, 0.3, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION_MATRIX);
glLoadIdentity();
glPerspective(45, ratio, 1.0f, 200.0f);
glMatrixMode(GL_MODELVIEW_MATRIX);
if(minimap){
camera->getEye(position);
labirinthDrawer->drawMinimap(position);
}
setLuz();
if(thirdPerson){
character->draw();
}
camera->look();
labirinthDrawer->draw();
camera->processKeyboardInput(window, deltaTime);
glfwSwapBuffers(window);
glfwPollEvents();
}
}
int main(int argc, char** argv)
{
GLuint texture, texture2, texturePlayer;
GLFWwindow* window = initWindow("Labirinth", 1024, 620, controls);
if( NULL != window )
{
glfwWindowHint(GLFW_REFRESH_RATE, 60);
texture = aim = carregaTextura("bg3.png");
texture2 = carregaTextura("bg.png");
texturePlayer = carregaTextura("bgPLayer.png");
labirinth = new Labirinth(20,20);
labirinth->generate();
labirinth->print();
character = new Character(texturePlayer);
labirinthDrawer = new LabirinthDrawer(texture, texture2, labirinth);
camera = new Camera(-72, 40, labirinthDrawer, character);
display( window );
}
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}