From b673944a614baa276bca5bde46ec0bcd2d36ad28 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 14 Feb 2015 09:01:04 +1100 Subject: [PATCH] Simplify local player interpolation. --- Entities/LocalPlayer.cs | 17 +++-------------- Game/Game.cs | 6 +++--- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/Entities/LocalPlayer.cs b/Entities/LocalPlayer.cs index 44c26b39a..368d0bde0 100644 --- a/Entities/LocalPlayer.cs +++ b/Entities/LocalPlayer.cs @@ -291,20 +291,9 @@ namespace ClassicalSharp { Vector3 lastPos, nextPos; float lastYaw, nextYaw, lastPitch, nextPitch; public void SetInterpPosition( float t ) { - // The first two cases shouldn't happen, but just in case.. - if( t < 0 ) { - Position = lastPos; - YawDegrees = lastYaw; - PitchDegrees = lastPitch; - } else if( t > 1 ) { - Position = nextPos; - YawDegrees = nextYaw; - PitchRadians = nextPitch; - } else { - Position = Vector3.Lerp( lastPos, nextPos, t ); - YawDegrees = Utils.Lerp( lastYaw, nextYaw, t ); - PitchDegrees = Utils.Lerp( lastPitch, nextPitch, t ); - } + Position = Vector3.Lerp( lastPos, nextPos, t ); + YawDegrees = Utils.Lerp( lastYaw, nextYaw, t ); + PitchDegrees = Utils.Lerp( lastPitch, nextPitch, t ); } int tickCount = 0; diff --git a/Game/Game.cs b/Game/Game.cs index 94fe213f7..61ca33046 100644 --- a/Game/Game.cs +++ b/Game/Game.cs @@ -234,7 +234,8 @@ namespace ClassicalSharp { if( ticksThisFrame > ticksFrequency / 3 ) { Utils.LogWarning( "Falling behind (did {0} ticks this frame)", ticksThisFrame ); } - LocalPlayer.SetInterpPosition( (float)( ticksAccumulator / ticksPeriod ) ); + float t = (float)( ticksAccumulator / ticksPeriod ); + LocalPlayer.SetInterpPosition( t ); Graphics.Clear(); Graphics.SetMatrixMode( MatrixType.Modelview ); @@ -245,8 +246,7 @@ namespace ClassicalSharp { bool visible = activeScreen == null || !activeScreen.BlocksWorld; if( visible ) { - //EnvRenderer.EnableAmbientLighting(); - float t = (float)( ticksAccumulator / ticksPeriod ); + //EnvRenderer.EnableAmbientLighting(); RenderPlayers( e.Time, t ); ParticleManager.Render( e.Time, t ); SelectedPos = Camera.GetPickedPos(); // TODO: only pick when necessary