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