]> git.localhorst.tv Git - blank.git/blob - src/camera.cpp
rename model -> controller
[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 , vp(projection) {
17
18 }
19
20 Camera::~Camera() {
21
22 }
23
24
25 void Camera::Viewport(int width, int height) {
26         Viewport(0, 0, width, height);
27 }
28
29 void Camera::Viewport(int x, int y, int width, int height) {
30         glViewport(x, y, width, height);
31         Aspect(width, height);
32 }
33
34 void Camera::FOV(float f) {
35         fov = f;
36         UpdateProjection();
37 }
38
39 void Camera::Aspect(float r) {
40         aspect = r;
41         UpdateProjection();
42 }
43
44 void Camera::Aspect(float w, float h) {
45         Aspect(w / h);
46 }
47
48 void Camera::Clip(float near, float far) {
49         near_clip = near;
50         far_clip = far;
51         UpdateProjection();
52 }
53
54
55 void Camera::Update(int dt) {
56         FPSController::Update(dt);
57         vp = projection * glm::inverse(Transform());
58 }
59
60 void Camera::UpdateProjection() {
61         projection = glm::perspective(fov, aspect, near_clip, far_clip);
62 }
63
64 }