]> git.localhorst.tv Git - blank.git/blob - src/camera.cpp
fbf10bca2e1391a9f88522c0ba5ab9fe040475f1
[blank.git] / src / camera.cpp
1 #include "camera.hpp"
2
3 #include <GL/glew.h>
4 #include <glm/gtc/matrix_transform.hpp>
5
6
7 namespace blank {
8
9 Camera::Camera()
10 : FPSController()
11 , fov(45.0f)
12 , aspect(1.0f)
13 , near_clip(0.1f)
14 , far_clip(100.0f)
15 , projection(glm::perspective(fov, aspect, near_clip, far_clip))
16 , view(glm::inverse(Transform()))
17 , vp(projection) {
18
19 }
20
21 Camera::~Camera() {
22
23 }
24
25
26 void Camera::Viewport(int width, int height) {
27         Viewport(0, 0, width, height);
28 }
29
30 void Camera::Viewport(int x, int y, int width, int height) {
31         glViewport(x, y, width, height);
32         Aspect(width, height);
33 }
34
35 void Camera::FOV(float f) {
36         fov = f;
37         UpdateProjection();
38 }
39
40 void Camera::Aspect(float r) {
41         aspect = r;
42         UpdateProjection();
43 }
44
45 void Camera::Aspect(float w, float h) {
46         Aspect(w / h);
47 }
48
49 void Camera::Clip(float near, float far) {
50         near_clip = near;
51         far_clip = far;
52         UpdateProjection();
53 }
54
55
56 void Camera::Update(int dt) {
57         FPSController::Update(dt);
58         view = glm::inverse(Transform());
59         vp = projection * view;
60 }
61
62 void Camera::UpdateProjection() {
63         projection = glm::perspective(fov, aspect, near_clip, far_clip);
64 }
65
66 }