FrameSmoothing Camera

This commit is contained in:
Josef 2025-04-25 13:47:31 +02:00
parent 861ffd1a6d
commit ab4d9cf473
3 changed files with 22 additions and 4 deletions

View File

@ -9,7 +9,7 @@ namespace Rokojori
public partial class FrameSmoothing: Smoothing public partial class FrameSmoothing: Smoothing
{ {
[Export( PropertyHint.Range, "0,600")] [Export( PropertyHint.Range, "0,600")]
public int frames = 10; public float frames = 10;
protected override float _ComputeInterpolationAmount( float delta ) protected override float _ComputeInterpolationAmount( float delta )
{ {
@ -20,11 +20,10 @@ namespace Rokojori
return 1; return 1;
} }
var coefficient = GetCoefficientForFrames( frames ); var coefficient = GetLerpedCoefficientForFrames( frames );
return 1f - Mathf.Exp( -coefficient * delta ); return 1f - Mathf.Exp( -coefficient * delta );
} }
public static float ComputeCoefficient( float delta, float frames ) public static float ComputeCoefficient( float delta, float frames )
{ {
int floored = Mathf.FloorToInt( frames ); int floored = Mathf.FloorToInt( frames );
@ -48,6 +47,16 @@ namespace Rokojori
return 1f - Mathf.Exp( -coefficient * delta ); return 1f - Mathf.Exp( -coefficient * delta );
} }
public static float GetLerpedCoefficientForFrames( float frames )
{
int floored = Mathf.FloorToInt( frames );
float low = GetCoefficientForFrames( floored );
float high = GetCoefficientForFrames( floored + 1 );
return Mathf.Lerp( low, high, frames - floored );
}
public static float GetCoefficientForFrames( int frames ) public static float GetCoefficientForFrames( int frames )
{ {
return FrameSmoothingTable.Get( frames ); return FrameSmoothingTable.Get( frames );

View File

@ -4,6 +4,8 @@ using Godot;
namespace Rokojori namespace Rokojori
{ {
[Tool]
[GlobalClass]
public partial class Smoothing: Resource public partial class Smoothing: Resource
{ {
float _currentFloat = 0; float _currentFloat = 0;

View File

@ -42,6 +42,9 @@ namespace Rokojori
public float zoomSmoothingCoefficient = 0.1f; public float zoomSmoothingCoefficient = 0.1f;
Smoother smoother = new Smoother(); Smoother smoother = new Smoother();
[Export( PropertyHint.Range, "0,600")]
public Smoothing zoomSmoothing = new Smoothing();
public Vector3 moveDirection = Vector3.Zero; public Vector3 moveDirection = Vector3.Zero;
[Export] [Export]
@ -244,7 +247,11 @@ namespace Rokojori
void Apply( float delta ) void Apply( float delta )
{ {
_smoothDistance = smoother.SmoothWithCoefficient( _smoothDistance, distance, zoomSmoothingCoefficient, delta ); // _smoothDistance = smoother.SmoothWithCoefficient( _smoothDistance, distance, zoomSmoothingCoefficient, delta );
// _smoothDistance = FrameSmoothing.ComputeCoefficient
_smoothDistance = Smoothing.Apply( zoomSmoothing, distance, delta );
GlobalRotation = new Vector3( Mathf.DegToRad( pitch ), Mathf.DegToRad( yaw ), 0 ); GlobalRotation = new Vector3( Mathf.DegToRad( pitch ), Mathf.DegToRad( yaw ), 0 );
var forward = Math3D.GetGlobalForward( this ) * _smoothDistance; var forward = Math3D.GetGlobalForward( this ) * _smoothDistance;