MATH: Add fromEuler() to Math::Quaternion

This commit is contained in:
Dries Harnie 2012-06-08 00:57:14 +02:00
parent 0b5a4b0cd1
commit 9541c89859
2 changed files with 21 additions and 0 deletions

View File

@ -102,4 +102,24 @@ Matrix4 Quaternion::toMatrix() {
return dst;
}
Quaternion Quaternion::fromEuler(const Angle & yaw, const Angle & pitch, const Angle & roll) {
float cr, cp, cy, sr, sp, sy, cpcy, spsy;
cy = (yaw / 2).getCosine();
cp = (pitch / 2).getCosine();
cr = (roll / 2).getCosine();
sy = (yaw / 2).getSine();
sp = (pitch / 2).getSine();
sr = (roll / 2).getSine();
cpcy = cp * cy;
spsy = sp * sy;
return Quaternion(
cr * sp * cy + sr * cp * sy,
cr * cp * sy - sr * sp * cy,
sr * cpcy - cr * spsy,
cr * cpcy + sr * spsy);
}
}

View File

@ -59,6 +59,7 @@ public:
* @return the resulting quaternion.
*/
Quaternion slerpQuat(const Quaternion& to, const float t);
static Quaternion fromEuler(const Angle & yaw, const Angle & pitch, const Angle & roll);
inline static Quaternion get_quaternion(const char *data) {
return Quaternion(get_float(data), get_float(data + 4), get_float(data + 8), get_float(data + 12));