@@ -37,28 +37,15 @@ namespace godot {
37
37
38
38
real_t Quaternion::angle_to (const Quaternion &p_to) const {
39
39
real_t d = dot (p_to);
40
- return Math::acos (CLAMP (d * d * 2 - 1 , -1 , 1 ));
40
+ // acos does clamping.
41
+ return Math::acos (d * d * 2 - 1 );
41
42
}
42
43
43
- // get_euler_xyz returns a vector containing the Euler angles in the format
44
- // (ax,ay,az), where ax is the angle of rotation around x axis,
45
- // and similar for other axes.
46
- // This implementation uses XYZ convention (Z is the first rotation).
47
- Vector3 Quaternion::get_euler_xyz () const {
48
- Basis m (*this );
49
- return m.get_euler (EULER_ORDER_XYZ);
50
- }
51
-
52
- // get_euler_yxz returns a vector containing the Euler angles in the format
53
- // (ax,ay,az), where ax is the angle of rotation around x axis,
54
- // and similar for other axes.
55
- // This implementation uses YXZ convention (Z is the first rotation).
56
- Vector3 Quaternion::get_euler_yxz () const {
44
+ Vector3 Quaternion::get_euler (EulerOrder p_order) const {
57
45
#ifdef MATH_CHECKS
58
- ERR_FAIL_COND_V_MSG (!is_normalized (), Vector3 (0 , 0 , 0 ), " The quaternion must be normalized." );
46
+ ERR_FAIL_COND_V_MSG (!is_normalized (), Vector3 (0 , 0 , 0 ), " The quaternion " + operator String () + " must be normalized." );
59
47
#endif
60
- Basis m (*this );
61
- return m.get_euler (EULER_ORDER_YXZ);
48
+ return Basis (*this ).get_euler (p_order);
62
49
}
63
50
64
51
void Quaternion::operator *=(const Quaternion &p_q) {
@@ -103,7 +90,7 @@ bool Quaternion::is_normalized() const {
103
90
104
91
Quaternion Quaternion::inverse () const {
105
92
#ifdef MATH_CHECKS
106
- ERR_FAIL_COND_V_MSG (!is_normalized (), Quaternion (), " The quaternion must be normalized." );
93
+ ERR_FAIL_COND_V_MSG (!is_normalized (), Quaternion (), " The quaternion " + operator String () + " must be normalized." );
107
94
#endif
108
95
return Quaternion (-x, -y, -z, w);
109
96
}
@@ -125,10 +112,10 @@ Quaternion Quaternion::exp() const {
125
112
return Quaternion (src_v, theta);
126
113
}
127
114
128
- Quaternion Quaternion::slerp (const Quaternion &p_to, const real_t & p_weight) const {
115
+ Quaternion Quaternion::slerp (const Quaternion &p_to, real_t p_weight) const {
129
116
#ifdef MATH_CHECKS
130
- ERR_FAIL_COND_V_MSG (!is_normalized (), Quaternion (), " The start quaternion must be normalized." );
131
- ERR_FAIL_COND_V_MSG (!p_to.is_normalized (), Quaternion (), " The end quaternion must be normalized." );
117
+ ERR_FAIL_COND_V_MSG (!is_normalized (), Quaternion (), " The start quaternion " + operator String () + " must be normalized." );
118
+ ERR_FAIL_COND_V_MSG (!p_to.is_normalized (), Quaternion (), " The end quaternion " + p_to. operator String () + " must be normalized." );
132
119
#endif
133
120
Quaternion to1;
134
121
real_t omega, cosom, sinom, scale0, scale1;
@@ -166,10 +153,10 @@ Quaternion Quaternion::slerp(const Quaternion &p_to, const real_t &p_weight) con
166
153
scale0 * w + scale1 * to1.w );
167
154
}
168
155
169
- Quaternion Quaternion::slerpni (const Quaternion &p_to, const real_t & p_weight) const {
156
+ Quaternion Quaternion::slerpni (const Quaternion &p_to, real_t p_weight) const {
170
157
#ifdef MATH_CHECKS
171
- ERR_FAIL_COND_V_MSG (!is_normalized (), Quaternion (), " The start quaternion must be normalized." );
172
- ERR_FAIL_COND_V_MSG (!p_to.is_normalized (), Quaternion (), " The end quaternion must be normalized." );
158
+ ERR_FAIL_COND_V_MSG (!is_normalized (), Quaternion (), " The start quaternion " + operator String () + " must be normalized." );
159
+ ERR_FAIL_COND_V_MSG (!p_to.is_normalized (), Quaternion (), " The end quaternion " + p_to. operator String () + " must be normalized." );
173
160
#endif
174
161
const Quaternion &from = *this ;
175
162
@@ -190,10 +177,10 @@ Quaternion Quaternion::slerpni(const Quaternion &p_to, const real_t &p_weight) c
190
177
invFactor * from.w + newFactor * p_to.w );
191
178
}
192
179
193
- Quaternion Quaternion::spherical_cubic_interpolate (const Quaternion &p_b, const Quaternion &p_pre_a, const Quaternion &p_post_b, const real_t & p_weight) const {
180
+ Quaternion Quaternion::spherical_cubic_interpolate (const Quaternion &p_b, const Quaternion &p_pre_a, const Quaternion &p_post_b, real_t p_weight) const {
194
181
#ifdef MATH_CHECKS
195
- ERR_FAIL_COND_V_MSG (!is_normalized (), Quaternion (), " The start quaternion must be normalized." );
196
- ERR_FAIL_COND_V_MSG (!p_b.is_normalized (), Quaternion (), " The end quaternion must be normalized." );
182
+ ERR_FAIL_COND_V_MSG (!is_normalized (), Quaternion (), " The start quaternion " + operator String () + " must be normalized." );
183
+ ERR_FAIL_COND_V_MSG (!p_b.is_normalized (), Quaternion (), " The end quaternion " + p_b. operator String () + " must be normalized." );
197
184
#endif
198
185
Quaternion from_q = *this ;
199
186
Quaternion pre_q = p_pre_a;
@@ -236,15 +223,15 @@ Quaternion Quaternion::spherical_cubic_interpolate(const Quaternion &p_b, const
236
223
ln.z = Math::cubic_interpolate (ln_from.z , ln_to.z , ln_pre.z , ln_post.z , p_weight);
237
224
Quaternion q2 = to_q * ln.exp ();
238
225
239
- // To cancel error made by Expmap ambiguity, do blends .
226
+ // To cancel error made by Expmap ambiguity, do blending .
240
227
return q1.slerp (q2, p_weight);
241
228
}
242
229
243
- Quaternion Quaternion::spherical_cubic_interpolate_in_time (const Quaternion &p_b, const Quaternion &p_pre_a, const Quaternion &p_post_b, const real_t & p_weight,
244
- const real_t & p_b_t , const real_t & p_pre_a_t , const real_t & p_post_b_t ) const {
230
+ Quaternion Quaternion::spherical_cubic_interpolate_in_time (const Quaternion &p_b, const Quaternion &p_pre_a, const Quaternion &p_post_b, real_t p_weight,
231
+ real_t p_b_t , real_t p_pre_a_t , real_t p_post_b_t ) const {
245
232
#ifdef MATH_CHECKS
246
- ERR_FAIL_COND_V_MSG (!is_normalized (), Quaternion (), " The start quaternion must be normalized." );
247
- ERR_FAIL_COND_V_MSG (!p_b.is_normalized (), Quaternion (), " The end quaternion must be normalized." );
233
+ ERR_FAIL_COND_V_MSG (!is_normalized (), Quaternion (), " The start quaternion " + operator String () + " must be normalized." );
234
+ ERR_FAIL_COND_V_MSG (!p_b.is_normalized (), Quaternion (), " The end quaternion " + p_b. operator String () + " must be normalized." );
248
235
#endif
249
236
Quaternion from_q = *this ;
250
237
Quaternion pre_q = p_pre_a;
@@ -287,7 +274,7 @@ Quaternion Quaternion::spherical_cubic_interpolate_in_time(const Quaternion &p_b
287
274
ln.z = Math::cubic_interpolate_in_time (ln_from.z , ln_to.z , ln_pre.z , ln_post.z , p_weight, p_b_t , p_pre_a_t , p_post_b_t );
288
275
Quaternion q2 = to_q * ln.exp ();
289
276
290
- // To cancel error made by Expmap ambiguity, do blends .
277
+ // To cancel error made by Expmap ambiguity, do blending .
291
278
return q1.slerp (q2, p_weight);
292
279
}
293
280
@@ -309,7 +296,7 @@ real_t Quaternion::get_angle() const {
309
296
310
297
Quaternion::Quaternion (const Vector3 &p_axis, real_t p_angle) {
311
298
#ifdef MATH_CHECKS
312
- ERR_FAIL_COND_MSG (!p_axis.is_normalized (), " The axis Vector3 must be normalized." );
299
+ ERR_FAIL_COND_MSG (!p_axis.is_normalized (), " The axis Vector3 " + p_axis. operator String () + " must be normalized." );
313
300
#endif
314
301
real_t d = p_axis.length ();
315
302
if (d == 0 ) {
@@ -332,7 +319,7 @@ Quaternion::Quaternion(const Vector3 &p_axis, real_t p_angle) {
332
319
// (ax, ay, az), where ax is the angle of rotation around x axis,
333
320
// and similar for other axes.
334
321
// This implementation uses YXZ convention (Z is the first rotation).
335
- Quaternion::Quaternion (const Vector3 &p_euler) {
322
+ Quaternion Quaternion::from_euler (const Vector3 &p_euler) {
336
323
real_t half_a1 = p_euler.y * 0 .5f ;
337
324
real_t half_a2 = p_euler.x * 0 .5f ;
338
325
real_t half_a3 = p_euler.z * 0 .5f ;
@@ -348,10 +335,11 @@ Quaternion::Quaternion(const Vector3 &p_euler) {
348
335
real_t cos_a3 = Math::cos (half_a3);
349
336
real_t sin_a3 = Math::sin (half_a3);
350
337
351
- x = sin_a1 * cos_a2 * sin_a3 + cos_a1 * sin_a2 * cos_a3;
352
- y = sin_a1 * cos_a2 * cos_a3 - cos_a1 * sin_a2 * sin_a3;
353
- z = -sin_a1 * sin_a2 * cos_a3 + cos_a1 * cos_a2 * sin_a3;
354
- w = sin_a1 * sin_a2 * sin_a3 + cos_a1 * cos_a2 * cos_a3;
338
+ return Quaternion (
339
+ sin_a1 * cos_a2 * sin_a3 + cos_a1 * sin_a2 * cos_a3,
340
+ sin_a1 * cos_a2 * cos_a3 - cos_a1 * sin_a2 * sin_a3,
341
+ -sin_a1 * sin_a2 * cos_a3 + cos_a1 * cos_a2 * sin_a3,
342
+ sin_a1 * sin_a2 * sin_a3 + cos_a1 * cos_a2 * cos_a3);
355
343
}
356
344
357
345
} // namespace godot
0 commit comments