avoid NaN input for MyAvatar's scripted motor

This commit is contained in:
Andrew Meadows 2019-07-18 10:58:41 -07:00
parent d1199f9e1d
commit dcf3df68f2

View file

@ -2751,19 +2751,23 @@ QString MyAvatar::getScriptedMotorMode() const {
} }
void MyAvatar::setScriptedMotorVelocity(const glm::vec3& velocity) { void MyAvatar::setScriptedMotorVelocity(const glm::vec3& velocity) {
float MAX_SCRIPTED_MOTOR_SPEED = 500.0f; float newSpeed = glm::length(velocity);
_scriptedMotorVelocity = velocity; if (!glm::isnan(newSpeed)) {
float speed = glm::length(_scriptedMotorVelocity); _scriptedMotorVelocity = velocity;
if (speed > MAX_SCRIPTED_MOTOR_SPEED) { constexpr float MAX_SCRIPTED_MOTOR_SPEED = 500.0f;
_scriptedMotorVelocity *= MAX_SCRIPTED_MOTOR_SPEED / speed; if (newSpeed > MAX_SCRIPTED_MOTOR_SPEED) {
_scriptedMotorVelocity *= MAX_SCRIPTED_MOTOR_SPEED / newSpeed;
}
} }
} }
void MyAvatar::setScriptedMotorTimescale(float timescale) { void MyAvatar::setScriptedMotorTimescale(float timescale) {
// we clamp the timescale on the large side (instead of just the low side) to prevent if (!glm::isnan(timescale)) {
// obnoxiously large values from introducing NaN into avatar's velocity // we clamp the timescale on the large side (instead of just the low side) to prevent
_scriptedMotorTimescale = glm::clamp(timescale, MIN_SCRIPTED_MOTOR_TIMESCALE, // obnoxiously large values from introducing NaN into avatar's velocity
DEFAULT_SCRIPTED_MOTOR_TIMESCALE); _scriptedMotorTimescale = glm::clamp(timescale, MIN_SCRIPTED_MOTOR_TIMESCALE,
DEFAULT_SCRIPTED_MOTOR_TIMESCALE);
}
} }
void MyAvatar::setScriptedMotorFrame(QString frame) { void MyAvatar::setScriptedMotorFrame(QString frame) {