]> git.localhorst.tv Git - blank.git/blob - src/camera.cpp
fix dec/rad error in camera FOV
[blank.git] / src / camera.cpp
1 #include "camera.hpp"
2
3 #include "geometry.hpp"
4
5 #include <GL/glew.h>
6 #include <glm/gtc/matrix_transform.hpp>
7
8
9 namespace blank {
10
11 Camera::Camera()
12 : fov(PI_0p25)
13 , aspect(1.0f)
14 , near_clip(0.1f)
15 , far_clip(256.0f)
16 , projection(glm::perspective(fov, aspect, near_clip, far_clip)) {
17
18 }
19
20
21 void Camera::Viewport(int width, int height) {
22         Viewport(0, 0, width, height);
23 }
24
25 void Camera::Viewport(int x, int y, int width, int height) {
26         glViewport(x, y, width, height);
27         Aspect(width, height);
28 }
29
30 void Camera::FOV(float f) {
31         fov = f;
32         UpdateProjection();
33 }
34
35 void Camera::Aspect(float r) {
36         aspect = r;
37         UpdateProjection();
38 }
39
40 void Camera::Aspect(float w, float h) {
41         Aspect(w / h);
42 }
43
44 void Camera::Clip(float near, float far) {
45         near_clip = near;
46         far_clip = far;
47         UpdateProjection();
48 }
49
50
51 void Camera::UpdateProjection() {
52         projection = glm::perspective(fov, aspect, near_clip, far_clip);
53 }
54
55 }