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