-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamera.cpp
More file actions
92 lines (81 loc) · 2.31 KB
/
Camera.cpp
File metadata and controls
92 lines (81 loc) · 2.31 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
#include <GLFW/glfw3.h>
#include <cmath>
#include <iostream>
using namespace std;
#include "glUtils.h"
#include "Camera.h"
Camera::Camera(float x, float z, LabirinthDrawer *labirinthDrawer, Character *character){
fraction = 24.0f;
angleSpeed = 3.0;
angle=0.0;
lx=0.0f;
lz=-1.0f;
this->labirinthDrawer = labirinthDrawer;
this->character = character;
this->initialX = this->x = x;//0.0f;
this->initialZ = this->z = z;//5.0f;
}
void Camera::processKeyboardInput(GLFWwindow* window, float deltaT){
float up[] = {x+(lx * fraction*deltaT), 0, z+(lz * fraction*deltaT)};
float down[] = {x-(lx * fraction*deltaT), 0, z-(lz * fraction*deltaT)};
float inc = 0.1, sp = 0.001;
if(glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS){
if(!labirinthDrawer->collidesWith(up)){
x += lx * fraction*deltaT;
z += lz * fraction*deltaT;
character->updateFrame(deltaT);
}
}else if(glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS){
if(!labirinthDrawer->collidesWith(down)){
x -= lx * fraction*deltaT;
z -= lz * fraction*deltaT;
character->updateFrame(-deltaT);
}
}
if(glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS){
angle -= angleSpeed*deltaT;
lx = sin(angle);
lz = -cos(angle);
}else if(glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_PRESS){
angle += angleSpeed*deltaT;
lx = sin(angle);
lz = -cos(angle);
}
getEye(up);
if(labirinthDrawer->endsIn(up)){
this->x = this->initialX;
this->z = this->initialZ;
}
/* //DEBUG para calibrar os valores do minimapa
if(glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS){
labirinthDrawer->inc(-inc,0,0);
}else if(glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS){
labirinthDrawer->inc(inc,0,0);
}
if(glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS){
labirinthDrawer->inc(0,inc,0);
}else if(glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS){
labirinthDrawer->inc(0,-inc,0);
}
if(glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS){
labirinthDrawer->inc(0,0,-sp);
}else if(glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS){
labirinthDrawer->inc(0,0,sp);
}*/
}
void Camera::look(){
glLookAt(x, 1.0f, z, x+lx, 1.0f, z+lz, 0.0f, 1.0f, 0.0f);
}
void Camera::getEye(float *eye){
eye[0] = x;
eye[1] = 1.0f;
eye[2] = z;
}
void Camera::getDirection(float *direction){
direction[0] = lx;
direction[1] = 0;
direction[2] = lz;
}
float Camera::getAngle(){
return this->angle;
}