UdonLibrary
1.0.0
機械システム研究部 C++ ライブラリ
Toggle main menu visibility
読み取り中…
検索中…
一致する文字列を見つけられません
Euler.hpp
[詳解]
1
//
2
// オイラー角 前方定義
3
//
4
// Copyright (c) 2022 udonrobo
5
//
6
7
8
#pragma once
9
10
#include <
Udon/Algorithm/Math.hpp
>
// Udon::Normalized
11
#include <
Udon/Traits/EnumerableMacro.hpp
>
12
#include <
Udon/Serializer/Serializer.hpp
>
13
14
namespace
Udon
15
{
16
17
struct
Quaternion
;
18
19
21
struct
EulerDirection
22
{
23
bool
roll
;
24
bool
pitch
;
25
bool
yaw
;
26
};
27
28
30
struct
Euler
31
{
32
34
using
ValueType
= double;
35
37
ValueType
roll
;
38
40
ValueType
pitch
;
41
43
ValueType
yaw
;
44
46
constexpr
Euler
() noexcept
47
:
roll
()
48
,
pitch
()
49
,
yaw
()
50
{
51
}
52
57
constexpr
Euler
(
ValueType
roll
,
ValueType
pitch
,
ValueType
yaw
) noexcept
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
116
Euler
normalized
(
ValueType
min,
ValueType
max)
const
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
157
UDON_ENUMERABLE
(
roll
,
pitch
,
yaw
);
158
};
159
160
}
// namespace Udon
EnumerableMacro.hpp
Math.hpp
Serializer.hpp
F
#define F(x)
Definition
Show.hpp:17
Udon
Definition
Bit.hpp:12
Udon::Normalized
double Normalized(double value, double min, double max)
値を正規化する
Definition
Math.hpp:166
Udon::EulerDirection
オイラー角の回転方向
Definition
Euler.hpp:22
Udon::EulerDirection::yaw
bool yaw
Definition
Euler.hpp:25
Udon::EulerDirection::pitch
bool pitch
Definition
Euler.hpp:24
Udon::EulerDirection::roll
bool roll
Definition
Euler.hpp:23
Udon::Euler::yaw
ValueType yaw
ヨー角
Definition
Euler.hpp:43
Udon::Euler::operator+
constexpr Euler operator+(const Euler &rhs) const noexcept
Definition
Euler.hpp:70
Udon::Euler::operator=
Euler & operator=(const Euler &)=default
デフォルトコピー代入演算子
Udon::Euler::roll
ValueType roll
ロール角
Definition
Euler.hpp:37
Udon::Euler::Euler
Euler(const Euler &)=default
デフォルトコピーコンストラクタ
Udon::Euler::operator/=
Euler & operator/=(const Euler &rhs) noexcept
Definition
Euler.hpp:82
Udon::Euler::operator/=
Euler & operator/=(ValueType rhs) noexcept
Definition
Euler.hpp:86
Udon::Euler::operator*
constexpr Euler operator*(const Euler &rhs) const noexcept
Definition
Euler.hpp:72
Udon::Euler::operator*=
Euler & operator*=(ValueType rhs) noexcept
Definition
Euler.hpp:85
Udon::Euler::operator+=
Euler & operator+=(const Euler &rhs) noexcept
Definition
Euler.hpp:79
Udon::Euler::operator/
constexpr Euler operator/(const Euler &rhs) const noexcept
Definition
Euler.hpp:73
Udon::Euler::operator-=
Euler & operator-=(ValueType rhs) noexcept
Definition
Euler.hpp:84
Udon::Euler::operator/
constexpr Euler operator/(ValueType rhs) const noexcept
Definition
Euler.hpp:77
Udon::Euler::operator*
constexpr Euler operator*(ValueType rhs) const noexcept
Definition
Euler.hpp:76
Udon::Euler::operator*=
Euler & operator*=(const Euler &rhs) noexcept
Definition
Euler.hpp:81
Udon::Euler::directionRevision
constexpr Euler directionRevision(const EulerDirection &direction) const noexcept
回転方向を修正したオイラー角を取得する
Definition
Euler.hpp:128
Udon::Euler::clear
void clear() noexcept
値クリア
Definition
Euler.hpp:142
Udon::Euler::operator-=
Euler & operator-=(const Euler &rhs) noexcept
Definition
Euler.hpp:80
Udon::Euler::operator-
constexpr Euler operator-(ValueType rhs) const noexcept
Definition
Euler.hpp:75
Udon::Euler::toQuaternion
Quaternion toQuaternion() const noexcept
クォータニオンに変換する
Definition
Euler.hpp:12
Udon::Euler::isZero
constexpr bool isZero() const noexcept
要素がゼロであるか返す
Definition
Euler.hpp:107
Udon::Euler::operator+=
Euler & operator+=(ValueType rhs) noexcept
Definition
Euler.hpp:83
Udon::Euler::Euler
constexpr Euler() noexcept
デフォルトコンストラクタ
Definition
Euler.hpp:46
Udon::Euler::operator+
constexpr Euler operator+(ValueType rhs) const noexcept
Definition
Euler.hpp:74
Udon::Euler::operator==
constexpr bool operator==(const Euler &rhs) const noexcept
Definition
Euler.hpp:88
Udon::Euler::Euler
constexpr Euler(ValueType roll, ValueType pitch, ValueType yaw) noexcept
コンストラクタ
Definition
Euler.hpp:57
Udon::Euler::normalized
Euler normalized(ValueType min, ValueType max) const
正規化されたオイラー角を取得する
Definition
Euler.hpp:116
Udon::Euler::operator-
constexpr Euler operator-(const Euler &rhs) const noexcept
Definition
Euler.hpp:71
Udon::Euler::UDON_ENUMERABLE
UDON_ENUMERABLE(roll, pitch, yaw)
Udon::Euler::operator!=
constexpr bool operator!=(const Euler &rhs) const noexcept
Definition
Euler.hpp:94
Udon::Euler::ValueType
double ValueType
要素の型
Definition
Euler.hpp:34
Udon::Euler::pitch
ValueType pitch
ピッチ角
Definition
Euler.hpp:40
Udon::Quaternion
クオータニオン
Definition
Quaternion.hpp:30