HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
lookat.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 "point.hpp"
9
10namespace hi { inline namespace v1 {
11namespace geo {
12
16class lookat {
17public:
18 lookat() = delete;
19 constexpr lookat(lookat const&) noexcept = default;
20 constexpr lookat(lookat&&) noexcept = default;
21 constexpr lookat& operator=(lookat const&) noexcept = default;
22 constexpr lookat& operator=(lookat&&) noexcept = default;
23
24 constexpr lookat(point3 camera_location, point3 lookat_location, vector3 up = vector3{0.0f, 1.0f, 0.0f}) :
25 _camera_location(camera_location), _lookat_location(lookat_location), _up(up)
26 {
27 }
28
29 [[nodiscard]] constexpr operator matrix<3>() noexcept
30 {
31 hilet f = normalize(_lookat_location - _camera_location);
32 hilet s = normalize(cross(f, _up));
33 hilet u = cross(s, f);
34
35 hilet eye = vector3{static_cast<f32x4>(_camera_location).xyz0()};
36
37 // clang-format off
38 // Matrix constructor is in row-major for nice display.
39 return matrix3{
40 s.x(), u.x(), -f.x(), -dot(s, eye),
41 s.y(), u.y(), -f.y(), -dot(u, eye),
42 s.z(), u.z(), -f.z(), -dot(f, eye),
43 0.0f , 0.0f , 0.0f , 1.0f
44 };
45 // clang-format on
46 }
47
48private:
49 point3 _camera_location;
50 point3 _lookat_location;
51 vector3 _up;
52};
53
54} // namespace geo
55
56using lookat3 = geo::lookat;
57
58}} // namespace hi::v1
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:15
The HikoGUI namespace.
Definition ascii.hpp:19
Perspective transform.
Definition lookat.hpp:16