Fixed fast moving items interpolation

This commit is contained in:
Lwmte 2025-03-14 02:42:23 +01:00
parent 66f5f67620
commit 61ca421fb8

View file

@ -451,7 +451,11 @@ namespace TEN::Renderer
// Renderer slot has no interpolation flag set in case it is fetched for first time (e.g. item first time in frustum).
newItem.DisableInterpolation = item.DisableInterpolation || newItem.DisableInterpolation;
if (newItem.DisableInterpolation)
// Disable interpolation when object has traveled significant distance.
// It's needed because when object gets out of frustum, its previous position doesn't update.
bool positionChanged = Vector3::Distance(newItem.PrevPosition, newItem.Position) > BLOCK(1);
if (newItem.DisableInterpolation || positionChanged)
{
// NOTE: Interpolation always returns same result.
newItem.PrevPosition = newItem.Position;
@ -469,12 +473,13 @@ namespace TEN::Renderer
// Force interpolation only for player in player freeze mode.
bool forceValue = g_GameFlow->CurrentFreezeMode == FreezeMode::Player && item.ObjectNumber == ID_LARA;
float interpFactor = GetInterpolationFactor(forceValue);
newItem.InterpolatedPosition = Vector3::Lerp(newItem.PrevPosition, newItem.Position, GetInterpolationFactor(forceValue));
newItem.InterpolatedTranslation = Matrix::Lerp(newItem.PrevTranslation, newItem.Translation, GetInterpolationFactor(forceValue));
newItem.InterpolatedRotation = Matrix::Lerp(newItem.InterpolatedRotation, newItem.Rotation, GetInterpolationFactor(forceValue));
newItem.InterpolatedScale = Matrix::Lerp(newItem.InterpolatedScale, newItem.Scale, GetInterpolationFactor(forceValue));
newItem.InterpolatedWorld = Matrix::Lerp(newItem.PrevWorld, newItem.World, GetInterpolationFactor(forceValue));
newItem.InterpolatedPosition = Vector3::Lerp(newItem.PrevPosition, newItem.Position, interpFactor);
newItem.InterpolatedTranslation = Matrix::Lerp(newItem.PrevTranslation, newItem.Translation, interpFactor);
newItem.InterpolatedRotation = Matrix::Lerp(newItem.InterpolatedRotation, newItem.Rotation, interpFactor);
newItem.InterpolatedScale = Matrix::Lerp(newItem.InterpolatedScale, newItem.Scale, interpFactor);
newItem.InterpolatedWorld = Matrix::Lerp(newItem.PrevWorld, newItem.World, interpFactor);
for (int j = 0; j < MAX_BONES; j++)
newItem.InterpolatedAnimTransforms[j] = Matrix::Lerp(newItem.PrevAnimTransforms[j], newItem.AnimTransforms[j], GetInterpolationFactor(forceValue));