mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-23 09:34:35 -05:00
Don't apply fall tilting when flying or noclip mode.
This commit is contained in:
parent
513e330337
commit
6fe8991f33
2 changed files with 68 additions and 72 deletions
|
@ -17,7 +17,7 @@ namespace ClassicalSharp.Entities {
|
|||
|
||||
public float legXRot, armXRot, armZRot;
|
||||
public float bobbingHor, bobbingVer, tiltX, tiltY;
|
||||
public float walkTime, swing, intensity = 1;
|
||||
public float walkTime, swing, bobStrength = 1;
|
||||
|
||||
internal float walkTimeO, walkTimeN, swingO, swingN;
|
||||
internal float leftXRot, leftZRot, rightXRot, rightZRot;
|
||||
|
@ -63,10 +63,10 @@ namespace ClassicalSharp.Entities {
|
|||
bobbingVer = (float)(Math.Abs( Math.Sin( walkTime ) ) * swing * (2.5f/16f));
|
||||
|
||||
if( !game.ViewBobbing || !entity.onGround )
|
||||
intensity *= 0.9f;
|
||||
bobStrength *= 0.9f;
|
||||
else
|
||||
intensity += 0.1f;
|
||||
Utils.Clamp( ref intensity, 0, 1 );
|
||||
bobStrength += 0.1f;
|
||||
Utils.Clamp( ref bobStrength, 0, 1 );
|
||||
|
||||
tiltX = (float)Math.Cos( walkTime ) * swing * (0.15f * Utils.Deg2Rad);
|
||||
tiltY = (float)Math.Sin( walkTime ) * swing * (0.15f * Utils.Deg2Rad);
|
||||
|
|
|
@ -4,38 +4,38 @@ using System.Drawing;
|
|||
using ClassicalSharp.Entities;
|
||||
using OpenTK;
|
||||
using OpenTK.Input;
|
||||
|
||||
|
||||
namespace ClassicalSharp {
|
||||
|
||||
|
||||
public abstract class Camera {
|
||||
protected Game game;
|
||||
internal Matrix4 tiltM;
|
||||
internal float bobbingVer, bobbingHor;
|
||||
|
||||
internal Matrix4 tiltM;
|
||||
internal float bobbingVer, bobbingHor;
|
||||
|
||||
public abstract Matrix4 GetProjection();
|
||||
|
||||
|
||||
public abstract Matrix4 GetView( double delta, float t );
|
||||
|
||||
|
||||
/// <summary> Calculates the location of the camera's position in the world
|
||||
/// based on the entity's eye position. </summary>
|
||||
public abstract Vector3 GetCameraPos( Vector3 eyePos );
|
||||
|
||||
|
||||
/// <summary> Calculates the yaw and pitch of the camera in radians. </summary>
|
||||
public abstract Vector2 GetCameraOrientation();
|
||||
|
||||
|
||||
/// <summary> Whether this camera is using a third person perspective. </summary>
|
||||
/// <remarks> This causes the local player to be renderered if true. </remarks>
|
||||
public abstract bool IsThirdPerson { get; }
|
||||
|
||||
|
||||
public virtual void Tick( double elapsed ) { }
|
||||
|
||||
|
||||
public virtual bool DoZoom( float deltaPrecise ) { return false; }
|
||||
|
||||
|
||||
public abstract void RegrabMouse();
|
||||
|
||||
|
||||
/// <summary> Calculates the picked block based on the camera's current position. </summary>
|
||||
public virtual void GetPickedBlock( PickedPos pos ) { }
|
||||
|
||||
|
||||
protected float AdjustPitch( float value ) {
|
||||
if( value >= 90.0f && value <= 90.1f ) return 90.1f * Utils.Deg2Rad;
|
||||
if( value >= 89.9f && value <= 90.0f ) return 89.9f * Utils.Deg2Rad;
|
||||
|
@ -44,31 +44,31 @@ namespace ClassicalSharp {
|
|||
return value * Utils.Deg2Rad;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public abstract class PerspectiveCamera : Camera {
|
||||
|
||||
|
||||
protected LocalPlayer player;
|
||||
public PerspectiveCamera( Game game ) {
|
||||
this.game = game;
|
||||
player = game.LocalPlayer;
|
||||
tiltM = Matrix4.Identity;
|
||||
}
|
||||
|
||||
|
||||
public override Matrix4 GetProjection() {
|
||||
float fovy = game.Fov * Utils.Deg2Rad;
|
||||
float aspectRatio = (float)game.Width / game.Height;
|
||||
float zNear = game.Graphics.MinZNear;
|
||||
return Matrix4.CreatePerspectiveFieldOfView( fovy, aspectRatio, zNear, game.ViewDistance );
|
||||
}
|
||||
|
||||
|
||||
public override void GetPickedBlock( PickedPos pos ) {
|
||||
Vector3 dir = Utils.GetDirVector( player.HeadYawRadians,
|
||||
AdjustPitch( player.PitchDegrees ) );
|
||||
AdjustPitch( player.PitchDegrees ) );
|
||||
Vector3 eyePos = player.EyePosition;
|
||||
float reach = game.LocalPlayer.ReachDistance;
|
||||
Picking.CalculatePickedBlock( game, eyePos, dir, reach, pos );
|
||||
}
|
||||
|
||||
|
||||
internal Point previous, delta;
|
||||
void CentreMousePosition() {
|
||||
if( !game.Focused ) return;
|
||||
|
@ -81,7 +81,7 @@ namespace ClassicalSharp {
|
|||
// Fixes issues with large DPI displays on Windows >= 8.0.
|
||||
previous = game.DesktopCursorPos;
|
||||
}
|
||||
|
||||
|
||||
public override void RegrabMouse() {
|
||||
if( !game.Exists ) return;
|
||||
Point topLeft = game.PointToScreen( Point.Empty );
|
||||
|
@ -91,7 +91,7 @@ namespace ClassicalSharp {
|
|||
previous = new Point( cenX, cenY );
|
||||
delta = Point.Empty;
|
||||
}
|
||||
|
||||
|
||||
static readonly float sensiFactor = 0.0002f / 3 * Utils.Rad2Deg;
|
||||
private void UpdateMouseRotation() {
|
||||
float sensitivity = sensiFactor * game.MouseSensitivity;
|
||||
|
@ -99,136 +99,132 @@ namespace ClassicalSharp {
|
|||
float yAdj = game.InvertMouse ? -delta.Y * sensitivity : delta.Y * sensitivity;
|
||||
float pitch = player.nextPitch + yAdj;
|
||||
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 );
|
||||
}
|
||||
|
||||
|
||||
public override void Tick( double elapsed ) {
|
||||
if( game.ActiveScreen.HandlesAllInput ) return;
|
||||
CentreMousePosition();
|
||||
UpdateMouseRotation();
|
||||
}
|
||||
|
||||
protected void CalcVelocityTilt(double delta, float t) {
|
||||
|
||||
protected void CalcViewBobbing( double delta, float t, bool velTilt ) {
|
||||
LocalPlayer p = game.LocalPlayer;
|
||||
float tiltAmount = (-p.Velocity.Y - 0.08F);
|
||||
float tiltAmount2 = 0;
|
||||
tiltAmount2 = Utils.Lerp(p.OldVelocity.Y, player.Velocity.Y, t);
|
||||
tiltM = Matrix4.RotateZ( -p.anim.tiltX * p.anim.bobStrength );
|
||||
tiltM = tiltM * Matrix4.RotateX( Math.Abs( p.anim.tiltY ) * 3 * p.anim.bobStrength );
|
||||
|
||||
tiltM = tiltM * Matrix4.RotateX( (float)(-tiltAmount2 * 0.05F) );
|
||||
}
|
||||
protected void CalcViewBobbing( double delta ) {
|
||||
LocalPlayer p = game.LocalPlayer;
|
||||
tiltM = Matrix4.RotateZ( -p.anim.tiltX * p.anim.intensity );
|
||||
tiltM = tiltM * Matrix4.RotateX( Math.Abs( p.anim.tiltY ) * 3 * p.anim.intensity );
|
||||
|
||||
bobbingHor = (p.anim.bobbingHor * 0.3f) * p.anim.intensity;
|
||||
bobbingVer = (p.anim.bobbingVer * 0.6f) * p.anim.intensity;
|
||||
bobbingHor = (p.anim.bobbingHor * 0.3f) * p.anim.bobStrength;
|
||||
bobbingVer = (p.anim.bobbingVer * 0.6f) * p.anim.bobStrength;
|
||||
|
||||
if( !velTilt || p.Hacks.Noclip || p.Hacks.Flying ) return;
|
||||
float vel = Utils.Lerp( p.OldVelocity.Y + 0.08f, p.Velocity.Y + 0.08f, t );
|
||||
Utils.Clamp( ref vel, -1, 1 );
|
||||
tiltM = tiltM * Matrix4.RotateX( -vel * 0.05f );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class ThirdPersonCamera : PerspectiveCamera {
|
||||
|
||||
|
||||
public ThirdPersonCamera( Game window ) : base( window ) {
|
||||
}
|
||||
|
||||
|
||||
public override Vector2 GetCameraOrientation() {
|
||||
return new Vector2( player.HeadYawRadians, player.PitchRadians );
|
||||
}
|
||||
|
||||
|
||||
float dist = 3;
|
||||
public override bool DoZoom( float deltaPrecise ) {
|
||||
dist = Math.Max( dist - deltaPrecise, 2 );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public override Matrix4 GetView( double delta, float t ) {
|
||||
CalcViewBobbing( delta );
|
||||
CalcViewBobbing( delta, t, false );
|
||||
Vector3 eyePos = player.EyePosition;
|
||||
eyePos.Y += bobbingVer;
|
||||
|
||||
|
||||
Vector3 dir = -Utils.GetDirVector( player.HeadYawRadians,
|
||||
AdjustPitch( player.PitchDegrees ) );
|
||||
AdjustPitch( player.PitchDegrees ) );
|
||||
Picking.ClipCameraPos( game, eyePos, dir, dist, game.CameraClipPos );
|
||||
Vector3 cameraPos = game.CameraClipPos.IntersectPoint;
|
||||
return Matrix4.LookAt( cameraPos, eyePos, Vector3.UnitY ) * tiltM;
|
||||
}
|
||||
|
||||
|
||||
public override bool IsThirdPerson { get { return true; } }
|
||||
|
||||
|
||||
public override Vector3 GetCameraPos( Vector3 eyePos ) {
|
||||
Vector3 dir = -Utils.GetDirVector( player.HeadYawRadians,
|
||||
AdjustPitch( player.PitchDegrees ) );
|
||||
AdjustPitch( player.PitchDegrees ) );
|
||||
Picking.ClipCameraPos( game, eyePos, dir, dist, game.CameraClipPos );
|
||||
return game.CameraClipPos.IntersectPoint;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class ForwardThirdPersonCamera : PerspectiveCamera {
|
||||
|
||||
|
||||
public ForwardThirdPersonCamera( Game window ) : base( window ) {
|
||||
}
|
||||
|
||||
|
||||
public override Vector2 GetCameraOrientation() {
|
||||
return new Vector2( player.HeadYawRadians, -player.PitchRadians );
|
||||
}
|
||||
|
||||
|
||||
float dist = 3;
|
||||
public override bool DoZoom( float deltaPrecise ) {
|
||||
dist = Math.Max( dist - deltaPrecise, 2 );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public override Matrix4 GetView( double delta, float t ) {
|
||||
CalcViewBobbing( delta );
|
||||
CalcViewBobbing( delta, t, false );
|
||||
Vector3 eyePos = player.EyePosition;
|
||||
eyePos.Y += bobbingVer;
|
||||
|
||||
Vector3 dir = Utils.GetDirVector( player.HeadYawRadians,
|
||||
AdjustPitch( player.PitchDegrees ) );
|
||||
AdjustPitch( player.PitchDegrees ) );
|
||||
Picking.ClipCameraPos( game, eyePos, dir, dist, game.CameraClipPos );
|
||||
Vector3 cameraPos = game.CameraClipPos.IntersectPoint;
|
||||
return Matrix4.LookAt( cameraPos, eyePos, Vector3.UnitY ) * tiltM;
|
||||
}
|
||||
|
||||
|
||||
public override bool IsThirdPerson { get { return true; } }
|
||||
|
||||
|
||||
public override Vector3 GetCameraPos( Vector3 eyePos ) {
|
||||
Vector3 dir = Utils.GetDirVector( player.HeadYawRadians,
|
||||
AdjustPitch( player.PitchDegrees ) );
|
||||
AdjustPitch( player.PitchDegrees ) );
|
||||
Picking.ClipCameraPos( game, eyePos, dir, dist, game.CameraClipPos );
|
||||
return game.CameraClipPos.IntersectPoint;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class FirstPersonCamera : PerspectiveCamera {
|
||||
|
||||
|
||||
public FirstPersonCamera( Game window ) : base( window ) {
|
||||
}
|
||||
|
||||
|
||||
public override Vector2 GetCameraOrientation() {
|
||||
return new Vector2( player.HeadYawRadians, player.PitchRadians );
|
||||
}
|
||||
|
||||
|
||||
public override Matrix4 GetView( double delta, float t ) {
|
||||
CalcViewBobbing( delta );
|
||||
CalcVelocityTilt( delta, t );
|
||||
CalcViewBobbing( delta, t, true );
|
||||
Vector3 eyePos = player.EyePosition;
|
||||
eyePos.Y += bobbingVer;
|
||||
Vector3 cameraDir = Utils.GetDirVector( player.HeadYawRadians,
|
||||
AdjustPitch( player.PitchDegrees ) );
|
||||
AdjustPitch( player.PitchDegrees ) );
|
||||
|
||||
double adjYaw = player.HeadYawRadians + Math.PI / 2;
|
||||
eyePos.X += bobbingHor * (float)Math.Sin( adjYaw );
|
||||
eyePos.Z -= bobbingHor * (float)Math.Cos( adjYaw );
|
||||
return Matrix4.LookAt( eyePos, eyePos + cameraDir, Vector3.UnitY ) * tiltM;
|
||||
}
|
||||
|
||||
|
||||
public override bool IsThirdPerson { get { return false; } }
|
||||
|
||||
|
||||
public override Vector3 GetCameraPos( Vector3 eyePos ) {
|
||||
return eyePos;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue