From fce6f8792b966adfac366f3d7b9ada6e7ec0651f Mon Sep 17 00:00:00 2001 From: Thomas Weber Date: Sun, 28 Feb 2021 19:34:14 -0600 Subject: [PATCH] Further tune interpolation heuristic The interpolator is now generally more willing to interpolate movement. --- src/engine/tw-interpolate.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/engine/tw-interpolate.js b/src/engine/tw-interpolate.js index c065f7bf..d31fd1ea 100644 --- a/src/engine/tw-interpolate.js +++ b/src/engine/tw-interpolate.js @@ -64,14 +64,12 @@ const interpolate = (runtime, time) => { const absoluteYDistance = Math.abs(yDistance); if (absoluteXDistance > 0.1 || absoluteYDistance > 0.1) { const drawable = renderer._allDrawables[drawableID]; + // Large movements are likely intended to be instantaneous. // getAABB is less accurate than getBounds, but it's much faster const bounds = drawable.getAABB(); - - const xTolerance = Math.min(50, 10 + bounds.width); - const yTolerance = Math.min(50, 10 + bounds.height); - - // Large movements are likely intended to be instantaneous. - if (absoluteXDistance < xTolerance && absoluteYDistance < yTolerance) { + const tolerance = Math.min(240, Math.max(50, 1.5 * (bounds.width + bounds.height))); + const distance = Math.sqrt((absoluteXDistance ** 2) + (absoluteYDistance ** 2)); + if (distance < tolerance) { const newX = interpolationData.x + (xDistance * time); const newY = interpolationData.y + (yDistance * time); renderer.updateDrawablePosition(drawableID, [newX, newY]);