Return arm to neutral position when mouse pointer is invisible.

This commit is contained in:
Andrzej Kapolka 2013-11-05 16:06:11 -08:00
parent aa03af8dbf
commit 9460fb87c2
4 changed files with 46 additions and 1 deletions

View file

@ -831,6 +831,7 @@ void MyAvatar::updateHandMovementAndTouching(float deltaTime, bool enableHandMov
// reset hand and arm positions according to hand movement
glm::vec3 up = orientation * IDENTITY_UP;
bool pointing = false;
if (enableHandMovement && glm::length(_mouseRayDirection) > EPSILON && !Application::getInstance()->isMouseHidden()) {
// confine to the approximate shoulder plane
glm::vec3 pointDirection = _mouseRayDirection;
@ -842,6 +843,7 @@ void MyAvatar::updateHandMovementAndTouching(float deltaTime, bool enableHandMov
}
const float FAR_AWAY_POINT = TREE_SCALE;
_skeleton.joint[AVATAR_JOINT_RIGHT_FINGERTIPS].position = _mouseRayOrigin + pointDirection * FAR_AWAY_POINT;
pointing = true;
}
_avatarTouch.setMyBodyPosition(_position);
@ -933,6 +935,8 @@ void MyAvatar::updateHandMovementAndTouching(float deltaTime, bool enableHandMov
if (_mousePressed) {
_handState = HAND_STATE_GRASPING;
} else if (pointing) {
_handState = HAND_STATE_POINTING;
} else {
_handState = HAND_STATE_NULL;
}

View file

@ -28,7 +28,12 @@ void SkeletonModel::simulate(float deltaTime) {
Model::simulate(deltaTime);
setRightHandPosition(_owningAvatar->getHandPosition());
if (_owningAvatar->getHandState() == HAND_STATE_NULL) {
const float HAND_RESTORATION_RATE = 0.25f;
restoreRightHandPosition(HAND_RESTORATION_RATE);
} else {
setRightHandPosition(_owningAvatar->getHandPosition());
}
}
bool SkeletonModel::render(float alpha) {

View file

@ -477,6 +477,10 @@ bool Model::setLeftHandPosition(const glm::vec3& position) {
return isActive() && setJointPosition(_geometry->getFBXGeometry().leftHandJointIndex, position);
}
bool Model::restoreLeftHandPosition(float percent) {
return isActive() && restoreJointPosition(_geometry->getFBXGeometry().leftHandJointIndex, percent);
}
bool Model::setLeftHandRotation(const glm::quat& rotation) {
return isActive() && setJointRotation(_geometry->getFBXGeometry().leftHandJointIndex, rotation);
}
@ -485,6 +489,10 @@ bool Model::setRightHandPosition(const glm::vec3& position) {
return isActive() && setJointPosition(_geometry->getFBXGeometry().rightHandJointIndex, position);
}
bool Model::restoreRightHandPosition(float percent) {
return isActive() && restoreJointPosition(_geometry->getFBXGeometry().rightHandJointIndex, percent);
}
bool Model::setRightHandRotation(const glm::quat& rotation) {
return isActive() && setJointRotation(_geometry->getFBXGeometry().rightHandJointIndex, rotation);
}
@ -617,6 +625,18 @@ bool Model::setJointRotation(int jointIndex, const glm::quat& rotation) {
return true;
}
bool Model::restoreJointPosition(int jointIndex, float percent) {
if (jointIndex == -1 || _jointStates.isEmpty()) {
return false;
}
const FBXGeometry& geometry = _geometry->getFBXGeometry();
const QVector<int>& freeLineage = geometry.joints.at(jointIndex).freeLineage;
foreach (int index, freeLineage) {
_jointStates[index].rotation = safeMix(_jointStates[index].rotation, geometry.joints.at(index).rotation, percent);
}
}
void Model::deleteGeometry() {
foreach (Model* attachment, _attachments) {
delete attachment;

View file

@ -74,6 +74,11 @@ public:
/// \return whether or not the left hand joint was found
bool setLeftHandPosition(const glm::vec3& position);
/// Restores some percentage of the default position of the left hand.
/// \param percent the percentage of the default position to restore
/// \return whether or not the left hand joint was found
bool restoreLeftHandPosition(float percent = 1.0f);
/// Sets the rotation of the left hand.
/// \return whether or not the left hand joint was found
bool setLeftHandRotation(const glm::quat& rotation);
@ -82,6 +87,11 @@ public:
/// \return whether or not the right hand joint was found
bool setRightHandPosition(const glm::vec3& position);
/// Restores some percentage of the default position of the right hand.
/// \param percent the percentage of the default position to restore
/// \return whether or not the right hand joint was found
bool restoreRightHandPosition(float percent = 1.0f);
/// Sets the rotation of the right hand.
/// \return whether or not the right hand joint was found
bool setRightHandRotation(const glm::quat& rotation);
@ -130,6 +140,12 @@ protected:
bool setJointPosition(int jointIndex, const glm::vec3& position);
bool setJointRotation(int jointIndex, const glm::quat& rotation);
/// Restores the indexed joint to its default position.
/// \param percent the percentage of the default position to apply (i.e., 0.25f to slerp one fourth of the way to
/// the original position
/// \return true if the joint was found
bool restoreJointPosition(int jointIndex, float percent = 1.0f);
private:
void deleteGeometry();