fix clamping of scale and DRY it up

This commit is contained in:
Stephen Birarda 2016-11-10 15:03:13 -08:00
parent 53769f4edf
commit d5722c1654
2 changed files with 17 additions and 28 deletions

View file

@ -1832,49 +1832,37 @@ bool findAvatarAvatarPenetration(const glm::vec3 positionA, float radiusA, float
return false; return false;
} }
void MyAvatar::clampScaleChangeToDomainLimits(float desiredScale) {
auto clampedTargetScale = glm::clamp(desiredScale, _domainMinimumScale, _domainMaximumScale);
if (clampedTargetScale != desiredScale) {
qCDebug(interfaceapp, "Forcing scale to %f since %f is not allowed by domain",
clampedTargetScale, desiredScale);
}
setTargetScale(clampedTargetScale);
qCDebug(interfaceapp, "Changed scale to %f", _targetScale);
}
void MyAvatar::increaseSize() { void MyAvatar::increaseSize() {
// clamp the target scale to the allowable scale in the domain // clamp the target scale to the allowable scale in the domain
float updatedTargetScale = _targetScale * (1.0f + SCALING_RATIO); float updatedTargetScale = _targetScale * (1.0f + SCALING_RATIO);
auto clampedTargetScale = glm::clamp(_targetScale, _domainMinimumScale, _domainMaximumScale); clampScaleChangeToDomainLimits(updatedTargetScale);
if (clampedTargetScale != updatedTargetScale) {
qCDebug(interfaceapp, "Forcing scale to %f since %f is not allowed by domain",
clampedTargetScale, updatedTargetScale);
}
setTargetScale(clampedTargetScale);
qCDebug(interfaceapp, "Changed scale to %f", (double)_targetScale);
} }
void MyAvatar::decreaseSize() { void MyAvatar::decreaseSize() {
// clamp the target scale to the allowable scale in the domain // clamp the target scale to the allowable scale in the domain
float updatedTargetScale = _targetScale * (1.0f - SCALING_RATIO); float updatedTargetScale = _targetScale * (1.0f - SCALING_RATIO);
auto clampedTargetScale = glm::clamp(_targetScale, _domainMinimumScale, _domainMaximumScale); clampScaleChangeToDomainLimits(updatedTargetScale);
if (clampedTargetScale != updatedTargetScale) {
qCDebug(interfaceapp, "Forcing scale to %f since %f is not allowed by domain",
clampedTargetScale, updatedTargetScale);
}
setTargetScale(clampedTargetScale);
qCDebug(interfaceapp, "Changed scale to %f", (double)_targetScale);
} }
void MyAvatar::resetSize() { void MyAvatar::resetSize() {
// if the default // attempt to reset avatar size to the default
const float DEFAULT_AVATAR_SCALE = 1.0f; const float DEFAULT_AVATAR_SCALE = 1.0f;
float allowedDefaultScale = glm::clamp(DEFAULT_AVATAR_SCALE, _domainMinimumScale, _domainMaximumScale); clampScaleChangeToDomainLimits(DEFAULT_AVATAR_SCALE);
if (allowedDefaultScale != DEFAULT_AVATAR_SCALE) {
qCDebug(interfaceapp, "Forcing scale to %f since %f is not an allowed avatar scale by the domain",
allowedDefaultScale, DEFAULT_AVATAR_SCALE);
}
setTargetScale(allowedDefaultScale);
qCDebug(interfaceapp, "Reset scale to %f", (double)_targetScale);
} }
void MyAvatar::restrictScaleFromDomainSettings(const QJsonObject& domainSettingsObject) { void MyAvatar::restrictScaleFromDomainSettings(const QJsonObject& domainSettingsObject) {

View file

@ -372,6 +372,7 @@ private:
virtual void updatePalms() override {} virtual void updatePalms() override {}
void lateUpdatePalms(); void lateUpdatePalms();
void clampScaleChangeToDomainLimits(float desiredScale);
float _driveKeys[MAX_DRIVE_KEYS]; float _driveKeys[MAX_DRIVE_KEYS];
bool _wasPushing; bool _wasPushing;