Made increaseScale and decreaseScale more responsive at limits

This commit is contained in:
Anthony J. Thibault 2017-11-22 14:45:52 -08:00
parent 9f54ce55f3
commit b3896f664d
4 changed files with 28 additions and 22 deletions

View file

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

View file

@ -558,8 +558,6 @@ public slots:
void increaseSize();
void decreaseSize();
void resetSize();
float getDomainMinScale();
float getDomainMaxScale();
void setGravity(float gravity);
float getGravity();

View file

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

View file

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