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 "matrix.hpp"
8#include "../utility/module.hpp"
9
10namespace hi { inline namespace v1 {
11namespace geo {
12
17public:
18 perspective() = delete;
19 constexpr perspective(perspective const&) noexcept = default;
20 constexpr perspective(perspective&&) noexcept = default;
21 constexpr perspective& operator=(perspective const&) noexcept = default;
22 constexpr perspective& operator=(perspective&&) noexcept = default;
23
32 perspective(float fov_y, float aspect_ratio, float znear, float zfar) noexcept :
33 _tan_half_fov_y(std::tan(fov_y * 0.5f)), _aspect_ratio(aspect_ratio), _znear(znear), _zfar(zfar)
34 {
37 }
38
47 perspective(float fov_y, extent2 view_port, float znear, float zfar) noexcept :
48 perspective(fov_y, view_port.width() / view_port.height(), znear, zfar)
49 {
50 }
51
52 [[nodiscard]] constexpr operator matrix<3>() noexcept
53 {
54 hilet a = _aspect_ratio;
55 hilet t = _tan_half_fov_y;
56 hilet f = _zfar;
57 hilet n = _znear;
58
59 // clang-format off
60 return {
61 1.0f / (a * t), 0.0f , 0.0f , 0.0f,
62 0.0f , 1.0f / t, 0.0f , 0.0f,
63 0.0f , 0.0f , f / (n - f), -(f * n) / (f - n),
64 0.0f , 0.0f , -1.0f , 0.0f
65 };
66 // clang-format on
67 }
68
69private:
70 float _tan_half_fov_y;
71 float _aspect_ratio;
72 float _znear;
73 float _zfar;
74};
75
76} // namespace geo
77
78using perspective3 = geo::perspective;
79
80}} // namespace hi::v1
Defines geo::matrix, matrix2 and matrix3.
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:238
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
A 2D or 3D homogenius matrix for transforming homogenious vectors and points.
Definition matrix.hpp:33
Perspective transform.
Definition perspective.hpp:16
perspective(float fov_y, extent2 view_port, float znear, float zfar) noexcept
Create a right-handed perspective transform.
Definition perspective.hpp:47
perspective(float fov_y, float aspect_ratio, float znear, float zfar) noexcept
Create a right-handed perspective transform.
Definition perspective.hpp:32
T tan(T... args)