]> git.localhorst.tv Git - blank.git/blob - src/camera.hpp
88da8caf858aff87a3aacada9bd8cf865d2c300e
[blank.git] / src / camera.hpp
1 #ifndef BLANK_CAMERA_HPP_
2 #define BLANK_CAMERA_HPP_
3
4 #include <glm/glm.hpp>
5
6 #include "model.hpp"
7
8
9 namespace blank {
10
11 class Camera {
12
13 public:
14         Camera();
15         ~Camera();
16
17         Camera(const Camera &) = delete;
18         Camera &operator =(const Camera &) = delete;
19
20         glm::mat4 MakeMVP(const glm::mat4 &m) const { return vp * m; }
21
22         void Viewport(int width, int height);
23         void Viewport(int x, int y, int width, int height);
24
25         void FOV(float f);
26         void Aspect(float r);
27         void Aspect(float w, float h);
28         void Clip(float near, float far);
29
30         void Position(glm::vec3 pos) { model.Position(pos); UpdateView(); }
31         void Move(glm::vec3 delta) { model.Move(delta); UpdateView(); }
32
33         // all angles in radians (full circle = 2π)
34         float Pitch() const { return model.Pitch(); }
35         void Pitch(float p) { model.Pitch(p); UpdateView(); }
36         void RotatePitch(float delta) { model.RotatePitch(delta); UpdateView(); }
37         float Yaw() const { return model.Yaw(); }
38         void Yaw(float y) { model.Yaw(y); UpdateView(); }
39         void RotateYaw(float delta) { model.RotateYaw(delta); UpdateView(); }
40
41 private:
42         void UpdateProjection();
43         void UpdateView();
44
45 private:
46         float fov;
47         float aspect;
48         float near_clip;
49         float far_clip;
50
51         Model model;
52
53         glm::mat4 projection;
54         glm::mat4 view;
55         glm::mat4 vp;
56
57 };
58
59 }
60
61 #endif