summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2017-09-28 12:50:28 +0100
committerSean Harmer <sean.harmer@kdab.com>2017-10-06 10:27:35 +0000
commitbff7d2aaa74cb6d576e56b44617949f29c36cead (patch)
tree022933ab4ecb0040e336a1eb834436ac3e3d6b7c /src
parente743158b0b17335ef321c2c378bacfe2697ba5f1 (diff)
Decompose a new quaternion rotation into euler angles
Same as in QTransform. Change-Id: Ia1dca19c8faf996629ecbf8832e5625e7b22532c Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/core/transforms/qjoint.cpp54
-rw-r--r--src/core/transforms/qjoint.h1
2 files changed, 34 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);