From b3896f664d8439b460e3eeacf236da71dc397719 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Wed, 22 Nov 2017 14:45:52 -0800 Subject: [PATCH] Made increaseScale and decreaseScale more responsive at limits --- interface/src/avatar/MyAvatar.cpp | 18 ++++++------------ interface/src/avatar/MyAvatar.h | 2 -- libraries/avatars/src/AvatarData.cpp | 26 ++++++++++++++++++-------- libraries/avatars/src/AvatarData.h | 4 ++++ 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index d77bfbe09d..5da7e37fec 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -2162,16 +2162,6 @@ bool findAvatarAvatarPenetration(const glm::vec3 positionA, float radiusA, float // target scale to match the new scale they have chosen. When they leave the domain they will not return to the scale they were // before they entered the limiting domain. -float MyAvatar::getDomainMinScale() { - const float unscaledHeight = getUnscaledEyeHeight(); - return _domainMinimumHeight / unscaledHeight; -} - -float MyAvatar::getDomainMaxScale() { - const float unscaledHeight = getUnscaledEyeHeight(); - return _domainMaximumHeight / unscaledHeight; -} - void MyAvatar::setGravity(float gravity) { _characterController.setGravity(gravity); } @@ -2184,7 +2174,9 @@ void MyAvatar::increaseSize() { float minScale = getDomainMinScale(); float maxScale = getDomainMaxScale(); - float newTargetScale = glm::clamp(_targetScale * (1.0f + SCALING_RATIO), minScale, maxScale); + float clampedTargetScale = glm::clamp(_targetScale, minScale, maxScale); + float newTargetScale = glm::clamp(clampedTargetScale * (1.0f + SCALING_RATIO), minScale, maxScale); + setTargetScale(newTargetScale); } @@ -2192,7 +2184,9 @@ void MyAvatar::decreaseSize() { float minScale = getDomainMinScale(); float maxScale = getDomainMaxScale(); - float newTargetScale = glm::clamp(_targetScale * (1.0f - SCALING_RATIO), minScale, maxScale); + float clampedTargetScale = glm::clamp(_targetScale, minScale, maxScale); + float newTargetScale = glm::clamp(clampedTargetScale * (1.0f - SCALING_RATIO), minScale, maxScale); + setTargetScale(newTargetScale); } diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index e4e8f8d02c..3b5157fdeb 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -558,8 +558,6 @@ public slots: void increaseSize(); void decreaseSize(); void resetSize(); - float getDomainMinScale(); - float getDomainMaxScale(); void setGravity(float gravity); float getGravity(); diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 7117fd01aa..c6b78de07c 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -119,14 +119,8 @@ void AvatarData::setTargetScale(float targetScale) { float AvatarData::getDomainLimitedScale() const { if (canMeasureEyeHeight()) { - const float unscaledEyeHeight = getUnscaledEyeHeight(); - - // Add in an estimate of forehead height. - const float ratio = unscaledEyeHeight / DEFAULT_AVATAR_HEIGHT; - const float unscaledHeight = unscaledEyeHeight + ratio * DEFAULT_AVATAR_EYE_TO_TOP_OF_HEAD; - - const float minScale = _domainMinimumHeight / unscaledHeight; - const float maxScale = _domainMaximumHeight / unscaledHeight; + const float minScale = getDomainMinScale(); + const float maxScale = getDomainMaxScale(); return glm::clamp(_targetScale, minScale, maxScale); } else { // We can't make a good estimate. @@ -142,6 +136,22 @@ void AvatarData::setDomainMaximumHeight(float domainMaximumHeight) { _domainMaximumHeight = glm::clamp(domainMaximumHeight, MIN_AVATAR_HEIGHT, MAX_AVATAR_HEIGHT); } +float AvatarData::getDomainMinScale() const { + const float unscaledHeight = getUnscaledHeight(); + return _domainMinimumHeight / unscaledHeight; +} + +float AvatarData::getDomainMaxScale() const { + const float unscaledHeight = getUnscaledHeight(); + return _domainMaximumHeight / unscaledHeight; +} + +float AvatarData::getUnscaledHeight() const { + const float eyeHeight = getUnscaledEyeHeight(); + const float ratio = eyeHeight / DEFAULT_AVATAR_HEIGHT; + return eyeHeight + ratio * DEFAULT_AVATAR_EYE_TO_TOP_OF_HEAD; +} + float AvatarData::getHeight() const { const float eyeHeight = getEyeHeight(); const float ratio = eyeHeight / DEFAULT_AVATAR_HEIGHT; diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index e228fb42d5..50704b98e3 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -483,6 +483,8 @@ public: virtual void setTargetScale(float targetScale); float getDomainLimitedScale() const; + float getDomainMinScale() const; + float getDomainMaxScale() const; // returns eye height of avatar in meters, ignoreing avatar scale. // if _targetScale is 1 then this will be identical to getEyeHeight; @@ -508,6 +510,8 @@ public: */ Q_INVOKABLE virtual float getHeight() const; + float getUnscaledHeight() const; + void setDomainMinimumHeight(float domainMinimumHeight); void setDomainMaximumHeight(float domainMaximumHeight);