HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
rotate3.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 "vector3.hpp"
8#include "../macros.hpp"
9#include <cmath>
10#include <exception>
11#include <compare>
12
13hi_export_module(hikogui.geometry : rotate3);
14
15hi_export namespace hi { inline namespace v1 {
16
17class rotate3 {
18public:
19 using array_type = simd<float, 4>;
20 using value_type = array_type::value_type;
21
22 constexpr rotate3(rotate3 const&) noexcept = default;
23 constexpr rotate3(rotate3&&) noexcept = default;
24 constexpr rotate3& operator=(rotate3 const&) noexcept = default;
25 constexpr rotate3& operator=(rotate3&&) noexcept = default;
26 constexpr rotate3() noexcept : _v(0.0f, 0.0f, 1.0f, 0.0f) {}
27
28 [[nodiscard]] rotate3(float angle, vector3 axis) noexcept : _v()
29 {
30 hi_axiom(axis.holds_invariant());
31 hi_axiom(std::abs(hypot(axis) - 1.0f) < 0.0001f);
32
33 auto const half_angle = angle * 0.5f;
34 auto const C = std::cos(half_angle);
35 auto const S = std::sin(half_angle);
36
37 _v = static_cast<f32x4>(axis) * array_type::broadcast(S);
38 _v.w() = C;
39 }
40
41 [[nodiscard]] constexpr explicit operator array_type() const noexcept
42 {
43 return _v;
44 }
45
46
47
48
49
50 //std::pair<float, vector3> angle_and_axis() const noexcept
51 //{
52 // auto const rcp_length = rcp_hypot<0b0111>(_v);
53 // auto const length = 1.0f / rcp_length;
54 //
55 // return {2.0f * std::atan2(length), vector3{_v.xyz0() * rcp_length}};
56 //}
57
58private:
62 array_type _v;
63};
64
65}} // namespace hi::v1
axis
An enumeration of the 3 axis for 3D geometry.
Definition axis.hpp:24
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Definition simd_intf.hpp:18
Definition rotate3.hpp:17
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector3.hpp:26
T cos(T... args)
T sin(T... args)