-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera.cpp
63 lines (56 loc) · 1.39 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
#include "camera.hpp"
void Camera::UpdateCam(bool tab[4]) //trzeba przekazać do funkcji tablicę wynikową z obsługi klawiszy
{
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now();
std::chrono::duration<float> time = now - lastTime;
lastTime = now;
if (tab[up])
{
cPos += camSpeed * glm::normalize(glm::vec3(cDir.x, 0.f, cDir.z)) * time.count();
//cPos.y -= camSpeed * cDir.y;
}
if (tab[down])
{
cPos -= camSpeed * glm::normalize(glm::vec3(cDir.x, 0.f, cDir.z)) * time.count();
//cPos.y += camSpeed * cDir.y;
}
if (tab[left])
{
cPos -= camSpeed * cDirX * time.count();
}
if (tab[right])
{
cPos += camSpeed * cDirX * time.count();
}
}
glm::mat4 Camera::GetViewMatrix()
{
return glm::lookAt(cPos, cPos + cDir, cUp);
}
void Camera::MouseMov(float yaw, float pitch)
{
glm::vec3 direction;
direction.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch));
direction.y = sin(glm::radians(pitch));
direction.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch));
cDir = glm::normalize(direction);
cDirX = glm::normalize(glm::cross(cDir, cUp));
}
glm::vec3 Camera::getPos()
{
return cPos;
}
glm::vec3 Camera::getDir()
{
return cDir;
}
float Camera::getCamSpeed()
{
return camSpeed;
}
void Camera::UpdatePos(float* shift)
{
cPos.x += shift[0];
cPos.y += shift[1];
cPos.z += shift[2];
}