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
14namespace hi { inline namespace v1 {
15
19class lookat {
20public:
21 lookat() = delete;
22 constexpr lookat(lookat const&) noexcept = default;
23 constexpr lookat(lookat&&) noexcept = default;
24 constexpr lookat& operator=(lookat const&) noexcept = default;
25 constexpr lookat& operator=(lookat&&) noexcept = default;
26
27 constexpr lookat(point3 camera_location, point3 lookat_location, vector3 up = vector3{0.0f, 1.0f, 0.0f}) :
28 _camera_location(camera_location), _lookat_location(lookat_location), _up(up)
29 {
30 }
31
32 [[nodiscard]] constexpr operator matrix3() noexcept
33 {
34 hilet f = normalize(_lookat_location - _camera_location);
35 hilet s = normalize(cross(f, _up));
36 hilet u = cross(s, f);
37
38 hilet eye = vector3{static_cast<f32x4>(_camera_location).xyz0()};
39
40 // clang-format off
41 // Matrix constructor is in row-major for nice display.
42 return matrix3{
43 s.x(), u.x(), -f.x(), -dot(s, eye),
44 s.y(), u.y(), -f.y(), -dot(u, eye),
45 s.z(), u.z(), -f.z(), -dot(f, eye),
46 0.0f , 0.0f , 0.0f , 1.0f
47 };
48 // clang-format on
49 }
50
51private:
52 point3 _camera_location;
53 point3 _lookat_location;
54 vector3 _up;
55};
56
57}} // namespace hi::v1
#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
Perspective transform.
Definition lookat.hpp:19
A 2D or 3D homogenius matrix for transforming homogenious vectors and points.
Definition matrix3.hpp:29
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector3.hpp:19