mirror of
https://github.com/overte-org/overte.git
synced 2025-08-05 23:39:26 +02:00
Fix up hand roll, pitch, and yaw as best able for now
This commit is contained in:
parent
1527c40e1d
commit
a594136a9a
4 changed files with 38 additions and 48 deletions
|
@ -211,6 +211,7 @@ var leapHands = (function () {
|
||||||
handRoll,
|
handRoll,
|
||||||
handPitch,
|
handPitch,
|
||||||
handYaw,
|
handYaw,
|
||||||
|
handRotation,
|
||||||
locRotation;
|
locRotation;
|
||||||
|
|
||||||
for (h = 0; h < NUM_HANDS; h += 1) {
|
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.
|
// TODO: 2.0* scale factor should not be necessary; Leap Motion controller code needs investigating.
|
||||||
handRoll = 2.0 * -hands[h].controller.getAbsRotation().z;
|
handRoll = 2.0 * -hands[h].controller.getAbsRotation().z;
|
||||||
handPitch = 2.0 * -wrists[h].controller.getAbsRotation().x;
|
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) {
|
if (h === 1) {
|
||||||
handRoll = handRoll + PI / 2.0;
|
handRoll = handRoll + 0.6 * PI;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hand position and orientation ...
|
// Hand position and orientation ...
|
||||||
if (h === 0) {
|
if (h === 0) {
|
||||||
MyAvatar.setJointModelPositionAndOrientation(hands[h].jointName, handOffset, Quat.fromPitchYawRollRadians(
|
handRotation = Quat.multiply(Quat.angleAxis(-90.0, { x: 0, y: 1, z: 0 }),
|
||||||
handPitch,
|
Quat.fromVec3Radians({ x: handRoll, y: handYaw, z: -handPitch }));
|
||||||
-PI / 2.0 - handYaw,
|
|
||||||
handRoll), true);
|
|
||||||
} else {
|
} else {
|
||||||
MyAvatar.setJointModelPositionAndOrientation(hands[h].jointName, handOffset, Quat.fromPitchYawRollRadians(
|
handRotation = Quat.multiply(Quat.angleAxis(90.0, { x: 0, y: 1, z: 0 }),
|
||||||
handPitch,
|
Quat.fromVec3Radians({ x: -handRoll, y: handYaw, z: handPitch }));
|
||||||
PI / 2.0 - handYaw,
|
|
||||||
handRoll), true);
|
|
||||||
}
|
}
|
||||||
|
MyAvatar.setJointModelPositionAndOrientation(hands[h].jointName, handOffset, handRotation, true);
|
||||||
|
|
||||||
// Finger joints ...
|
// Finger joints ...
|
||||||
// TODO: 2.0 * scale factors should not be necessary; Leap Motion controller code needs investigating.
|
// TODO: 2.0 * scale factors should not be necessary; Leap Motion controller code needs investigating.
|
||||||
|
|
|
@ -840,36 +840,26 @@ glm::quat Avatar::getJointCombinedRotation(const QString& name) const {
|
||||||
return rotation;
|
return rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Avatar::setJointModelPositionAndOrientation(int index, glm::vec3 position, const glm::quat& rotation,
|
const float SCRIPT_PRIORITY = DEFAULT_PRIORITY + 1.0f;
|
||||||
bool useRotation) {
|
|
||||||
bool success;
|
void Avatar::setJointModelPositionAndOrientation(int index, glm::vec3 position, const glm::quat& rotation) {
|
||||||
if (QThread::currentThread() != thread()) {
|
if (QThread::currentThread() != thread()) {
|
||||||
QMetaObject::invokeMethod(const_cast<Avatar*>(this), "setJointModelPositionAndOrientation",
|
QMetaObject::invokeMethod(const_cast<Avatar*>(this), "setJointModelPositionAndOrientation",
|
||||||
Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, success), Q_ARG(const int, index),
|
Qt::BlockingQueuedConnection, Q_ARG(const int, index), Q_ARG(const glm::vec3, position),
|
||||||
Q_ARG(const glm::vec3, position),
|
Q_ARG(const glm::quat&, rotation));
|
||||||
Q_ARG(const glm::quat&, rotation), Q_ARG(bool, useRotation));
|
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "setJointModelPositionAndOrientation()";
|
_skeletonModel.inverseKinematics(index, position, rotation, SCRIPT_PRIORITY);
|
||||||
success = _skeletonModel.setJointPosition(index, position, rotation, useRotation, -1, true,
|
|
||||||
glm::vec3(0.0, -1.0, 0.0), DEFAULT_PRIORITY + 2.0f);
|
|
||||||
}
|
}
|
||||||
return success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Avatar::setJointModelPositionAndOrientation(const QString& name, glm::vec3 position, const glm::quat& rotation,
|
void Avatar::setJointModelPositionAndOrientation(const QString& name, glm::vec3 position, const glm::quat& rotation) {
|
||||||
bool useRotation) {
|
|
||||||
bool success;
|
|
||||||
if (QThread::currentThread() != thread()) {
|
if (QThread::currentThread() != thread()) {
|
||||||
QMetaObject::invokeMethod(const_cast<Avatar*>(this), "setJointModelPositionAndOrientation",
|
QMetaObject::invokeMethod(const_cast<Avatar*>(this), "setJointModelPositionAndOrientation",
|
||||||
Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, success), Q_ARG(const QString&, name),
|
Qt::BlockingQueuedConnection, Q_ARG(const QString&, name), Q_ARG(const glm::vec3, position),
|
||||||
Q_ARG(const glm::vec3, position),
|
Q_ARG(const glm::quat&, rotation));
|
||||||
Q_ARG(const glm::quat&, rotation), Q_ARG(bool, useRotation));
|
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "setJointModelPositionAndOrientation()";
|
_skeletonModel.inverseKinematics(getJointIndex(name), position, rotation, SCRIPT_PRIORITY);
|
||||||
success = _skeletonModel.setJointPosition(getJointIndex(name), position, rotation, useRotation, -1, true,
|
|
||||||
glm::vec3(0.0, -1.0, 0.0), DEFAULT_PRIORITY + 2.0f);
|
|
||||||
}
|
}
|
||||||
return success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Avatar::scaleVectorRelativeToPosition(glm::vec3 &positionToScale) const {
|
void Avatar::scaleVectorRelativeToPosition(glm::vec3 &positionToScale) const {
|
||||||
|
|
|
@ -151,10 +151,9 @@ public:
|
||||||
Q_INVOKABLE glm::quat getJointCombinedRotation(int index) const;
|
Q_INVOKABLE glm::quat getJointCombinedRotation(int index) const;
|
||||||
Q_INVOKABLE glm::quat getJointCombinedRotation(const QString& name) const;
|
Q_INVOKABLE glm::quat getJointCombinedRotation(const QString& name) const;
|
||||||
|
|
||||||
Q_INVOKABLE bool setJointModelPositionAndOrientation(int index, const glm::vec3 position,
|
Q_INVOKABLE void setJointModelPositionAndOrientation(int index, const glm::vec3 position, const glm::quat& rotation);
|
||||||
const glm::quat& rotation = glm::quat(), bool useRotation = false);
|
Q_INVOKABLE void setJointModelPositionAndOrientation(const QString& name, const glm::vec3 position,
|
||||||
Q_INVOKABLE bool setJointModelPositionAndOrientation(const QString& name, const glm::vec3 position,
|
const glm::quat& rotation);
|
||||||
const glm::quat& rotation = glm::quat(), bool useRotation = false);
|
|
||||||
|
|
||||||
Q_INVOKABLE glm::vec3 getVelocity() const { return _velocity; }
|
Q_INVOKABLE glm::vec3 getVelocity() const { return _velocity; }
|
||||||
Q_INVOKABLE glm::vec3 getAcceleration() const { return _acceleration; }
|
Q_INVOKABLE glm::vec3 getAcceleration() const { return _acceleration; }
|
||||||
|
|
|
@ -183,17 +183,7 @@ public:
|
||||||
QVector<JointState>& getJointStates() { return _jointStates; }
|
QVector<JointState>& getJointStates() { return _jointStates; }
|
||||||
const QVector<JointState>& getJointStates() const { return _jointStates; }
|
const QVector<JointState>& getJointStates() const { return _jointStates; }
|
||||||
|
|
||||||
/// \param jointIndex index of joint in model structure
|
void inverseKinematics(int jointIndex, glm::vec3 position, const glm::quat& rotation, float priority);
|
||||||
/// \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);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QSharedPointer<NetworkGeometry> _geometry;
|
QSharedPointer<NetworkGeometry> _geometry;
|
||||||
|
@ -238,8 +228,18 @@ protected:
|
||||||
|
|
||||||
virtual void updateVisibleJointStates();
|
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.
|
/// 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
|
/// \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
|
/// the original position
|
||||||
|
|
Loading…
Reference in a new issue