HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
lookat.hpp
Go to the documentation of this file.
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
9#pragma once
10
11#include "matrix3.hpp"
12#include "point3.hpp"
13#include "../macros.hpp"
14#include <exception>
15#include <compare>
16
17hi_export_module(hikogui.geometry : lookat);
18
19hi_export namespace hi { inline namespace v1 {
20
24class lookat {
25public:
26 lookat() = delete;
27 constexpr lookat(lookat const&) noexcept = default;
28 constexpr lookat(lookat&&) noexcept = default;
29 constexpr lookat& operator=(lookat const&) noexcept = default;
30 constexpr lookat& operator=(lookat&&) noexcept = default;
31
32 constexpr lookat(point3 camera_location, point3 lookat_location, vector3 up = vector3{0.0f, 1.0f, 0.0f}) :
33 _camera_location(camera_location), _lookat_location(lookat_location), _up(up)
34 {
35 }
36
37 [[nodiscard]] constexpr operator matrix3() noexcept
38 {
39 auto const f = normalize(_lookat_location - _camera_location);
40 auto const s = normalize(cross(f, _up));
41 auto const u = cross(s, f);
42
43 auto const eye = vector3{static_cast<f32x4>(_camera_location).xyz0()};
44
45 // clang-format off
46 // Matrix constructor is in row-major for nice display.
47 return matrix3{
48 s.x(), u.x(), -f.x(), -dot(s, eye),
49 s.y(), u.y(), -f.y(), -dot(u, eye),
50 s.z(), u.z(), -f.z(), -dot(f, eye),
51 0.0f , 0.0f , 0.0f , 1.0f
52 };
53 // clang-format on
54 }
55
56private:
57 point3 _camera_location;
58 point3 _lookat_location;
59 vector3 _up;
60};
61
62}} // namespace hi::v1
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Perspective transform.
Definition lookat.hpp:24
A 2D or 3D homogenius matrix for transforming homogenious vectors and points.
Definition matrix3.hpp:36
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector3.hpp:26