Graphics v0.0.0
A simple abstraction layer for the modern graphics APIs.
载入中...
搜索中...
未找到
Camera.h
1// Copyright 2022 ShenMian
2// License(Apache-2.0)
3
4#pragma once
5
6#include <math/math.hpp>
7
11class Camera
12{
13public:
17 enum class Type
18 {
19 Perspective, // 透视投影
20 Orthographic // 正交投影
21 };
22
28 Camera(Type type);
29
38 void set_perspective(float vFOV, float aspectRatio, float near, float far);
39
48 void set_orthographic(float width, float height, float near, float far);
49
53 Type get_type() const;
54
58 float get_vfov() const;
59
63 float get_hfov() const;
64
68 float get_aspect_ratio() const;
69
73 float get_near() const;
74
78 float get_far() const;
79
85 void set_position(const Vector3f& pos);
86
90 const Vector3f& get_position() const;
91
100 void set_rotation(const Vector3f& rot);
101
105 const Vector3f& get_rotation() const;
106
107 Vector3f get_front() const;
108 Vector3f get_right() const;
109 Vector3f get_up() const;
110
114 const Matrix4& get_view() const;
115
119 const Matrix4& get_projection() const;
120
121protected:
125 void update_projection_matrix() const;
126
130 void update_view_matrix() const;
131
133 {
134 float vFOV;
135 float aspectRatio;
136 float near;
137 float far;
138 };
139
141 {
142 float width;
143 float height;
144 float near;
145 float far;
146 };
147
148 union {
149 Perspective perspective_;
150 Orthographic orthographic_;
151 };
152
153 Type type_;
154
155 Vector3f position_;
156 Vector3f rotation_;
157 Vector3f up_ = -Vector3f({0.f, 1.f, 0.f}); // TODO
158
159 mutable Matrix4 projection_;
160 mutable bool projection_dirty_ = true;
161 mutable Matrix4 view_;
162 mutable bool view_dirty_ = true;
163};
摄像机.
Definition: Camera.h:12
float get_hfov() const
获取水平视角范围, 单位: 弧度.
Definition: Camera.cpp:86
float get_near() const
获取近裁剪平面距离.
Definition: Camera.cpp:100
void set_position(const Vector3f &pos)
设置相机坐标.
Definition: Camera.cpp:36
void update_view_matrix() const
更新视图矩阵.
Definition: Camera.cpp:131
float get_far() const
获取远裁剪平面距离.
Definition: Camera.cpp:105
Type
投影类型.
Definition: Camera.h:18
float get_vfov() const
获取垂直视角范围, 单位: 弧度.
Definition: Camera.cpp:78
const Vector3f & get_position() const
获得相机坐标.
Definition: Camera.cpp:42
const Matrix4 & get_view() const
获取观察矩阵.
Definition: Camera.cpp:110
void update_projection_matrix() const
更新投影矩阵.
Definition: Camera.cpp:122
const Matrix4 & get_projection() const
获取投影矩阵.
Definition: Camera.cpp:116
const Vector3f & get_rotation() const
获取绕各轴旋转的角度.
Definition: Camera.cpp:53
void set_rotation(const Vector3f &rot)
设置绕各轴旋转的角度.
Definition: Camera.cpp:47
float get_aspect_ratio() const
获取宽高比.
Definition: Camera.cpp:92
Type get_type() const
获取投影类型.
Definition: Camera.cpp:31
void set_perspective(float vFOV, float aspectRatio, float near, float far)
设置截头锥体观察体, 用于透视投影.
Definition: Camera.cpp:11
void set_orthographic(float width, float height, float near, float far)
设置正投影观观察体, 用于正交投影.
Definition: Camera.cpp:21
Definition: Camera.h:141
Definition: Camera.h:133