-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCamera.cpp
80 lines (67 loc) · 1.48 KB
/
Camera.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
#include "Header Files/Include.h"
Camera::Camera(GLFWwindow* window, vec3 pos, vec3 point, vec3 up)
{
m_position = pos;
m_direction = normalize(m_position - point);
m_up = up;
m_parallel = { 1, 0, 0 };
m_window = window;
m_viewMatrix = lookAt(m_position, m_direction, m_up);
}
Camera::~Camera()
{
}
vec3 Camera::GetDir()
{
return m_direction;
}
vec3 Camera::GetPos()
{
return m_position;
}
vec3 Camera::GetUp()
{
return m_up;
}
inline mat4 Camera::GetView()
{
return m_viewMatrix;
}
void Camera::ChangePos(vec3 pos)
{
m_position = pos;
}
void Camera::ChangeDir(vec3 dir)
{
m_direction = dir;
}
void Camera::ChangeUp(vec3 up)
{
m_up = up;
}
void Camera::MoveCamera(vec3 newPos)
{
m_position += newPos;
m_viewMatrix = lookAt(m_position, m_position + m_direction, m_up);
}
void Camera::UpdateMovement(float deltaTime, float speed)
{
bool pressed = false;
if (glfwGetKey(m_window, GLFW_KEY_W) == GLFW_PRESS) {
m_position += m_direction * deltaTime * speed;
pressed = true;
}
if (glfwGetKey(m_window, GLFW_KEY_S) == GLFW_PRESS) {
m_position -= m_direction * deltaTime * speed;
pressed = true;
}
if (glfwGetKey(m_window, GLFW_KEY_D) == GLFW_PRESS) {
m_position += m_parallel * deltaTime * speed;
pressed = true;
}
if (glfwGetKey(m_window, GLFW_KEY_A) == GLFW_PRESS) {
m_position -= m_parallel * deltaTime * speed;
pressed = true;
}
m_viewMatrix = lookAt(m_position, m_direction, m_up);
}