From 0757368e60595ed7a93ae7959b73d8c2a5c58b32 Mon Sep 17 00:00:00 2001 From: Ryan Friedman Date: Sat, 27 Jan 2024 16:24:59 -0700 Subject: [PATCH] Fix regression with default value * Infinite rate would crash, now it has special handling Signed-off-by: Ryan Friedman --- src/CameraZoomPlugin.cc | 46 ++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/src/CameraZoomPlugin.cc b/src/CameraZoomPlugin.cc index 944a8d1d..5e6958c3 100644 --- a/src/CameraZoomPlugin.cc +++ b/src/CameraZoomPlugin.cc @@ -440,36 +440,44 @@ void CameraZoomPlugin::PreUpdate( std::numeric_limits::epsilon()) return; - // This is the amount of time passed since the last update. - const auto dt = _info.dt; - // How many meters the focal length could change per update loop - const auto maxFocalLengthChange = this->impl->slewRate * - std::chrono::duration(dt).count(); const auto curFocalLength = cameraSdf->LensFocalLength(); // This value should be static every iteration. const auto sensorWidth = CameraZoomPlugin::Impl::SensorWidth( - curFocalLength, oldHfov); - + curFocalLength, oldHfov); const auto goalFocalLength = CameraZoomPlugin::Impl::FovToFocalLength( - sensorWidth, this->impl->goalHfov); - // How many meters the focal length should change this iteration - const auto deltaFL = std::min(maxFocalLengthChange, - std::abs(curFocalLength - goalFocalLength)); + sensorWidth, this->impl->goalHfov); - // Update rendering camera with the latest focal length. double newFocalLength; - if (goalFocalLength > curFocalLength) - { - newFocalLength = curFocalLength + deltaFL; - } - else - { - newFocalLength = curFocalLength - deltaFL; + if (std::isfinite(this->impl->slewRate)) { + // This is the amount of time passed since the last update. + const auto dt = _info.dt; + // How many meters the focal length could change per update loop + const auto maxFocalLengthChange = this->impl->slewRate * + std::chrono::duration(dt).count(); + + + + // How many meters the focal length should change this iteration + const auto deltaFL = std::min(maxFocalLengthChange, + std::abs(curFocalLength - goalFocalLength)); + + if (goalFocalLength > curFocalLength) + { + newFocalLength = curFocalLength + deltaFL; + } + else + { + newFocalLength = curFocalLength - deltaFL; + } + } else { + newFocalLength = goalFocalLength; } + const auto newHfov = CameraZoomPlugin::Impl::FocalLengthToFov( sensorWidth, newFocalLength); + // Update rendering camera with the latest focal length. cameraSdf->SetHorizontalFov(newHfov); _ecm.SetChanged(cameraEntity, components::Camera::typeId, ComponentState::OneTimeChange);