mirror of
https://github.com/JulianGro/overte.git
synced 2025-05-01 00:43:38 +02:00
Merge pull request #1190 from ey6es/master
Restore arms to neutral position (rather than straight down) when mouse cursor hidden, remove growing heads.
This commit is contained in:
commit
6103787811
6 changed files with 47 additions and 29 deletions
interface/src
|
@ -96,8 +96,6 @@ Avatar::Avatar(Node* owningNode) :
|
|||
_leadingAvatar(NULL),
|
||||
_voxels(this),
|
||||
_moving(false),
|
||||
_hoverOnDuration(0.0f),
|
||||
_hoverOffDuration(0.0f),
|
||||
_initialized(false),
|
||||
_handHoldingPosition(0.0f, 0.0f, 0.0f),
|
||||
_maxArmLength(0.0f),
|
||||
|
@ -387,30 +385,6 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
}
|
||||
}
|
||||
|
||||
// head scale grows when avatar is looked at
|
||||
const float BASE_MAX_SCALE = 3.0f;
|
||||
float maxScale = BASE_MAX_SCALE * glm::distance(_position, Application::getInstance()->getCamera()->getPosition());
|
||||
if (Application::getInstance()->getLookatTargetAvatar() == this) {
|
||||
_hoverOnDuration += deltaTime;
|
||||
_hoverOffDuration = 0.0f;
|
||||
|
||||
const float GROW_DELAY = 1.0f;
|
||||
const float GROW_RATE = 0.25f;
|
||||
if (_hoverOnDuration > GROW_DELAY) {
|
||||
_head.setScale(glm::mix(_head.getScale(), maxScale, GROW_RATE));
|
||||
}
|
||||
|
||||
} else {
|
||||
_hoverOnDuration = 0.0f;
|
||||
_hoverOffDuration += deltaTime;
|
||||
|
||||
const float SHRINK_DELAY = 1.0f;
|
||||
const float SHRINK_RATE = 0.25f;
|
||||
if (_hoverOffDuration > SHRINK_DELAY) {
|
||||
_head.setScale(glm::mix(_head.getScale(), 1.0f, SHRINK_RATE));
|
||||
}
|
||||
}
|
||||
|
||||
_skeletonModel.simulate(deltaTime);
|
||||
_head.setBodyRotation(glm::vec3(_bodyPitch, _bodyYaw, _bodyRoll));
|
||||
glm::vec3 headPosition;
|
||||
|
|
|
@ -227,8 +227,6 @@ protected:
|
|||
AvatarVoxelSystem _voxels;
|
||||
|
||||
bool _moving; ///< set when position is changing
|
||||
float _hoverOnDuration;
|
||||
float _hoverOffDuration;
|
||||
|
||||
// protected methods...
|
||||
glm::vec3 getBodyRightDirection() const { return getOrientation() * IDENTITY_RIGHT; }
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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,19 @@ 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);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Model::deleteGeometry() {
|
||||
foreach (Model* attachment, _attachments) {
|
||||
delete attachment;
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue