xcal
基于 C++23 的现代图形渲染引擎
载入中...
搜索中...
未找到
abs_camera.cc
浏览该文件的文档.
2#undef OUT // undefine OUT macro to avoid conflict with xcal::OUT
3#define ROLE Camera
4#define LABEL AbsCamera
6void xcal::camera::AbsCamera::update_view_matrix() const {
7 if (!view_should_update()) return;
8
9 using vec3 = xcmath::vec<float_t, 3>;
10 const vec3 eye = position_.value();
11 const vec3 center = target_.value();
12 const vec3 up = up_.value();
13
14 const vec3 f = (center - eye).normalize();
15 const vec3 r = f.cross(up).normalize();
16 const vec3 u = r.cross(f);
17
18 auto& V = view_matrix_cache_;
20
21 // 行主序 look-at
22 V[0][0] = r.x();
23 V[0][1] = r.y();
24 V[0][2] = r.z();
25 V[0][3] = -r.dot(eye);
26 V[1][0] = u.x();
27 V[1][1] = u.y();
28 V[1][2] = u.z();
29 V[1][3] = -u.dot(eye);
30 V[2][0] = -f.x();
31 V[2][1] = -f.y();
32 V[2][2] = -f.z();
33 V[2][3] = f.dot(eye);
34 V[3][3] = 1.0f;
35
36 position_.reset_changed();
37 target_.reset_changed();
38 up_.reset_changed();
39 view_or_projection_has_changed_ = true;
40}
42 return position_.is_changed() || target_.is_changed() || up_.is_changed();
43};
45 if (projection_should_update() || view_should_update() ||
46 view_or_projection_has_changed_)
47 _D("should_update(): "
48 << (projection_should_update() ? "projection should update" : "")
49 << (view_should_update() ? "view should update" : "")
50 << (view_or_projection_has_changed_
51 ? "view or projection has changed"
52 : ""));
53 return projection_should_update() || view_should_update() ||
54 view_or_projection_has_changed_;
55};
57 if (should_update()) {
58 pv_matrix_cache_ = projection_matrix() ^ view_matrix();
59 view_or_projection_has_changed_ = false;
60 }
61 return pv_matrix_cache_;
62}
64 view_or_projection_has_changed_ = true;
65}
67 update_view_matrix();
68 return view_matrix_cache_;
69}
抽象相机基类
const xcmath::mat< float_t, 4, 4 > & view_matrix() const
获取视图矩阵
Definition abs_camera.cc:66
void projection_has_changed() const
标记投影矩阵已改变
Definition abs_camera.cc:63
bool_t should_update() const
检查相机矩阵是否需要更新
Definition abs_camera.cc:44
property::Vec< float_t, 3 > & up()
获取相机上方向(可修改)
bool_t view_should_update() const
检查视图矩阵是否需要更新
Definition abs_camera.cc:41
const xcmath::mat< float_t, 4, 4 > & pv_matrix() const
获取投影视图矩阵(PV矩阵)
Definition abs_camera.cc:56
data_t & value()
Definition vec.hpp:26
Matrix class template
Definition mat.hpp:27
Vector class template
Definition vec.hpp:206
constexpr _Tp & x()
Get the item at index 0
Definition vec.hpp:454
bool bool_t
Definition public.h:28