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/module.hpp"
9
10namespace hi { inline namespace v1 {
11
16public:
17 perspective() = delete;
18 constexpr perspective(perspective const&) noexcept = default;
19 constexpr perspective(perspective&&) noexcept = default;
20 constexpr perspective& operator=(perspective const&) noexcept = default;
21 constexpr perspective& operator=(perspective&&) noexcept = default;
22
31 perspective(float fov_y, float aspect_ratio, float znear, float zfar) noexcept :
32 _tan_half_fov_y(std::tan(fov_y * 0.5f)), _aspect_ratio(aspect_ratio), _znear(znear), _zfar(zfar)
33 {
36 }
37
46 perspective(float fov_y, extent2 view_port, float znear, float zfar) noexcept :
47 perspective(fov_y, view_port.width() / view_port.height(), znear, zfar)
48 {
49 }
50
51 [[nodiscard]] constexpr operator matrix3() noexcept
52 {
53 hilet a = _aspect_ratio;
54 hilet t = _tan_half_fov_y;
55 hilet f = _zfar;
56 hilet n = _znear;
57
58 // clang-format off
59 return {
60 1.0f / (a * t), 0.0f , 0.0f , 0.0f,
61 0.0f , 1.0f / t, 0.0f , 0.0f,
62 0.0f , 0.0f , f / (n - f), -(f * n) / (f - n),
63 0.0f , 0.0f , -1.0f , 0.0f
64 };
65 // clang-format on
66 }
67
68private:
69 float _tan_half_fov_y;
70 float _aspect_ratio;
71 float _znear;
72 float _zfar;
73};
74
75}} // namespace hi::v1
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
#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 high-level geometric extent.
Definition extent2.hpp:26
A 2D or 3D homogenius matrix for transforming homogenious vectors and points.
Definition matrix3.hpp:29
Perspective transform.
Definition perspective.hpp:15
perspective(float fov_y, float aspect_ratio, float znear, float zfar) noexcept
Create a right-handed perspective transform.
Definition perspective.hpp:31
perspective(float fov_y, extent2 view_port, float znear, float zfar) noexcept
Create a right-handed perspective transform.
Definition perspective.hpp:46
T tan(T... args)