From 5265103c2d15997cadc71b1cf236b9fb55564e4a Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Sat, 2 Aug 2008 17:30:25 +0000 Subject: [PATCH] Add two new functions Vector3f_EulerToForwardVector and Vector3f_EulerToUpVector which compute a forward and up vector from a rotation vector in Euler angles (pitch, yaw and roll) git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5744 4a71c877-e1ca-e34f-864e-861f7616d084 --- lib/ivis_common/pievector.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lib/ivis_common/pievector.h b/lib/ivis_common/pievector.h index e4fe0b156..88f3c2962 100644 --- a/lib/ivis_common/pievector.h +++ b/lib/ivis_common/pievector.h @@ -391,6 +391,41 @@ static inline WZ_DECL_CONST Vector3f Vector3f_Normalise(const Vector3f v) } } +/*! + * Compute the forward vector, a body's local Z axis, for a set of Euler angles + * (pitch, yaw and roll). + * \param v Vector containing the pitch, yaw and roll in its x, y and z members + * respectively. + * \return Forward vector. + */ +static inline WZ_DECL_CONST Vector3f Vector3f_EulerToForwardVector(const Vector3f v) +{ + Vector3f dest = { + cosf(v.x) * sinf(v.y), + -sinf(v.x), + cosf(v.x) * cosf(v.y) + }; + + return dest; +} + +/*! + * Compute the up vector, a body's local Y axis, for a set of Euler angles + * (pitch, yaw and roll). + * \param v Vector containing the pitch, yaw and roll in its x, y and z members + * respectively. + * \return Up vector. + */ +static inline WZ_DECL_CONST Vector3f Vector3f_EulerToUpVector(const Vector3f v) +{ + Vector3f dest = { + sinf(v.x) * sinf(v.y) * cosf(v.z) - sinf(v.z) * cosf(v.z), + cosf(v.x) * cosf(v.z), + sinf(v.x) * cosf(v.y) * cosf(v.z) + sinf(v.y) * sinf(v.z) + }; + + return dest; +} /*! * Set the vector field by field, same as v = (Vector3i){x, y, z};