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