xcal
基于 C++23 的现代图形渲染引擎
载入中...
搜索中...
未找到
perspectivecamera.cc
浏览该文件的文档.
2
3void xcal::camera::PerspectiveCamera::update_projection_matrix() const {
4 if (!projection_should_update()) return;
5
6 const float fov_rad = fov_.value() * xcmath::PI / 180.0f;
7 const float tan_half = std::tan(fov_rad * 0.5f);
8 const float n = near_.value();
9 const float f = far_.value();
10 const float a = aspect_.value();
11
12 auto& P = projection_matrix_cache_;
14
15 // 行主序
16 P[0][0] = 1.0f / (a * tan_half);
17 P[1][1] = 1.0f / tan_half;
18 P[2][2] = -(f + n) / (f - n);
19 P[2][3] = -2.0f * f * n / (f - n);
20 P[3][2] = -1.0f;
21 // 其余元素保持 0
22
23 fov_.reset_changed();
24 aspect_.reset_changed();
25 near_.reset_changed();
26 far_.reset_changed();
28}
30 return fov_.is_changed() || aspect_.is_changed() || near_.is_changed() ||
31 far_.is_changed();
32};
35 update_projection_matrix();
36 return projection_matrix_cache_;
37}
void projection_has_changed() const
标记投影矩阵已改变
Definition abs_camera.cc:63
bool_t projection_should_update() const override
检查投影矩阵是否需要更新
const xcmath::mat< float_t, 4, 4 > & projection_matrix() const override
获取投影矩阵
const data_t & value() const
Definition scalar.hpp:19
Matrix class template
Definition mat.hpp:27
bool bool_t
Definition public.h:28
constexpr long double PI
Pi constant
透视相机类