Add option to invert idle behavior (fixes #2379)

Both through separate property and by allowing negative speed factor
This commit is contained in:
Emma Broman
2023-02-27 16:06:15 +01:00
parent b8c27f1fee
commit 3ffb29b9be
2 changed files with 22 additions and 6 deletions

View File

@@ -70,11 +70,12 @@ public:
properties::BoolProperty shouldTriggerWhenIdle;
properties::FloatProperty idleWaitTime;
properties::BoolProperty abortOnCameraInteraction;
properties::FloatProperty speedScale;
properties::BoolProperty invert;
properties::FloatProperty speedScaleFactor;
properties::FloatProperty dampenInterpolationTime;
properties::OptionProperty defaultBehavior;
std::optional<Behavior> chosenBehavior = std::nullopt;
std::optional<Behavior> chosenBehavior;
};
OrbitalNavigator();

View File

@@ -248,7 +248,16 @@ namespace {
"SpeedFactor",
"Speed Factor",
"A factor that can be used to increase or slow down the speed of an applied "
"idle behavior"
"idle behavior. A negative value will invert the direction. Note that a speed "
"of exactly 0 leads to no movement at all"
};
constexpr openspace::properties::Property::PropertyInfo InvertIdleBehaviorInfo = {
"Invert",
"Invert",
"If true, the direction of the idle behavior motion will be inverted compared "
"to the default. For example, the 'Orbit' option rotates to the right per "
"default, and will rotate to the left when inverted"
};
constexpr openspace::properties::Property::PropertyInfo AbortOnCameraInteractionInfo =
@@ -296,7 +305,8 @@ OrbitalNavigator::IdleBehavior::IdleBehavior()
, shouldTriggerWhenIdle(ShouldTriggerIdleBehaviorWhenIdleInfo, false)
, idleWaitTime(IdleWaitTimeInfo, 5.f, 0.f, 3600.f)
, abortOnCameraInteraction(AbortOnCameraInteractionInfo, true)
, speedScale(IdleBehaviorSpeedInfo, 1.f, 0.01f, 5.f)
, invert(InvertIdleBehaviorInfo, false)
, speedScaleFactor(IdleBehaviorSpeedInfo, 1.f, -5.f, 5.f)
, dampenInterpolationTime(IdleBehaviorDampenInterpolationTimeInfo, 0.5f, 0.f, 10.f)
, defaultBehavior(IdleBehaviorInfo)
{
@@ -320,7 +330,8 @@ OrbitalNavigator::IdleBehavior::IdleBehavior()
addProperty(shouldTriggerWhenIdle);
addProperty(idleWaitTime);
idleWaitTime.setExponent(2.2f);
addProperty(speedScale);
addProperty(invert);
addProperty(speedScaleFactor);
addProperty(abortOnCameraInteraction);
addProperty(dampenInterpolationTime);
}
@@ -1650,9 +1661,13 @@ void OrbitalNavigator::applyIdleBehavior(double deltaTime, glm::dvec3& position,
glm::clamp(distFromSurfaceToCamera / distFromCenterToSurface, 0.0, 1.0) :
1.0; // same as horizontal translation
speedScale *= _idleBehavior.speedScale;
speedScale *= _idleBehavior.speedScaleFactor;
speedScale *= 0.05; // without this scaling, the motion is way too fast
if (_idleBehavior.invert) {
speedScale *= -1.0;
}
// Interpolate so that the start and end are smooth
double s = _idleBehaviorDampenInterpolator.value();
speedScale *= _invertIdleBehaviorInterpolation ? (1.0 - s) : s;