-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcamera.h
57 lines (39 loc) · 1.27 KB
/
camera.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// Created by legend on 5/26/20.
//
#pragma once
#include <vector>
#include <glm/glm.hpp>
static const char* CameraModes[] = {"perspective", "orthographic", "spherical"};
class Camera
{
public:
explicit Camera(float aspect);
void translate(const glm::vec3 &in_translation);
void rotate(const glm::vec3 &in_rotation);
void set_fov(float fov);
void set_scale(float scale);
void set_camera_mode(int mode);
// Prevent looking beyond +/- 90 degrees vertically
void clamp_vertical_view_angle(bool clamp);
void update_imgui();
[[nodiscard]] float get_fov() const noexcept;
[[nodiscard]] float get_scale() const noexcept;
[[nodiscard]] int get_camera_mode() const noexcept;
[[nodiscard]] std::vector<glm::vec4> get_data();
[[nodiscard]] glm::mat4 get_camera_matrix();
[[nodiscard]] glm::mat4 get_view_matrix();
[[nodiscard]] glm::mat4 get_pv_matrix();
private:
void _update_values();
int mode = 0;
float fov = 90.f, scale = 4.f, aspect{};
bool vertical_view_angle_clamp = false;
glm::vec3 translation{};
glm::vec3 rotation{};
glm::mat4 camera_matrix{1.f};
/* view = inverse(camera_matrix) */
glm::mat4 view_matrix{1.f};
/* projection * view matrix */
glm::mat4 pv_matrix{1.f};
};