From c6d797aebc9eeddbd967413892bd254e4474dbea Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 22 Aug 2015 14:01:12 +1000 Subject: [PATCH] Properly respond to changes in yaw and pitch sent by server. Fix bug with InterpAngle when passing from <90 to >270 degrees. --- ClassicalSharp/Commands/DefaultCommands.cs | 4 ++-- ClassicalSharp/Entities/LocalPlayer.cs | 8 ++++---- ClassicalSharp/Entities/LocationUpdate.cs | 6 ++++-- ClassicalSharp/Utils/Camera.cs | 24 +++++++++------------- ClassicalSharp/Utils/Utils.cs | 4 ++-- OpenTK/Platform/Windows/WinGLNative.cs | 2 +- 6 files changed, 23 insertions(+), 25 deletions(-) diff --git a/ClassicalSharp/Commands/DefaultCommands.cs b/ClassicalSharp/Commands/DefaultCommands.cs index 29f905aaf..c0f535099 100644 --- a/ClassicalSharp/Commands/DefaultCommands.cs +++ b/ClassicalSharp/Commands/DefaultCommands.cs @@ -277,9 +277,9 @@ namespace ClassicalSharp.Commands { if( !reader.NextInt( out newDist ) ) { Window.AddChat( "View distance: " + Window.ViewDistance ); } else if( newDist < 8 ) { - Window.AddChat( "&e/client info: &cThat view distance is way too small." ); + Window.AddChat( "&e/client viewdistance: &cThat view distance is way too small." ); } else if( newDist > 4096 ) { - Window.AddChat( "&e/client info: &cThat view distance is way too large." ); + Window.AddChat( "&e/client viewdistance: &cThat view distance is way too large." ); } else { Window.SetViewDistance( newDist ); } diff --git a/ClassicalSharp/Entities/LocalPlayer.cs b/ClassicalSharp/Entities/LocalPlayer.cs index f0d624372..eb3329c81 100644 --- a/ClassicalSharp/Entities/LocalPlayer.cs +++ b/ClassicalSharp/Entities/LocalPlayer.cs @@ -212,12 +212,12 @@ namespace ClassicalSharp { } } - Vector3 lastPos, nextPos; - float lastYaw, nextYaw, lastPitch, nextPitch; + internal Vector3 lastPos, nextPos; + internal float lastYaw, nextYaw, lastPitch, nextPitch; public void SetInterpPosition( float t ) { Position = Vector3.Lerp( lastPos, nextPos, t ); - YawDegrees = Utils.Lerp( lastYaw, nextYaw, t ); - PitchDegrees = Utils.Lerp( lastPitch, nextPitch, t ); + YawDegrees = Utils.InterpAngle( lastYaw, nextYaw, t ); + PitchDegrees = Utils.InterpAngle( lastPitch, nextPitch, t ); } internal void HandleKeyDown( Key key ) { diff --git a/ClassicalSharp/Entities/LocationUpdate.cs b/ClassicalSharp/Entities/LocationUpdate.cs index ee4f7b75f..4da886e67 100644 --- a/ClassicalSharp/Entities/LocationUpdate.cs +++ b/ClassicalSharp/Entities/LocationUpdate.cs @@ -16,8 +16,10 @@ namespace ClassicalSharp { public LocationUpdate( float x, float y, float z, float yaw, float pitch, bool incPos, bool relPos, bool incOri ) { Pos = new Vector3( x, y, z ); - Yaw = yaw; - Pitch = pitch; + Yaw = yaw % 360; + if( Yaw < 0 ) Yaw += 360; + Pitch = pitch % 360; + if( Pitch < 0 ) Pitch += 360; IncludesPosition = incPos; RelativePosition = relPos; IncludesOrientation = incOri; diff --git a/ClassicalSharp/Utils/Camera.cs b/ClassicalSharp/Utils/Camera.cs index 7fe3980bf..078a8099d 100644 --- a/ClassicalSharp/Utils/Camera.cs +++ b/ClassicalSharp/Utils/Camera.cs @@ -29,7 +29,7 @@ namespace ClassicalSharp { public abstract class PerspectiveCamera : Camera { - protected Player player; + protected LocalPlayer player; public PerspectiveCamera( Game game ) { this.game = game; player = game.LocalPlayer; @@ -49,7 +49,6 @@ namespace ClassicalSharp { } Point previous, delta; - Vector2 Orientation; void CentreMousePosition() { if( !game.Focused ) return; Point current = game.DesktopCursorPos; @@ -70,20 +69,17 @@ namespace ClassicalSharp { delta = Point.Empty; } + static readonly float sensiFactor = (float)Utils.RadiansToDegrees( 0.0002f ); private void UpdateMouseRotation() { - float sensitivity = 0.0002f * game.MouseSensitivity; - Orientation.X += delta.X * sensitivity; - Orientation.Y += delta.Y * sensitivity; - - Utils.Clamp( ref Orientation.Y, halfPi + 0.01f, threeHalfPi - 0.01f ); - LocationUpdate update = LocationUpdate.MakeOri( - (float)Utils.RadiansToDegrees( Orientation.X ), - (float)Utils.RadiansToDegrees( Orientation.Y - Math.PI ) - ); + float sensitivity = sensiFactor * game.MouseSensitivity; + float yaw = player.nextYaw + delta.X * sensitivity; + float pitch = player.nextPitch + delta.Y * sensitivity; + LocationUpdate update = LocationUpdate.MakeOri( yaw, pitch ); + // Need to make sure we don't cross the vertical axes, because that gets weird. + if( update.Pitch >= 90 && update.Pitch <= 270 ) + update.Pitch = player.nextPitch < 180 ? 89.9f : 270.1f; game.LocalPlayer.SetLocation( update, true ); } - const float halfPi = (float)( Math.PI / 2 ); - const float threeHalfPi = (float)( 3 * Math.PI / 2 ); public override void Tick( double elapsed ) { if( game.ScreenLockedInput ) return; @@ -97,7 +93,7 @@ namespace ClassicalSharp { public ThirdPersonCamera( Game window ) : base( window ) { } - float distance = 3; + float distance = 3; public override bool MouseZoom( MouseWheelEventArgs e ) { distance -= e.DeltaPrecise; if( distance < 2 ) distance = 2; diff --git a/ClassicalSharp/Utils/Utils.cs b/ClassicalSharp/Utils/Utils.cs index a542c9222..8ccf32b9c 100644 --- a/ClassicalSharp/Utils/Utils.cs +++ b/ClassicalSharp/Utils/Utils.cs @@ -218,8 +218,8 @@ namespace ClassicalSharp { // but without adjusting for this case, we would interpolate back the whole 350* degrees. bool invertLeft = leftAngle > 270 && rightAngle < 90; bool invertRight = rightAngle > 270 && leftAngle < 90; - if( invertLeft ) leftAngle = 360 - leftAngle; - if( invertRight ) rightAngle = 360 - rightAngle; + if( invertLeft ) leftAngle = leftAngle - 360; + if( invertRight ) rightAngle = rightAngle - 360; return Lerp( leftAngle, rightAngle, t ); } diff --git a/OpenTK/Platform/Windows/WinGLNative.cs b/OpenTK/Platform/Windows/WinGLNative.cs index b8400113a..cf30bf0c4 100644 --- a/OpenTK/Platform/Windows/WinGLNative.cs +++ b/OpenTK/Platform/Windows/WinGLNative.cs @@ -575,7 +575,7 @@ namespace OpenTK.Platform.Windows get { sb_title.Remove(0, sb_title.Length); if (API.GetWindowText(window.WindowHandle, sb_title, sb_title.MaxCapacity) == 0) - Debug.Print("Failed to retrieve window title (window:{0}, reason:{2}).", window.WindowHandle, Marshal.GetLastWin32Error()); + Debug.Print("Failed to retrieve window title (window:{0}, reason:{1}).", window.WindowHandle, Marshal.GetLastWin32Error()); return sb_title.ToString(); } set { if (!API.SetWindowText(window.WindowHandle, value))