Merge pull request #44156 from aaronfranke/quat-angle-to

Add Quaternion angle_to method
This commit is contained in:
Rémi Verschelde 2021-06-18 12:35:58 +02:00 committed by GitHub
commit 7aebb8f81c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 3 deletions

View file

@ -33,6 +33,11 @@
#include "core/math/basis.h"
#include "core/string/print_string.h"
real_t Quaternion::angle_to(const Quaternion &p_to) const {
real_t d = dot(p_to);
return Math::acos(CLAMP(d * d * 2 - 1, -1, 1));
}
// get_euler_xyz returns a vector containing the Euler angles in the format
// (ax,ay,az), where ax is the angle of rotation around x axis,
// and similar for other axes.

View file

@ -28,8 +28,8 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef QUAT_H
#define QUAT_H
#ifndef QUATERNION_H
#define QUATERNION_H
#include "core/math/math_defs.h"
#include "core/math/math_funcs.h"
@ -62,6 +62,7 @@ public:
bool is_normalized() const;
Quaternion inverse() const;
_FORCE_INLINE_ real_t dot(const Quaternion &p_q) const;
real_t angle_to(const Quaternion &p_to) const;
Vector3 get_euler_xyz() const;
Vector3 get_euler_yxz() const;
@ -235,4 +236,4 @@ _FORCE_INLINE_ Quaternion operator*(const real_t &p_real, const Quaternion &p_qu
return p_quaternion * p_real;
}
#endif // QUAT_H
#endif // QUATERNION_H