From e34d0ddba30a2c37f8c929ba1348dece7194db91 Mon Sep 17 00:00:00 2001 From: Joseph Jezak Date: Mon, 18 Aug 2014 11:44:48 -0400 Subject: [PATCH] MATH: Replace Quaternion XYZ with Euler. --- engines/grim/actor.cpp | 6 +++--- engines/grim/costume/head.cpp | 2 +- engines/grim/keyframe.cpp | 2 +- engines/grim/model.cpp | 2 +- math/quat.cpp | 22 +++++++++++----------- math/quat.h | 16 ++++++++-------- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/engines/grim/actor.cpp b/engines/grim/actor.cpp index 11512b322d5..a0edc6eca1e 100644 --- a/engines/grim/actor.cpp +++ b/engines/grim/actor.cpp @@ -2286,7 +2286,7 @@ Math::Quaternion Actor::getRotationQuat() const { if (g_grim->getGameType() == GType_MONKEY4) { return Math::Quaternion(getFinalMatrix()).inverse(); } else { - return Math::Quaternion::fromXYZ(_yaw, _pitch, _roll, Math::EO_ZXY).inverse(); + return Math::Quaternion::fromEuler(_yaw, _pitch, _roll, Math::EO_ZXY).inverse(); } } @@ -2433,7 +2433,7 @@ void Actor::attachToActor(Actor *parent, const char *joint) { } // Get the final rotation euler coordinates - newRot.getXYZ(&_roll, &_yaw, &_pitch, Math::EO_ZYX); + newRot.getEuler(&_roll, &_yaw, &_pitch, Math::EO_ZYX); // Get the final position coordinates _pos = _pos - parentMatrix.getPosition(); @@ -2464,7 +2464,7 @@ void Actor::detach() { // Position and rotate the actor in relation to the world coords setPos(getWorldPos()); Math::Quaternion q = getRotationQuat(); - q.inverse().getXYZ(&_roll, &_yaw, &_pitch, Math::EO_ZYX); + q.inverse().getEuler(&_roll, &_yaw, &_pitch, Math::EO_ZYX); // Remove the attached actor _attachedActor = 0; diff --git a/engines/grim/costume/head.cpp b/engines/grim/costume/head.cpp index cf1f19d2b90..daf2e321269 100644 --- a/engines/grim/costume/head.cpp +++ b/engines/grim/costume/head.cpp @@ -146,7 +146,7 @@ void Head::Joint::orientTowards(bool entering, const Math::Vector3d &point, floa // Assemble ypr to a quaternion. // This is the head orientation with respect to parent-with-keyframe-animation space. - Math::Quaternion lookAtQuat = Math::Quaternion::fromXYZ(y, pt, r, Math::EO_ZXY); + Math::Quaternion lookAtQuat = Math::Quaternion::fromEuler(y, pt, r, Math::EO_ZXY); _node->_animRot = _node->_animRot * lookAtQuat; } diff --git a/engines/grim/keyframe.cpp b/engines/grim/keyframe.cpp index 93c49f20228..cf26a4b8324 100644 --- a/engines/grim/keyframe.cpp +++ b/engines/grim/keyframe.cpp @@ -299,7 +299,7 @@ void KeyframeAnim::KeyframeNode::animate(ModelNode &node, float frame, float fad node._animPos += (pos - node._pos) * fade; - Math::Quaternion rotQuat = Math::Quaternion::fromXYZ(yaw, pitch, roll, Math::EO_ZXY); + Math::Quaternion rotQuat = Math::Quaternion::fromEuler(yaw, pitch, roll, Math::EO_ZXY); rotQuat = node._animRot * node._rot.inverse() * rotQuat; node._animRot = node._animRot.slerpQuat(rotQuat, fade); } diff --git a/engines/grim/model.cpp b/engines/grim/model.cpp index a44f25e4ac6..a93b95f669e 100644 --- a/engines/grim/model.cpp +++ b/engines/grim/model.cpp @@ -631,7 +631,7 @@ void ModelNode::loadBinary(Common::SeekableReadStream *data, ModelNode *hierNode _yaw = get_float(f); data->read(f, 4); _roll = get_float(f); - _rot = Math::Quaternion::fromXYZ(_yaw, _pitch, _roll, Math::EO_ZXY); + _rot = Math::Quaternion::fromEuler(_yaw, _pitch, _roll, Math::EO_ZXY); _animPos = _pos; _sprite = nullptr; diff --git a/math/quat.cpp b/math/quat.cpp index 4efa4d20c79..e0f2b879f47 100644 --- a/math/quat.cpp +++ b/math/quat.cpp @@ -184,29 +184,29 @@ Angle Quaternion::getAngleBetween(const Quaternion &to) { return diff; } -Quaternion Quaternion::fromXYZ(const Angle &rotX, const Angle &rotY, const Angle &rotZ, EulerOrder order) { +Quaternion Quaternion::fromEuler(const Angle &first, const Angle &second, const Angle &third, EulerOrder order) { // First create a matrix with the rotation - Matrix4 rot(rotX, rotY, rotZ, order); + Matrix4 rot(first, second, third, order); // Convert this rotation matrix to a Quaternion return Quaternion(rot); } -void Quaternion::getXYZ(Angle *rotX, Angle *rotY, Angle *rotZ, EulerOrder order) { +void Quaternion::getEuler(Angle *first, Angle *second, Angle *third, EulerOrder order) { // Create a matrix from the Quaternion Matrix4 rot = toMatrix(); // Convert the matrix to Euler Angles - Angle ex, ey, ez; - rot.getEuler(&ex, &ey, &ez, order); + Angle f, s, t; + rot.getEuler(&f, &s, &t, order); // Assign the Angles if we have a reference - if (rotX != nullptr) - *rotX = ex; - if (rotY != nullptr) - *rotY = ey; - if (rotZ != nullptr) - *rotZ = ez; + if (first != nullptr) + *first = f; + if (second != nullptr) + *second = s; + if (third != nullptr) + *third = t; } Quaternion Quaternion::operator*(const Quaternion &o) const { diff --git a/math/quat.h b/math/quat.h index f660e3a02d4..f4da3cf9763 100644 --- a/math/quat.h +++ b/math/quat.h @@ -114,23 +114,23 @@ public: /** * Constructs a Quaternion from Euler Coordinates - * @param x The Euler Angle for the X Axis - * @param y The Euler Angle for the Y Axis - * @param z The Euler Angle for the Z Axis + * @param first The Euler Angle for the first Axis + * @param second The Euler Angle for the second Axis + * @param third The Euler Angle for the third Axis * @param order The Euler Order, specified in Rotation3D * @return The new Quaternion */ - static Quaternion fromXYZ(const Angle &rotX, const Angle &rotY, const Angle &rotZ, EulerOrder order); + static Quaternion fromEuler(const Angle &first, const Angle &second, const Angle &third, EulerOrder order); /** * Returns Euler Angles based on the Euler Order - * @param x The Euler Angle for the X Axis - * @param y The Euler Angle for the Y Axis - * @param z The Euler Angle for the Z Axis + * @param first The Euler Angle for the first Axis + * @param second The Euler Angle for the second Axis + * @param third The Euler Angle for the third Axis * @param order The Euler Order, specified in Rotation3D * @return The new Quaternion */ - void getXYZ(Angle *rotX, Angle *rotY, Angle *rotZ, EulerOrder order); + void getEuler(Angle *first, Angle *second, Angle *third, EulerOrder order); /** * Create a Quaternion from a rotation around the X Axis