From bff7d2aaa74cb6d576e56b44617949f29c36cead Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Thu, 28 Sep 2017 12:50:28 +0100 Subject: Decompose a new quaternion rotation into euler angles Same as in QTransform. Change-Id: Ia1dca19c8faf996629ecbf8832e5625e7b22532c Reviewed-by: Paul Lemire --- src/core/transforms/qjoint.cpp | 54 ++++++++++++++++++++++++++---------------- src/core/transforms/qjoint.h | 1 + 2 files changed, 34 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/core/transforms/qjoint.cpp b/src/core/transforms/qjoint.cpp index 84d75d55d..3f631ec98 100644 --- a/src/core/transforms/qjoint.cpp +++ b/src/core/transforms/qjoint.cpp @@ -240,7 +240,18 @@ void QJoint::setRotation(const QQuaternion &rotation) return; d->m_rotation = rotation; + const QVector3D oldRotation = d->m_eulerRotationAngles; + d->m_eulerRotationAngles = d->m_rotation.toEulerAngles(); emit rotationChanged(rotation); + + const bool wasBlocked = blockNotifications(true); + if (!qFuzzyCompare(d->m_eulerRotationAngles.x(), oldRotation.x())) + emit rotationXChanged(d->m_eulerRotationAngles.x()); + if (!qFuzzyCompare(d->m_eulerRotationAngles.y(), oldRotation.y())) + emit rotationYChanged(d->m_eulerRotationAngles.y()); + if (!qFuzzyCompare(d->m_eulerRotationAngles.z(), oldRotation.z())) + emit rotationZChanged(d->m_eulerRotationAngles.z()); + blockNotifications(wasBlocked); } void QJoint::setTranslation(const QVector3D &translation) @@ -267,47 +278,41 @@ void QJoint::setRotationX(float rotationX) { Q_D(QJoint); - if (d->m_eulerRotationAngles.x() == rotationX) + if (qFuzzyCompare(d->m_eulerRotationAngles.x(), rotationX)) return; - d->m_eulerRotationAngles.setX(rotationX); - const QQuaternion r = QQuaternion::fromEulerAngles(d->m_eulerRotationAngles); + const auto eulers = QVector3D(rotationX, + d->m_eulerRotationAngles.y(), + d->m_eulerRotationAngles.z()); + const QQuaternion r = QQuaternion::fromEulerAngles(eulers); setRotation(r); - - const bool wasBlocked = blockNotifications(true); - emit rotationXChanged(rotationX); - blockNotifications(wasBlocked); } void QJoint::setRotationY(float rotationY) { Q_D(QJoint); - if (d->m_eulerRotationAngles.y() == rotationY) + if (qFuzzyCompare(d->m_eulerRotationAngles.y(), rotationY)) return; - d->m_eulerRotationAngles.setY(rotationY); - const QQuaternion r = QQuaternion::fromEulerAngles(d->m_eulerRotationAngles); + const auto eulers = QVector3D(d->m_eulerRotationAngles.x(), + rotationY, + d->m_eulerRotationAngles.z()); + const QQuaternion r = QQuaternion::fromEulerAngles(eulers); setRotation(r); - - const bool wasBlocked = blockNotifications(true); - emit rotationYChanged(rotationY); - blockNotifications(wasBlocked); } void QJoint::setRotationZ(float rotationZ) { Q_D(QJoint); - if (d->m_eulerRotationAngles.z() == rotationZ) + if (qFuzzyCompare(d->m_eulerRotationAngles.z(), rotationZ)) return; - d->m_eulerRotationAngles.setZ(rotationZ); - const QQuaternion r = QQuaternion::fromEulerAngles(d->m_eulerRotationAngles); + const auto eulers = QVector3D(d->m_eulerRotationAngles.x(), + d->m_eulerRotationAngles.y(), + rotationZ); + const QQuaternion r = QQuaternion::fromEulerAngles(eulers); setRotation(r); - - const bool wasBlocked = blockNotifications(true); - emit rotationZChanged(rotationZ); - blockNotifications(wasBlocked); } void QJoint::setName(const QString &name) @@ -320,6 +325,13 @@ void QJoint::setName(const QString &name) emit nameChanged(name); } +void QJoint::setToIdentity() +{ + setScale(QVector3D(1.0f, 1.0f, 1.0f)); + setRotation(QQuaternion()); + setTranslation(QVector3D()); +} + /*! Adds \a joint as a child of this joint. If \a joint has no parent, then this joint takes ownership of it. Child joints are in the coordinate system diff --git a/src/core/transforms/qjoint.h b/src/core/transforms/qjoint.h index 732cfdddb..fdc3d51a3 100644 --- a/src/core/transforms/qjoint.h +++ b/src/core/transforms/qjoint.h @@ -91,6 +91,7 @@ public Q_SLOTS: void setRotationY(float rotationY); void setRotationZ(float rotationZ); void setName(const QString &name); + void setToIdentity(); Q_SIGNALS: void scaleChanged(const QVector3D &scale); -- cgit v1.2.3