MATH: Replace Quaternion XYZ with Euler.

This commit is contained in:
Joseph Jezak 2014-08-18 11:44:48 -04:00
parent 99fa91053c
commit e34d0ddba3
6 changed files with 25 additions and 25 deletions

View file

@ -2286,7 +2286,7 @@ Math::Quaternion Actor::getRotationQuat() const {
if (g_grim->getGameType() == GType_MONKEY4) { if (g_grim->getGameType() == GType_MONKEY4) {
return Math::Quaternion(getFinalMatrix()).inverse(); return Math::Quaternion(getFinalMatrix()).inverse();
} else { } 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 // 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 // Get the final position coordinates
_pos = _pos - parentMatrix.getPosition(); _pos = _pos - parentMatrix.getPosition();
@ -2464,7 +2464,7 @@ void Actor::detach() {
// Position and rotate the actor in relation to the world coords // Position and rotate the actor in relation to the world coords
setPos(getWorldPos()); setPos(getWorldPos());
Math::Quaternion q = getRotationQuat(); 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 // Remove the attached actor
_attachedActor = 0; _attachedActor = 0;

View file

@ -146,7 +146,7 @@ void Head::Joint::orientTowards(bool entering, const Math::Vector3d &point, floa
// Assemble ypr to a quaternion. // Assemble ypr to a quaternion.
// This is the head orientation with respect to parent-with-keyframe-animation space. // 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; _node->_animRot = _node->_animRot * lookAtQuat;
} }

View file

@ -299,7 +299,7 @@ void KeyframeAnim::KeyframeNode::animate(ModelNode &node, float frame, float fad
node._animPos += (pos - node._pos) * fade; 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; rotQuat = node._animRot * node._rot.inverse() * rotQuat;
node._animRot = node._animRot.slerpQuat(rotQuat, fade); node._animRot = node._animRot.slerpQuat(rotQuat, fade);
} }

View file

@ -631,7 +631,7 @@ void ModelNode::loadBinary(Common::SeekableReadStream *data, ModelNode *hierNode
_yaw = get_float(f); _yaw = get_float(f);
data->read(f, 4); data->read(f, 4);
_roll = get_float(f); _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; _animPos = _pos;
_sprite = nullptr; _sprite = nullptr;

View file

@ -184,29 +184,29 @@ Angle Quaternion::getAngleBetween(const Quaternion &to) {
return diff; 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 // 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 // Convert this rotation matrix to a Quaternion
return Quaternion(rot); 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 // Create a matrix from the Quaternion
Matrix4 rot = toMatrix(); Matrix4 rot = toMatrix();
// Convert the matrix to Euler Angles // Convert the matrix to Euler Angles
Angle ex, ey, ez; Angle f, s, t;
rot.getEuler(&ex, &ey, &ez, order); rot.getEuler(&f, &s, &t, order);
// Assign the Angles if we have a reference // Assign the Angles if we have a reference
if (rotX != nullptr) if (first != nullptr)
*rotX = ex; *first = f;
if (rotY != nullptr) if (second != nullptr)
*rotY = ey; *second = s;
if (rotZ != nullptr) if (third != nullptr)
*rotZ = ez; *third = t;
} }
Quaternion Quaternion::operator*(const Quaternion &o) const { Quaternion Quaternion::operator*(const Quaternion &o) const {

View file

@ -114,23 +114,23 @@ public:
/** /**
* Constructs a Quaternion from Euler Coordinates * Constructs a Quaternion from Euler Coordinates
* @param x The Euler Angle for the X Axis * @param first The Euler Angle for the first Axis
* @param y The Euler Angle for the Y Axis * @param second The Euler Angle for the second Axis
* @param z The Euler Angle for the Z Axis * @param third The Euler Angle for the third Axis
* @param order The Euler Order, specified in Rotation3D * @param order The Euler Order, specified in Rotation3D
* @return The new Quaternion * @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 * Returns Euler Angles based on the Euler Order
* @param x The Euler Angle for the X Axis * @param first The Euler Angle for the first Axis
* @param y The Euler Angle for the Y Axis * @param second The Euler Angle for the second Axis
* @param z The Euler Angle for the Z Axis * @param third The Euler Angle for the third Axis
* @param order The Euler Order, specified in Rotation3D * @param order The Euler Order, specified in Rotation3D
* @return The new Quaternion * @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 * Create a Quaternion from a rotation around the X Axis