51 lines
1.2 KiB
C#
51 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
using System.Text;
|
|
|
|
namespace Thousandto.Core.Base
|
|
{
|
|
public class Interpolator_Linear {
|
|
public void SetDest( float value ) {
|
|
_dest = value;
|
|
}
|
|
public void SetCur( float value ) {
|
|
_cur = value;
|
|
}
|
|
public void Set( float value ) {
|
|
_cur = _dest = value;
|
|
}
|
|
public float Get() {
|
|
return _cur;
|
|
}
|
|
public bool IsRunning() {
|
|
return _cur != _dest;
|
|
}
|
|
public float GetDest() {
|
|
return _dest;
|
|
}
|
|
public float GetSpeed() {
|
|
return _speed;
|
|
}
|
|
public void SetSpeed( float speed ) {
|
|
_speed = Math.Abs(speed);
|
|
}
|
|
public void Update( float dt ) {
|
|
if ( _dest == _cur ) {
|
|
return;
|
|
}
|
|
var sign = Math.Sign( _dest - _cur );
|
|
float newValue = _cur + _speed * sign * dt;
|
|
if ( ( newValue - _dest ) * ( _cur - _dest ) > 0 ) {
|
|
_cur = newValue;
|
|
} else {
|
|
// finished
|
|
_cur = _dest;
|
|
}
|
|
}
|
|
float _dest = 0;
|
|
float _cur = 0;
|
|
float _speed = 0;
|
|
}
|
|
}
|