HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
perspective.hpp
1// Copyright Take Vos 2021-2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "matrix3.hpp"
8#include "../utility/utility.hpp"
9#include "../macros.hpp"
10
11
12
13namespace hi { inline namespace v1 {
14
19public:
20 perspective() = delete;
21 constexpr perspective(perspective const&) noexcept = default;
22 constexpr perspective(perspective&&) noexcept = default;
23 constexpr perspective& operator=(perspective const&) noexcept = default;
24 constexpr perspective& operator=(perspective&&) noexcept = default;
25
34 perspective(float fov_y, float aspect_ratio, float znear, float zfar) noexcept :
35 _tan_half_fov_y(std::tan(fov_y * 0.5f)), _aspect_ratio(aspect_ratio), _znear(znear), _zfar(zfar)
36 {
39 }
40
50 perspective(fov_y, view_port.width() / view_port.height(), znear, zfar)
51 {
52 }
53
54 [[nodiscard]] constexpr operator matrix3() noexcept
55 {
56 hilet a = _aspect_ratio;
57 hilet t = _tan_half_fov_y;
58 hilet f = _zfar;
59 hilet n = _znear;
60
61 // clang-format off
62 return {
63 1.0f / (a * t), 0.0f , 0.0f , 0.0f,
64 0.0f , 1.0f / t, 0.0f , 0.0f,
65 0.0f , 0.0f , f / (n - f), -(f * n) / (f - n),
66 0.0f , 0.0f , -1.0f , 0.0f
67 };
68 // clang-format on
69 }
70
71private:
72 float _tan_half_fov_y;
73 float _aspect_ratio;
74 float _znear;
75 float _zfar;
76};
77
78}} // namespace hi::v1
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
A high-level geometric extent.
Definition extent2.hpp:29
A 2D or 3D homogenius matrix for transforming homogenious vectors and points.
Definition matrix3.hpp:30
Perspective transform.
Definition perspective.hpp:18
perspective(float fov_y, float aspect_ratio, float znear, float zfar) noexcept
Create a right-handed perspective transform.
Definition perspective.hpp:34
perspective(float fov_y, extent2 view_port, float znear, float zfar) noexcept
Create a right-handed perspective transform.
Definition perspective.hpp:49
T tan(T... args)