mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 10:05:44 -04:00
Properly respond to changes in yaw and pitch sent by server. Fix bug with InterpAngle when passing from <90 to >270 degrees.
This commit is contained in:
parent
15ab3d3b3f
commit
c6d797aebc
@ -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 );
|
||||
}
|
||||
|
@ -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 ) {
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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 );
|
||||
}
|
||||
|
@ -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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user