mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 18:15:28 -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 ) ) {
|
if( !reader.NextInt( out newDist ) ) {
|
||||||
Window.AddChat( "View distance: " + Window.ViewDistance );
|
Window.AddChat( "View distance: " + Window.ViewDistance );
|
||||||
} else if( newDist < 8 ) {
|
} 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 ) {
|
} 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 {
|
} else {
|
||||||
Window.SetViewDistance( newDist );
|
Window.SetViewDistance( newDist );
|
||||||
}
|
}
|
||||||
|
@ -212,12 +212,12 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 lastPos, nextPos;
|
internal Vector3 lastPos, nextPos;
|
||||||
float lastYaw, nextYaw, lastPitch, nextPitch;
|
internal float lastYaw, nextYaw, lastPitch, nextPitch;
|
||||||
public void SetInterpPosition( float t ) {
|
public void SetInterpPosition( float t ) {
|
||||||
Position = Vector3.Lerp( lastPos, nextPos, t );
|
Position = Vector3.Lerp( lastPos, nextPos, t );
|
||||||
YawDegrees = Utils.Lerp( lastYaw, nextYaw, t );
|
YawDegrees = Utils.InterpAngle( lastYaw, nextYaw, t );
|
||||||
PitchDegrees = Utils.Lerp( lastPitch, nextPitch, t );
|
PitchDegrees = Utils.InterpAngle( lastPitch, nextPitch, t );
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void HandleKeyDown( Key key ) {
|
internal void HandleKeyDown( Key key ) {
|
||||||
|
@ -16,8 +16,10 @@ namespace ClassicalSharp {
|
|||||||
public LocationUpdate( float x, float y, float z, float yaw, float pitch,
|
public LocationUpdate( float x, float y, float z, float yaw, float pitch,
|
||||||
bool incPos, bool relPos, bool incOri ) {
|
bool incPos, bool relPos, bool incOri ) {
|
||||||
Pos = new Vector3( x, y, z );
|
Pos = new Vector3( x, y, z );
|
||||||
Yaw = yaw;
|
Yaw = yaw % 360;
|
||||||
Pitch = pitch;
|
if( Yaw < 0 ) Yaw += 360;
|
||||||
|
Pitch = pitch % 360;
|
||||||
|
if( Pitch < 0 ) Pitch += 360;
|
||||||
IncludesPosition = incPos;
|
IncludesPosition = incPos;
|
||||||
RelativePosition = relPos;
|
RelativePosition = relPos;
|
||||||
IncludesOrientation = incOri;
|
IncludesOrientation = incOri;
|
||||||
|
@ -29,7 +29,7 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
public abstract class PerspectiveCamera : Camera {
|
public abstract class PerspectiveCamera : Camera {
|
||||||
|
|
||||||
protected Player player;
|
protected LocalPlayer player;
|
||||||
public PerspectiveCamera( Game game ) {
|
public PerspectiveCamera( Game game ) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
player = game.LocalPlayer;
|
player = game.LocalPlayer;
|
||||||
@ -49,7 +49,6 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Point previous, delta;
|
Point previous, delta;
|
||||||
Vector2 Orientation;
|
|
||||||
void CentreMousePosition() {
|
void CentreMousePosition() {
|
||||||
if( !game.Focused ) return;
|
if( !game.Focused ) return;
|
||||||
Point current = game.DesktopCursorPos;
|
Point current = game.DesktopCursorPos;
|
||||||
@ -70,20 +69,17 @@ namespace ClassicalSharp {
|
|||||||
delta = Point.Empty;
|
delta = Point.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static readonly float sensiFactor = (float)Utils.RadiansToDegrees( 0.0002f );
|
||||||
private void UpdateMouseRotation() {
|
private void UpdateMouseRotation() {
|
||||||
float sensitivity = 0.0002f * game.MouseSensitivity;
|
float sensitivity = sensiFactor * game.MouseSensitivity;
|
||||||
Orientation.X += delta.X * sensitivity;
|
float yaw = player.nextYaw + delta.X * sensitivity;
|
||||||
Orientation.Y += delta.Y * sensitivity;
|
float pitch = player.nextPitch + delta.Y * sensitivity;
|
||||||
|
LocationUpdate update = LocationUpdate.MakeOri( yaw, pitch );
|
||||||
Utils.Clamp( ref Orientation.Y, halfPi + 0.01f, threeHalfPi - 0.01f );
|
// Need to make sure we don't cross the vertical axes, because that gets weird.
|
||||||
LocationUpdate update = LocationUpdate.MakeOri(
|
if( update.Pitch >= 90 && update.Pitch <= 270 )
|
||||||
(float)Utils.RadiansToDegrees( Orientation.X ),
|
update.Pitch = player.nextPitch < 180 ? 89.9f : 270.1f;
|
||||||
(float)Utils.RadiansToDegrees( Orientation.Y - Math.PI )
|
|
||||||
);
|
|
||||||
game.LocalPlayer.SetLocation( update, true );
|
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 ) {
|
public override void Tick( double elapsed ) {
|
||||||
if( game.ScreenLockedInput ) return;
|
if( game.ScreenLockedInput ) return;
|
||||||
|
@ -218,8 +218,8 @@ namespace ClassicalSharp {
|
|||||||
// but without adjusting for this case, we would interpolate back the whole 350* degrees.
|
// but without adjusting for this case, we would interpolate back the whole 350* degrees.
|
||||||
bool invertLeft = leftAngle > 270 && rightAngle < 90;
|
bool invertLeft = leftAngle > 270 && rightAngle < 90;
|
||||||
bool invertRight = rightAngle > 270 && leftAngle < 90;
|
bool invertRight = rightAngle > 270 && leftAngle < 90;
|
||||||
if( invertLeft ) leftAngle = 360 - leftAngle;
|
if( invertLeft ) leftAngle = leftAngle - 360;
|
||||||
if( invertRight ) rightAngle = 360 - rightAngle;
|
if( invertRight ) rightAngle = rightAngle - 360;
|
||||||
|
|
||||||
return Lerp( leftAngle, rightAngle, t );
|
return Lerp( leftAngle, rightAngle, t );
|
||||||
}
|
}
|
||||||
|
@ -575,7 +575,7 @@ namespace OpenTK.Platform.Windows
|
|||||||
get {
|
get {
|
||||||
sb_title.Remove(0, sb_title.Length);
|
sb_title.Remove(0, sb_title.Length);
|
||||||
if (API.GetWindowText(window.WindowHandle, sb_title, sb_title.MaxCapacity) == 0)
|
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();
|
return sb_title.ToString();
|
||||||
} set {
|
} set {
|
||||||
if (!API.SetWindowText(window.WindowHandle, value))
|
if (!API.SetWindowText(window.WindowHandle, value))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user