xcal
基于 C++23 的现代图形渲染引擎
载入中...
搜索中...
未找到
abs_camera.hpp
浏览该文件的文档.
1
11#pragma once
12#include <xcal/public.h>
13
16#include <xcal/property/vec.hpp>
17#include <xcmath/xcmath.hpp>
18
19namespace xcal::camera {
20enum class CameraType {
23};
24#define XCAL_CAMERA_TYPE(tp) \
25 private: \
26 ::xcal::camera::CameraType type_() const noexcept override { \
27 return ::xcal::camera::CameraType::tp; \
28 }
29
44
45 private:
46 virtual CameraType type_() const noexcept = 0;
47 private:
48 /* 视图参数 */
49 property::Vec<float_t, 3> position_{0.f, 0.f, -1.f};
50 property::Vec<float_t, 3> target_{0.f, 0.f, 0.f};
51 property::Vec<float_t, 3> up_{0.f, 1.f, 0.f};
52 property::Color background_color_{0.f, 0.f, 0.f, 1.f};
53 mutable bool_t view_or_projection_has_changed_{
54 true};
55 mutable xcmath::mat<float_t, 4, 4> view_matrix_cache_{
57 mutable xcmath::mat<float_t, 4, 4> pv_matrix_cache_{
59
60 private:
65 void update_view_matrix() const;
66
67 public:
68 /* 获取投影矩阵 P */
73 property::Vec<float_t, 3>& position() { return position_; }
74
79 const property::Vec<float_t, 3>& position() const { return position_; }
80
85 property::Vec<float_t, 3>& target() { return target_; }
86
91 const property::Vec<float_t, 3>& target() const { return target_; }
92
97 property::Vec<float_t, 3>& up() { return up_; }
98
103 const property::Vec<float_t, 3>& up() const { return up_; }
104
110 property::Color& background_color() { return background_color_; }
111
118 return background_color_;
119 }
120
121 CameraType type() const { return type_(); }
128 template <typename... Args>
129 requires(std::is_constructible_v<vec, Args...>)
130 AbsCamera* set_position(Args&&... args) {
131 position_ = vec{float_t(std::forward<Args>(args))...};
132 return this;
133 }
134
141 template <typename... Args>
142 requires(std::is_constructible_v<vec, Args...>)
143 AbsCamera* set_target(Args&&... args) {
144 target_ = vec{float_t(std::forward<Args>(args))...};
145 return this;
146 }
147
154 template <typename... Args>
155 requires(std::is_constructible_v<vec, Args...>)
156 AbsCamera* set_up(Args&&... args) {
157 up_ = vec{float_t(std::forward<Args>(args))...};
158 return this;
159 }
166 template <typename... Args>
167 requires(std::is_constructible_v<property::Color::data_t, Args...>)
169 background_color_ =
170 property::Color::data_t{(float_t)std::forward<Args>(args)...};
171 return this;
172 }
173
174 /* 获取视图矩阵 V */
179 const xcmath::mat<float_t, 4, 4>& view_matrix() const;
180
181 protected:
186 void projection_has_changed() const;
187
188 public:
193
197 virtual ~AbsCamera() = default;
198
205
211 virtual bool_t projection_should_update() const = 0;
212
217 bool_t view_should_update() const;
218
223 bool_t should_update() const;
224
229 const xcmath::mat<float_t, 4, 4>& pv_matrix() const;
230};
231} // namespace xcal::camera
233namespace xcal {
235 switch (type) {
237 return "Perspective";
239 return "Orthogonal";
240 default:
241 return "Unknown";
242 }
243}
244} // namespace xcal
相机系统命名空间
AbsCamera()
默认构造函数
CameraType type() const
const property::Vec< float_t, 3 > & target() const
获取相机目标点(只读)
const property::Vec< float_t, 3 > & up() const
获取相机上方向(只读)
virtual ~AbsCamera()=default
虚析构函数
const property::Vec< float_t, 3 > & position() const
获取相机位置(只读)
virtual bool_t projection_should_update() const =0
检查投影矩阵是否需要更新
AbsCamera * set_up(Args &&... args)
设置相机上方向
AbsCamera * set_target(Args &&... args)
设置相机目标点
AbsCamera * set_position(Args &&... args)
设置相机位置
AbsCamera * set_background_color(Args &&... args)
设置背景颜色
property::Vec< float_t, 3 > & position()
获取相机位置(可修改)
property::Color & background_color()
获取背景颜色(可修改)
property::Vec< float_t, 3 > & up()
获取相机上方向(可修改)
virtual const xcmath::mat< float_t, 4, 4 > & projection_matrix() const =0
获取投影矩阵
property::Vec< float_t, 3 > & target()
获取相机目标点(可修改)
const property::Color & background_color() const
获取背景颜色(只读)
颜色属性类
Definition color.hpp:16
Matrix class template
Definition mat.hpp:27
static constexpr mat< _Tp, _rows, _cols > eye()
Create an identity matrix
Definition mat.hpp:168
Vector class template
Definition vec.hpp:206
帧处理类
PerspectiveCamera 测试套件
@ Orthogonal
正交相机
@ Perspective
透视相机
bool bool_t
Definition public.h:28
XCAL_API const char * to_string(xcal::camera::CameraType type)
float float_t
Definition public.h:27
#define XCAL_API
Definition public.h:69