-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamera.cpp
More file actions
42 lines (35 loc) · 935 Bytes
/
Copy pathCamera.cpp
File metadata and controls
42 lines (35 loc) · 935 Bytes
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
#include "Camera.h"
Camera::Camera()
{
}
Camera::Camera(glm::vec3 position, glm::vec3 forward, glm::vec3 up)
: Position{ position }, Forward{ forward }, Up{ up }
{
updateView();
}
void Camera::update(float deltaTime)
{
updateCameraVectors();
}
void Camera::setPerspective(float fov, float aspect, float near, float far)
{
Projection = glm::perspective(fov, aspect, near, far);
Fov = fov;
Aspect = aspect;
Near = near;
Far = far;
}
void Camera::updateView()
{
View = glm::lookAt(Position, Position + Forward, Up);
}
void Camera::updateCameraVectors()
{
glm::vec3 front;
front.x = cos(glm::radians(Yaw)) * cos(glm::radians(Pitch));
front.y = sin(glm::radians(Pitch));
front.z = sin(glm::radians(Yaw)) * cos(glm::radians(Pitch));
Forward = glm::normalize(front);
Right = glm::normalize(glm::cross(Forward, WorldUp));
Up = glm::normalize(glm::cross(Right, Forward));
}