From a594136a9af9494749984d644f08f13a188e2ef9 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Mon, 15 Sep 2014 20:12:13 -0700 Subject: [PATCH] Fix up hand roll, pitch, and yaw as best able for now --- examples/leapHands.js | 23 ++++++++++++----------- interface/src/avatar/Avatar.cpp | 30 ++++++++++-------------------- interface/src/avatar/Avatar.h | 7 +++---- interface/src/renderer/Model.h | 26 +++++++++++++------------- 4 files changed, 38 insertions(+), 48 deletions(-) diff --git a/examples/leapHands.js b/examples/leapHands.js index db4988dcc4..08d4a918bf 100644 --- a/examples/leapHands.js +++ b/examples/leapHands.js @@ -211,6 +211,7 @@ var leapHands = (function () { handRoll, handPitch, handYaw, + handRotation, locRotation; for (h = 0; h < NUM_HANDS; h += 1) { @@ -229,25 +230,25 @@ var leapHands = (function () { // TODO: 2.0* scale factor should not be necessary; Leap Motion controller code needs investigating. handRoll = 2.0 * -hands[h].controller.getAbsRotation().z; handPitch = 2.0 * -wrists[h].controller.getAbsRotation().x; - handYaw = 2.0 * -wrists[h].controller.getAbsRotation().y; + handYaw = 2.0 * wrists[h].controller.getAbsRotation().y; - // TODO: Leap Motion controller's right-hand roll calculation is off by 90 degrees. + // TODO: Leap Motion controller's right-hand roll calculation only works if physical hand is upside down. + // Approximate fix is to add a fudge factor. if (h === 1) { - handRoll = handRoll + PI / 2.0; + handRoll = handRoll + 0.6 * PI; } // Hand position and orientation ... if (h === 0) { - MyAvatar.setJointModelPositionAndOrientation(hands[h].jointName, handOffset, Quat.fromPitchYawRollRadians( - handPitch, - -PI / 2.0 - handYaw, - handRoll), true); + handRotation = Quat.multiply(Quat.angleAxis(-90.0, { x: 0, y: 1, z: 0 }), + Quat.fromVec3Radians({ x: handRoll, y: handYaw, z: -handPitch })); + + } else { - MyAvatar.setJointModelPositionAndOrientation(hands[h].jointName, handOffset, Quat.fromPitchYawRollRadians( - handPitch, - PI / 2.0 - handYaw, - handRoll), true); + handRotation = Quat.multiply(Quat.angleAxis(90.0, { x: 0, y: 1, z: 0 }), + Quat.fromVec3Radians({ x: -handRoll, y: handYaw, z: handPitch })); } + MyAvatar.setJointModelPositionAndOrientation(hands[h].jointName, handOffset, handRotation, true); // Finger joints ... // TODO: 2.0 * scale factors should not be necessary; Leap Motion controller code needs investigating. diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 301020f1c5..1eaa717585 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -840,36 +840,26 @@ glm::quat Avatar::getJointCombinedRotation(const QString& name) const { return rotation; } -bool Avatar::setJointModelPositionAndOrientation(int index, glm::vec3 position, const glm::quat& rotation, - bool useRotation) { - bool success; +const float SCRIPT_PRIORITY = DEFAULT_PRIORITY + 1.0f; + +void Avatar::setJointModelPositionAndOrientation(int index, glm::vec3 position, const glm::quat& rotation) { if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(const_cast(this), "setJointModelPositionAndOrientation", - Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, success), Q_ARG(const int, index), - Q_ARG(const glm::vec3, position), - Q_ARG(const glm::quat&, rotation), Q_ARG(bool, useRotation)); + Qt::BlockingQueuedConnection, Q_ARG(const int, index), Q_ARG(const glm::vec3, position), + Q_ARG(const glm::quat&, rotation)); } else { - qDebug() << "setJointModelPositionAndOrientation()"; - success = _skeletonModel.setJointPosition(index, position, rotation, useRotation, -1, true, - glm::vec3(0.0, -1.0, 0.0), DEFAULT_PRIORITY + 2.0f); + _skeletonModel.inverseKinematics(index, position, rotation, SCRIPT_PRIORITY); } - return success; } -bool Avatar::setJointModelPositionAndOrientation(const QString& name, glm::vec3 position, const glm::quat& rotation, - bool useRotation) { - bool success; +void Avatar::setJointModelPositionAndOrientation(const QString& name, glm::vec3 position, const glm::quat& rotation) { if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(const_cast(this), "setJointModelPositionAndOrientation", - Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, success), Q_ARG(const QString&, name), - Q_ARG(const glm::vec3, position), - Q_ARG(const glm::quat&, rotation), Q_ARG(bool, useRotation)); + Qt::BlockingQueuedConnection, Q_ARG(const QString&, name), Q_ARG(const glm::vec3, position), + Q_ARG(const glm::quat&, rotation)); } else { - qDebug() << "setJointModelPositionAndOrientation()"; - success = _skeletonModel.setJointPosition(getJointIndex(name), position, rotation, useRotation, -1, true, - glm::vec3(0.0, -1.0, 0.0), DEFAULT_PRIORITY + 2.0f); + _skeletonModel.inverseKinematics(getJointIndex(name), position, rotation, SCRIPT_PRIORITY); } - return success; } void Avatar::scaleVectorRelativeToPosition(glm::vec3 &positionToScale) const { diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index 3a29f04d4c..20f8f0c9a2 100755 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -151,10 +151,9 @@ public: Q_INVOKABLE glm::quat getJointCombinedRotation(int index) const; Q_INVOKABLE glm::quat getJointCombinedRotation(const QString& name) const; - Q_INVOKABLE bool setJointModelPositionAndOrientation(int index, const glm::vec3 position, - const glm::quat& rotation = glm::quat(), bool useRotation = false); - Q_INVOKABLE bool setJointModelPositionAndOrientation(const QString& name, const glm::vec3 position, - const glm::quat& rotation = glm::quat(), bool useRotation = false); + Q_INVOKABLE void setJointModelPositionAndOrientation(int index, const glm::vec3 position, const glm::quat& rotation); + Q_INVOKABLE void setJointModelPositionAndOrientation(const QString& name, const glm::vec3 position, + const glm::quat& rotation); Q_INVOKABLE glm::vec3 getVelocity() const { return _velocity; } Q_INVOKABLE glm::vec3 getAcceleration() const { return _acceleration; } diff --git a/interface/src/renderer/Model.h b/interface/src/renderer/Model.h index 39090c7e1b..9d02168c47 100644 --- a/interface/src/renderer/Model.h +++ b/interface/src/renderer/Model.h @@ -183,17 +183,7 @@ public: QVector& getJointStates() { return _jointStates; } const QVector& getJointStates() const { return _jointStates; } - /// \param jointIndex index of joint in model structure - /// \param position position of joint in model-frame - /// \param rotation rotation of joint in model-frame - /// \param useRotation false if rotation should be ignored - /// \param lastFreeIndex - /// \param allIntermediatesFree - /// \param alignment - /// \return true if joint exists - bool setJointPosition(int jointIndex, const glm::vec3& position, const glm::quat& rotation = glm::quat(), - bool useRotation = false, int lastFreeIndex = -1, bool allIntermediatesFree = false, - const glm::vec3& alignment = glm::vec3(0.0f, -1.0f, 0.0f), float priority = 1.0f); + void inverseKinematics(int jointIndex, glm::vec3 position, const glm::quat& rotation, float priority); protected: QSharedPointer _geometry; @@ -238,8 +228,18 @@ protected: virtual void updateVisibleJointStates(); - void inverseKinematics(int jointIndex, glm::vec3 position, const glm::quat& rotation, float priority); - + /// \param jointIndex index of joint in model structure + /// \param position position of joint in model-frame + /// \param rotation rotation of joint in model-frame + /// \param useRotation false if rotation should be ignored + /// \param lastFreeIndex + /// \param allIntermediatesFree + /// \param alignment + /// \return true if joint exists + bool setJointPosition(int jointIndex, const glm::vec3& position, const glm::quat& rotation = glm::quat(), + bool useRotation = false, int lastFreeIndex = -1, bool allIntermediatesFree = false, + const glm::vec3& alignment = glm::vec3(0.0f, -1.0f, 0.0f), float priority = 1.0f); + /// Restores the indexed joint to its default position. /// \param fraction the fraction of the default position to apply (i.e., 0.25f to slerp one fourth of the way to /// the original position