UdonLibrary 1.0.0
機械システム研究部 C++ ライブラリ
読み取り中…
検索中…
一致する文字列を見つけられません
Euler.hpp
[詳解]
1//
2// オイラー角 前方定義
3//
4// Copyright (c) 2022-2024 udonrobo
5//
6
7
8#pragma once
9
10#include <Udon/Algorithm/Math.hpp> // Udon::Normalized
13
14namespace Udon
15{
16
17 struct Quaternion;
18
19
22 {
23 bool roll;
24 bool pitch;
25 bool yaw;
26 };
27
28
30 struct Euler
31 {
32
34 using ValueType = double;
35
38
41
44
46 constexpr Euler() noexcept
47 : roll()
48 , pitch()
49 , yaw()
50 {
51 }
52
58 : roll(roll)
59 , pitch(pitch)
60 , yaw(yaw)
61 {
62 }
63
65 Euler(const Euler&) = default;
66
68 Euler& operator=(const Euler&) = default;
69
70 constexpr Euler operator+(const Euler& rhs) const noexcept { return { roll + rhs.roll, pitch + rhs.pitch, yaw + rhs.yaw }; }
71 constexpr Euler operator-(const Euler& rhs) const noexcept { return { roll - rhs.roll, pitch - rhs.pitch, yaw - rhs.yaw }; }
72 constexpr Euler operator*(const Euler& rhs) const noexcept { return { roll * rhs.roll, pitch * rhs.pitch, yaw * rhs.yaw }; }
73 constexpr Euler operator/(const Euler& rhs) const noexcept { return { roll / rhs.roll, pitch / rhs.pitch, yaw / rhs.yaw }; }
74 constexpr Euler operator+(ValueType rhs) const noexcept { return { roll + rhs, pitch + rhs, yaw + rhs }; }
75 constexpr Euler operator-(ValueType rhs) const noexcept { return { roll - rhs, pitch - rhs, yaw - rhs }; }
76 constexpr Euler operator*(ValueType rhs) const noexcept { return { roll * rhs, pitch * rhs, yaw * rhs }; }
77 constexpr Euler operator/(ValueType rhs) const noexcept { return { roll / rhs, pitch / rhs, yaw / rhs }; }
78
79 Euler& operator+=(const Euler& rhs) noexcept { return *this = *this + rhs; };
80 Euler& operator-=(const Euler& rhs) noexcept { return *this = *this - rhs; };
81 Euler& operator*=(const Euler& rhs) noexcept { return *this = *this * rhs; };
82 Euler& operator/=(const Euler& rhs) noexcept { return *this = *this / rhs; };
83 Euler& operator+=(ValueType rhs) noexcept { return *this = *this + rhs; };
84 Euler& operator-=(ValueType rhs) noexcept { return *this = *this - rhs; };
85 Euler& operator*=(ValueType rhs) noexcept { return *this = *this * rhs; };
86 Euler& operator/=(ValueType rhs) noexcept { return *this = *this / rhs; };
87
88 constexpr bool operator==(const Euler& rhs) const noexcept
89 {
90 return roll == rhs.roll &&
91 pitch == rhs.pitch &&
92 yaw == rhs.yaw;
93 };
94 constexpr bool operator!=(const Euler& rhs) const noexcept
95 {
96 return !(*this == rhs);
97 };
98
101 explicit constexpr operator bool() const noexcept
102 {
103 return roll || pitch || yaw;
104 }
105
107 constexpr bool isZero() const noexcept
108 {
109 return !operator bool();
110 }
111
117 {
118 return {
119 Udon::Normalized(roll, min, max),
120 Udon::Normalized(pitch, min, max),
121 Udon::Normalized(yaw, min, max),
122 };
123 }
124
128 constexpr Euler directionRevision(const EulerDirection& direction) const noexcept
129 {
130 return {
131 roll * (direction.roll ? 1 : -1),
132 pitch * (direction.pitch ? 1 : -1),
133 yaw * (direction.yaw ? 1 : -1),
134 };
135 }
136
139 Quaternion toQuaternion() const noexcept;
140
142 void clear() noexcept
143 {
144 *this = {};
145 }
146
147#ifdef ARDUINO
149 void show() const noexcept
150 {
151 Serial.print(F("r: ")), Serial.print(roll), Serial.print('\t');
152 Serial.print(F("p: ")), Serial.print(pitch), Serial.print('\t');
153 Serial.print(F("y: ")), Serial.print(yaw), Serial.print('\t');
154 }
155#endif
156
158 };
159
160} // namespace Udon
#define F(x)
Definition Show.hpp:17
Definition Bit.hpp:12
double Normalized(double value, double min, double max)
値を正規化する
Definition Math.hpp:154
オイラー角の回転方向
Definition Euler.hpp:22
bool yaw
Definition Euler.hpp:25
bool pitch
Definition Euler.hpp:24
bool roll
Definition Euler.hpp:23
オイラー角
Definition Euler.hpp:31
ValueType yaw
ヨー角
Definition Euler.hpp:43
constexpr Euler operator+(const Euler &rhs) const noexcept
Definition Euler.hpp:70
Euler & operator=(const Euler &)=default
デフォルトコピー代入演算子
ValueType roll
ロール角
Definition Euler.hpp:37
Euler(const Euler &)=default
デフォルトコピーコンストラクタ
Euler & operator/=(const Euler &rhs) noexcept
Definition Euler.hpp:82
Euler & operator/=(ValueType rhs) noexcept
Definition Euler.hpp:86
constexpr Euler operator*(const Euler &rhs) const noexcept
Definition Euler.hpp:72
Euler & operator*=(ValueType rhs) noexcept
Definition Euler.hpp:85
Euler & operator+=(const Euler &rhs) noexcept
Definition Euler.hpp:79
constexpr Euler operator/(const Euler &rhs) const noexcept
Definition Euler.hpp:73
Euler & operator-=(ValueType rhs) noexcept
Definition Euler.hpp:84
constexpr Euler operator/(ValueType rhs) const noexcept
Definition Euler.hpp:77
constexpr Euler operator*(ValueType rhs) const noexcept
Definition Euler.hpp:76
Euler & operator*=(const Euler &rhs) noexcept
Definition Euler.hpp:81
constexpr Euler directionRevision(const EulerDirection &direction) const noexcept
回転方向を修正したオイラー角を取得する
Definition Euler.hpp:128
void clear() noexcept
値クリア
Definition Euler.hpp:142
Euler & operator-=(const Euler &rhs) noexcept
Definition Euler.hpp:80
constexpr Euler operator-(ValueType rhs) const noexcept
Definition Euler.hpp:75
Quaternion toQuaternion() const noexcept
クォータニオンに変換する
Definition Euler.hpp:12
constexpr bool isZero() const noexcept
要素がゼロであるか返す
Definition Euler.hpp:107
Euler & operator+=(ValueType rhs) noexcept
Definition Euler.hpp:83
constexpr Euler() noexcept
デフォルトコンストラクタ
Definition Euler.hpp:46
constexpr Euler operator+(ValueType rhs) const noexcept
Definition Euler.hpp:74
constexpr bool operator==(const Euler &rhs) const noexcept
Definition Euler.hpp:88
constexpr Euler(ValueType roll, ValueType pitch, ValueType yaw) noexcept
コンストラクタ
Definition Euler.hpp:57
Euler normalized(ValueType min, ValueType max) const
正規化されたオイラー角を取得する
Definition Euler.hpp:116
constexpr Euler operator-(const Euler &rhs) const noexcept
Definition Euler.hpp:71
UDON_ENUMERABLE(roll, pitch, yaw)
constexpr bool operator!=(const Euler &rhs) const noexcept
Definition Euler.hpp:94
double ValueType
要素の型
Definition Euler.hpp:34
ValueType pitch
ピッチ角
Definition Euler.hpp:40
クオータニオン
Definition Quaternion.hpp:30