-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLabirinthDrawer.cpp
More file actions
209 lines (154 loc) · 5.16 KB
/
LabirinthDrawer.cpp
File metadata and controls
209 lines (154 loc) · 5.16 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
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
#include <GLFW/glfw3.h>
#include <iostream>
using namespace std;
#include "ShapeDrawer.h"
#include "LabirinthDrawer.h"
LabirinthDrawer::LabirinthDrawer(int textureCube, int textureFc, Labirinth *labirinth){
this->textureCube = textureCube;
this->textureFc = textureFc;
this->labirinth = labirinth;
mx = 17.7; //Valores calibrados
my = -9.3; //Valores calibrados
mspeed = 0.245;
}
void LabirinthDrawer::drawCubeAt(int i, int j){
float position[] = {0,0,0};
getIndexPosition(i, j, position);
glPushMatrix();
glTranslatef(position[0], position[1], position[2]);
ShapeDrawer::cube(this->textureCube);
glPopMatrix();
}
void LabirinthDrawer::drawFloorCeilAt(int i, int j, int fc){
float position[] = {0,0,0};
getIndexPosition(i, j, position);
glPushMatrix();
glTranslatef(position[0], (fc?-2:fc), position[2]);
ShapeDrawer::square(this->textureFc);
glPopMatrix();
}
void LabirinthDrawer::draw(){//int **wallMatrix, int alt, int larg){
glPushMatrix();
glScalef(4,4,4);
float matAmbAndDif[] = {1.0, 1.0, 1.0, 1.0}; // cor ambiente e difusa: branca
float corInicio[] = {0.5, 0.5, 1.0, 1.0}; // cor ambiente e difusa: verde
float corFim[] = {1.0, 0.5, 0.5, 1.0}; // cor ambiente e difusa: verde
// Definindo as propriedades do material
int i, j;
for(i = 0; i <= 21; i++){
for(j = 0; j <= 21; j++){
if(i < 2 && j < 2){
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, corInicio);
}else if(i > 19 && j > 19){
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, corFim);
}else{
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, matAmbAndDif);
}
if(j <= 20 && i <= 20 && j > 0 && i > 0 ){
if(!this->labirinth->getBlockAt(i-1,j-1)){
LabirinthDrawer::drawCubeAt(i,j);
// LabirinthDrawer::drawFloorCeilAt(i,j,1);
}else{
LabirinthDrawer::drawFloorCeilAt(i,j,0);
LabirinthDrawer::drawFloorCeilAt(i,j,1);
}
}else{
LabirinthDrawer::drawCubeAt(i,j);
}
}
}
glPopMatrix();
}
void LabirinthDrawer::getIndexPosition(int i, int j, float *vec){
int n = 20;
int size = 2;
vec[0] = (i-(n/2))*size;
vec[2] = (j-(n/2))*size + 4*size;
vec[2] = -vec[2];
}
void LabirinthDrawer::getPositionIndex(int *i, int *j, float *vec3){
int n = 20;
int size = 2;
float vec[] = {vec3[0]/4.0f, vec3[1]/4.0f, vec3[2]/4.0f};
vec[2] = -vec[2];
*j = -((4*size - vec[2])/size)+(n/2);
*i = (vec[0]/size)+(n/2);
}
void LabirinthDrawer::drawMinimap(float *pos){
float size = 2;
glPushMatrix();
glDisable(GL_LIGHTING);
glTranslatef(0.5,0,-2);
glScalef(0.02,0.02,0.02);
glPushMatrix();
glRotatef(90, 1, 0, 0);
glRotatef(-90, 0, 1, 0);
glTranslatef(mx,0,my);
glTranslatef(pos[0]*mspeed,pos[1]*mspeed,pos[2]*mspeed);
glColor3f(1,0,1);
ShapeDrawer::circle(0,0, 0.5, 360);
glPopMatrix();
glRotatef(-90, 1, 0, 0);
glRotatef(90, 0, 1, 0);
for(int i = 0; i < 20; i++){
for(int j = 0; j < 20; j++){
glPushMatrix();
glTranslatef(((float)i)*size, 0, ((float)j)*size);
if(i == 0 && j == 0){
glColor3f(0,0,1);
ShapeDrawer::circle(0,0, 1, 360);
}else if(i == 19 && j == 19){
glColor3f(1,0,0);
ShapeDrawer::circle(0,0, 1, 360);
}
if(!this->labirinth->getBlockAt(i,j)){
ShapeDrawer::square(-1);
}
glPopMatrix();
}
}
glEnable(GL_LIGHTING);
glPopMatrix();
}
bool LabirinthDrawer::collidesWith(float *vec){
float position[] = {0,0,0};
float side = 5.5f;
bool xColl = false, zColl = false;
// return false;
for(int i = 0; i <= 21; i++){
for(int j = 0; j <= 21; j++){
getIndexPosition(i, j, position);
position[0] = position[0]*4;
position[1] = position[1]*4;
position[2] = position[2]*4;
xColl = (position[0]-side < vec[0] && position[0]+side > vec[0]);
zColl = (position[2]-side < vec[2] && position[2]+side > vec[2]);
if(xColl && zColl && !this->labirinth->getBlockAt(i-1,j-1)){
return true;
}
}
}
return false;
}
bool LabirinthDrawer::endsIn(float *vec){
float position[] = {0,0,0};
float side = 5.0f;
bool xColl = false, zColl = false;
getIndexPosition(20, 20, position);
position[0] = position[0]*4;
position[1] = position[1]*4;
position[2] = position[2]*4;
xColl = (position[0]-side < vec[0] && position[0]+side > vec[0]);
zColl = (position[2]-side < vec[2] && position[2]+side > vec[2]);
if(xColl && zColl){
return true;
}
return false;
}
//Debug para calcular os valores do minimapa
void LabirinthDrawer::inc(float mx, float my, float mspeed){
this->mx +=mx;
this->my +=my;
this->mspeed +=mspeed;
cout << "[ " << this->mx << ", " << this->my << ", " << this->mspeed << "] " <<endl;
}