Fix up hand roll, pitch, and yaw as best able for now

This commit is contained in:
David Rowe 2014-09-15 20:12:13 -07:00
parent 1527c40e1d
commit a594136a9a
4 changed files with 38 additions and 48 deletions

View file

@ -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.

View file

@ -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<Avatar*>(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<Avatar*>(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 {

View file

@ -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; }

View file

@ -183,17 +183,7 @@ public:
QVector<JointState>& getJointStates() { return _jointStates; }
const QVector<JointState>& 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<NetworkGeometry> _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