]> git.localhorst.tv Git - blank.git/blob - src/camera.cpp
21df87414cee2ce382a3e2014efb94187c602240
[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 : fov(45.0f)
11 , aspect(1.0f)
12 , near_clip(0.1f)
13 , far_clip(100.0f)
14 , model()
15 , projection(glm::perspective(fov, aspect, near_clip, far_clip))
16 , view(model.Transform())
17 , vp(projection * view) {
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::UpdateProjection() {
57         projection = glm::perspective(fov, aspect, near_clip, far_clip);
58         vp = projection * view;
59 }
60
61 void Camera::UpdateView() {
62         view = glm::inverse(model.Transform());
63         vp = projection * view;
64 }
65
66 }