diff options
-rw-r--r-- | src/core/transforms/qjoint.cpp | 54 | ||||
-rw-r--r-- | src/core/transforms/qjoint.h | 1 | ||||
-rw-r--r-- | tests/auto/core/qjoint/tst_qjoint.cpp | 7 |
3 files changed, 41 insertions, 21 deletions
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); diff --git a/tests/auto/core/qjoint/tst_qjoint.cpp b/tests/auto/core/qjoint/tst_qjoint.cpp index a63d275c5..ec1a45f90 100644 --- a/tests/auto/core/qjoint/tst_qjoint.cpp +++ b/tests/auto/core/qjoint/tst_qjoint.cpp @@ -65,6 +65,7 @@ private Q_SLOTS: { // WHEN + joint.setToIdentity(); QSignalSpy spy(&joint, SIGNAL(scaleChanged(QVector3D))); const QVector3D newValue(2.5f, 2.0f, 1.3f); joint.setScale(newValue); @@ -85,6 +86,7 @@ private Q_SLOTS: { // WHEN + joint.setToIdentity(); QSignalSpy spy(&joint, SIGNAL(rotationChanged(QQuaternion))); const auto newValue = QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, 45.0f); joint.setRotation(newValue); @@ -105,6 +107,7 @@ private Q_SLOTS: { // WHEN + joint.setToIdentity(); QSignalSpy spy(&joint, SIGNAL(translationChanged(QVector3D))); const QVector3D newValue(1.0f, 2.0f, 3.0f); joint.setTranslation(newValue); @@ -125,6 +128,7 @@ private Q_SLOTS: { // WHEN + joint.setToIdentity(); QSignalSpy spy(&joint, SIGNAL(inverseBindMatrixChanged(QMatrix4x4))); QMatrix4x4 newValue; newValue.scale(3.5f); @@ -146,6 +150,7 @@ private Q_SLOTS: { // WHEN + joint.setToIdentity(); QSignalSpy spy(&joint, SIGNAL(rotationChanged(QQuaternion))); QSignalSpy spyEuler(&joint, SIGNAL(rotationXChanged(float))); const auto newValue = 45.0f; @@ -176,6 +181,7 @@ private Q_SLOTS: { // WHEN + joint.setToIdentity(); QSignalSpy spy(&joint, SIGNAL(rotationChanged(QQuaternion))); QSignalSpy spyEuler(&joint, SIGNAL(rotationYChanged(float))); const auto newValue = 45.0f; @@ -206,6 +212,7 @@ private Q_SLOTS: { // WHEN + joint.setToIdentity(); QSignalSpy spy(&joint, SIGNAL(rotationChanged(QQuaternion))); QSignalSpy spyEuler(&joint, SIGNAL(rotationZChanged(float))); const auto newValue = 45.0f; |