MATH: Replace Quaternion XYZ with Euler.
This commit is contained in:
parent
99fa91053c
commit
e34d0ddba3
6 changed files with 25 additions and 25 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
16
math/quat.h
16
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue