Tatooine
perspective_camera.h
Go to the documentation of this file.
1#ifndef TATOOINE_RENDERING_PERSPECTIVE_CAMERA_H
2#define TATOOINE_RENDERING_PERSPECTIVE_CAMERA_H
3//==============================================================================
5//==============================================================================
6namespace tatooine::rendering {
7//==============================================================================
14template <floating_point Real>
16 public:
17 using real_type = Real;
21 using parent_type::eye;
23 //using parent_type::setup;
24 using typename parent_type::mat4;
25 using typename parent_type::vec3;
26 //----------------------------------------------------------------------------
27 // constructors / destructor
28 //----------------------------------------------------------------------------
31 constexpr perspective_camera(vec3 const& eye, vec3 const& lookat,
32 vec3 const& up, Real const fov, Real const near,
33 Real const far, std::size_t const res_x,
34 std::size_t const res_y)
36 eye, lookat, up, Vec4<std::size_t>{0, 0, res_x, res_y},
38 fov, static_cast<Real>(res_x) / static_cast<Real>(res_y), near,
39 far)} {
40 //setup();
41 }
42 //----------------------------------------------------------------------------
45 constexpr perspective_camera(vec3 const& eye, vec3 const& lookat, Real fov,
46 Real const near, Real const far,
47 std::size_t const res_x, std::size_t const res_y)
48 : perspective_camera(eye, lookat, vec3{0, 1, 0}, fov, near, far, res_x,
49 res_y) {}
50 //----------------------------------------------------------------------------
53 constexpr perspective_camera(vec3 const& eye, vec3 const& lookat, Real fov,
54 std::size_t const res_x, std::size_t const res_y)
55 : perspective_camera(eye, lookat, vec3{0, 1, 0}, fov, 0.001, 1000, res_x,
56 res_y) {}
57 //----------------------------------------------------------------------------
60 template <typename EyeReal, typename LookatReal, typename UpReal,
61 typename FovReal>
62 constexpr perspective_camera(vec<EyeReal, 3> const& eye,
63 vec<LookatReal, 3> const& lookat,
64 vec<UpReal, 3> const& up, FovReal const fov,
65 std::size_t const res_x, std::size_t const res_y)
66 : perspective_camera(eye, lookat, up, fov, 0.001, 1000, res_x, res_y) {}
67 //----------------------------------------------------------------------------
69 perspective_camera(perspective_camera &&) noexcept = default;
70 //----------------------------------------------------------------------------
71 auto operator=(perspective_camera const&)
72 -> perspective_camera& = default;
73 auto operator=(perspective_camera&&) noexcept
74 -> perspective_camera& = default;
75 //----------------------------------------------------------------------------
76 ~perspective_camera() = default;
77 //============================================================================
78 auto constexpr set_projection_matrix(Real const fov, Real const near,
79 Real const far) -> void {
80 set_projection_matrix(
81 perspective_matrix(fov, this->aspect_ratio(), near, far));
82 }
83};
84//==============================================================================
85template <typename EyeReal, typename LookatReal, typename UpReal,
86 typename FovReal, typename NearReal, typename FarReal>
88 vec<UpReal, 3> const&, FovReal const, NearReal const,
89 FarReal const, std::size_t const, std::size_t const)
92//------------------------------------------------------------------------------
93template <typename EyeReal, typename LookatReal, typename FovReal,
94 typename NearReal, typename FarReal>
96 FovReal const, NearReal const, FarReal const,
97 std::size_t const, std::size_t const)
100//------------------------------------------------------------------------------
101template <typename EyeReal, typename LookatReal, typename FovReal>
103 FovReal const, std::size_t const, std::size_t const)
105//------------------------------------------------------------------------------
106template <typename EyeReal, typename LookatReal, typename UpReal,
107 typename FovReal>
109 vec<UpReal, 3> const&, FovReal const, std::size_t const,
110 std::size_t const)
113//==============================================================================
114} // namespace tatooine::rendering
115//==============================================================================
116#endif
Definition: camera.h:12
auto constexpr perspective_matrix(Real const fov_angles, Real const aspect_ratio, Real const near, Real const far)
Definition: matrices.h:319
typename common_type_impl< Ts... >::type common_type
Definition: common_type.h:23
Interface for camera implementations.
Definition: camera.h:19
auto constexpr eye() const -> auto
Definition: camera.h:78
auto constexpr aspect_ratio() const
Definition: camera.h:74
Mat4< Real > mat4
Definition: camera.h:28
auto set_projection_matrix(mat4 const &projection_matrix) -> void
Definition: camera.h:280
Vec3< Real > vec3
Definition: camera.h:26
Perspective cameras are able to cast rays from one point called 'eye' through an image plane.
Definition: perspective_camera.h:15
auto constexpr eye() const -> auto
Definition: camera.h:78
constexpr perspective_camera(vec3 const &eye, vec3 const &lookat, Real fov, Real const near, Real const far, std::size_t const res_x, std::size_t const res_y)
Definition: perspective_camera.h:45
perspective_camera(perspective_camera const &)=default
constexpr perspective_camera(vec3 const &eye, vec3 const &lookat, vec3 const &up, Real const fov, Real const near, Real const far, std::size_t const res_x, std::size_t const res_y)
Definition: perspective_camera.h:31
constexpr perspective_camera(vec< EyeReal, 3 > const &eye, vec< LookatReal, 3 > const &lookat, vec< UpReal, 3 > const &up, FovReal const fov, std::size_t const res_x, std::size_t const res_y)
Definition: perspective_camera.h:62
Real real_type
Definition: perspective_camera.h:17
perspective_camera(perspective_camera &&) noexcept=default
constexpr perspective_camera(vec3 const &eye, vec3 const &lookat, Real fov, std::size_t const res_x, std::size_t const res_y)
Definition: perspective_camera.h:53
Definition: vec.h:12