From 9cb4114ccfb4cc120be76edbade84c47a3c7ffbd Mon Sep 17 00:00:00 2001 From: Ricardo Matias Date: Fri, 22 May 2020 20:10:41 +0200 Subject: [PATCH] Fix attack/decay interpolation (#114) --- .../src/main/kotlin/Envelope.kt | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/orx-time-operators/src/main/kotlin/Envelope.kt b/orx-time-operators/src/main/kotlin/Envelope.kt index efe51d9d..7011cd2e 100644 --- a/orx-time-operators/src/main/kotlin/Envelope.kt +++ b/orx-time-operators/src/main/kotlin/Envelope.kt @@ -95,27 +95,19 @@ class Envelope( } if (phase == EnvelopePhase.Attack) { - current = if (attack == 0.0) { - targetValue - } else { - val t = clamp(cycleTime / attack, 0.0, 1.0) + val denom = if (attack == 0.0) 1.0 else attack - mix(restValue, targetValue, exponentialEasing(t, easingFactor)) - } + val t = clamp(cycleTime / denom, 0.0, 1.0) + + current = mix(restValue, targetValue, exponentialEasing(t, easingFactor)) } if (phase == EnvelopePhase.Decay) { - current = if (decay == 0.0) { - initialRestValue - } else { - val t = clamp((cycleTime - attack) / decay, 0.0, 1.0) + val denom = if (decay == 0.0) 1.0 else decay - mix(targetValue, initialRestValue, exponentialEasing(t, easingFactor)) - } - } + val t = clamp((cycleTime - attack) / denom, 0.0, 1.0) - if (current.isNaN()) { - println("current is NaN, $phase") + current = mix(targetValue, initialRestValue, exponentialEasing(t, easingFactor)) } }