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
9namespace hi { inline namespace v1 {
10
11class rotate3 {
12public:
13 using array_type = simd<float, 4>;
14 using value_type = array_type::value_type;
15
16 constexpr rotate3(rotate3 const&) noexcept = default;
17 constexpr rotate3(rotate3&&) noexcept = default;
18 constexpr rotate3& operator=(rotate3 const&) noexcept = default;
19 constexpr rotate3& operator=(rotate3&&) noexcept = default;
20 constexpr rotate3() noexcept : _v(0.0f, 0.0f, 1.0f, 0.0f) {}
21
22 [[nodiscard]] rotate3(float angle, vector3 axis) noexcept : _v()
23 {
24 hi_axiom(axis.holds_invariant());
25 hi_axiom(std::abs(hypot(axis) - 1.0f) < 0.0001f);
26
27 hilet half_angle = angle * 0.5f;
28 hilet C = std::cos(half_angle);
29 hilet S = std::sin(half_angle);
30
31 _v = static_cast<f32x4>(axis) * S;
32 _v.w() = C;
33 }
34
35 [[nodiscard]] constexpr explicit operator array_type() const noexcept
36 {
37 return _v;
38 }
39
40
41
42
43
44 //std::pair<float, vector3> angle_and_axis() const noexcept
45 //{
46 // hilet rcp_length = rcp_hypot<0b0111>(_v);
47 // hilet length = 1.0f / rcp_length;
48 //
49 // return {2.0f * std::atan2(length), vector3{_v.xyz0() * rcp_length}};
50 //}
51
52private:
56 array_type _v;
57};
58
59}} // namespace hi::v1
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
axis
An enumeration of the 3 axis for 3D geometry.
Definition axis.hpp:18
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
Definition rotate3.hpp:11
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector3.hpp:19
T cos(T... args)
T sin(T... args)