Rewrite player animations.

This commit is contained in:
UnknownShadow200 2015-02-14 08:53:38 +11:00
parent b5af44396f
commit 39e67a182e
3 changed files with 33 additions and 25 deletions

View File

@ -321,7 +321,7 @@ namespace ClassicalSharp {
PhysicsTick( xMoving, zMoving ); PhysicsTick( xMoving, zMoving );
nextPos = Position; nextPos = Position;
Position = lastPos; Position = lastPos;
UpdateAnimState( lastPos, nextPos ); UpdateAnimState( lastPos, nextPos, delta );
tickCount++; tickCount++;
if( renderer != null ) { if( renderer != null ) {
Bitmap bmp; Bitmap bmp;
@ -341,7 +341,7 @@ namespace ClassicalSharp {
renderer = new PlayerRenderer( this, Window ); renderer = new PlayerRenderer( this, Window );
Window.AsyncDownloader.DownloadSkin( SkinName ); Window.AsyncDownloader.DownloadSkin( SkinName );
} }
SetCurrentAnimState( tickCount, t ); SetCurrentAnimState( t );
renderer.Render( deltaTime ); renderer.Render( deltaTime );
} }

View File

@ -74,7 +74,7 @@ namespace ClassicalSharp {
} }
tickCount++; tickCount++;
UpdateCurrentState(); UpdateCurrentState();
UpdateAnimState( oldState.pos, newState.pos ); UpdateAnimState( oldState.pos, newState.pos, delta );
} }
void UpdateCurrentState() { void UpdateCurrentState() {
@ -95,7 +95,7 @@ namespace ClassicalSharp {
YawDegrees = Utils.InterpAngle( oldState.yaw, newState.yaw, t ); YawDegrees = Utils.InterpAngle( oldState.yaw, newState.yaw, t );
PitchDegrees = Utils.InterpAngle( oldState.pitch, newState.pitch, t ); PitchDegrees = Utils.InterpAngle( oldState.pitch, newState.pitch, t );
SetCurrentAnimState( tickCount, t ); SetCurrentAnimState( t );
renderer.Render( deltaTime ); renderer.Render( deltaTime );
} }
} }

View File

@ -66,36 +66,44 @@ namespace ClassicalSharp {
public float leftLegXRot, leftArmXRot, leftArmZRot; public float leftLegXRot, leftArmXRot, leftArmZRot;
public float rightLegXRot, rightArmXRot, rightArmZRot; public float rightLegXRot, rightArmXRot, rightArmZRot;
protected float animStepO, animStepN, runO, runN; protected float walkTimeO, walkTimeN, swingO, swingN;
protected void UpdateAnimState( Vector3 oldPos, Vector3 newPos ) { protected void UpdateAnimState( Vector3 oldPos, Vector3 newPos, double delta ) {
animStepO = animStepN; walkTimeO = walkTimeN;
runO = runN; swingO = swingN;
float dx = newPos.X - oldPos.X; float dx = newPos.X - oldPos.X;
float dz = newPos.Z - oldPos.Z; float dz = newPos.Z - oldPos.Z;
double distance = Math.Sqrt( dx * dx + dz * dz ); double distance = Math.Sqrt( dx * dx + dz * dz );
float animSpeed = distance > 0.05 ? (float)distance * 3 : 0; bool moves = distance > 0.05;
float runDist = distance > 0.05 ? 1 : 0;
runN += ( runDist - runN ) * 0.3f; if( moves ) {
animStepN += animSpeed; walkTimeN += (float)distance * 2 * (float)( 20 * delta );
swingN += (float)delta * 3;
if( swingN > 1 ) swingN = 1;
} else {
swingN -= (float)delta * 3;
if( swingN < 0 ) swingN = 0;
}
} }
protected void SetCurrentAnimState( int tickCount, float t ) { const float armMax = (float)( 90 * Math.PI / 180.0 );
float run = Utils.Lerp( runO, runN, t ); const float legMax = (float)( 80 * Math.PI / 180.0 );
float anim = Utils.Lerp( animStepO, animStepN, t ); const float idleMax = (float)( 3 * Math.PI / 180.0 );
float time = tickCount + t; const float idleXPeriod = (float)( 2 * Math.PI / 5f );
const float idleZPeriod = (float)( 2 * Math.PI / 3.5f );
protected void SetCurrentAnimState( float t ) {
float swing = Utils.Lerp( swingO, swingN, t );
float walkTime = Utils.Lerp( walkTimeO, walkTimeN, t );
float idleTime = (float)( Window.accumulator );
float idleXRot = (float)( Math.Sin( idleTime * idleXPeriod ) * idleMax );
float idleZRot = (float)( idleMax + Math.Cos( idleTime * idleZPeriod ) * idleMax );
rightArmXRot = (float)( Math.Cos( anim * 0.6662f + Math.PI ) * 1.5f * run ); leftArmXRot = (float)( Math.Cos( walkTime ) * swing * armMax ) - idleXRot;
leftArmXRot = (float)( Math.Cos( anim * 0.6662f ) * 1.5f * run ); rightArmXRot = -leftArmXRot;
rightLegXRot = (float)( Math.Cos( anim * 0.6662f ) * 1.4f * run ); rightLegXRot = (float)( Math.Cos( walkTime ) * swing * legMax );
leftLegXRot = (float)( Math.Cos( anim * 0.6662f + Math.PI ) * 1.4f * run ); leftLegXRot = -rightLegXRot;
float idleZRot = (float)( Math.Cos( time * 0.09f ) * 0.05f + 0.05f );
float idleXRot = (float)( Math.Sin( time * 0.067f ) * 0.05f );
rightArmZRot = idleZRot; rightArmZRot = idleZRot;
leftArmZRot = -idleZRot; leftArmZRot = -idleZRot;
rightArmXRot += idleXRot;
leftArmXRot -= idleXRot;
} }
public void SetModel( string modelName ) { public void SetModel( string modelName ) {