46 lines
986 B
C#
46 lines
986 B
C#
using Sandbox;
|
|
using System;
|
|
|
|
namespace VeloX.Powertrain;
|
|
|
|
[Category( "VeloX/Powertrain/Gearbox" )]
|
|
public abstract class BaseGearbox : PowertrainComponent
|
|
{
|
|
[Property] public override float Inertia { get; set; } = 0.01f;
|
|
|
|
protected float ratio;
|
|
|
|
public override float QueryInertia()
|
|
{
|
|
if ( !HasOutput || ratio == 0 )
|
|
return Inertia;
|
|
|
|
return Inertia + Output.QueryInertia() / MathF.Pow( ratio, 2 );
|
|
}
|
|
|
|
public override float QueryAngularVelocity( float angularVelocity )
|
|
{
|
|
this.angularVelocity = angularVelocity;
|
|
if ( !HasOutput || ratio == 0 )
|
|
return angularVelocity;
|
|
|
|
return Output.QueryAngularVelocity( angularVelocity ) * ratio;
|
|
}
|
|
|
|
public override float ForwardStep( float torque, float inertia )
|
|
{
|
|
Torque = torque * ratio;
|
|
|
|
if ( !HasOutput )
|
|
return torque;
|
|
|
|
if ( ratio == 0 )
|
|
{
|
|
Output.ForwardStep( 0, Inertia * 0.5f );
|
|
return torque;
|
|
}
|
|
|
|
return Output.ForwardStep( Torque, (inertia + Inertia) * MathF.Pow( ratio, 2 ) ) / ratio;
|
|
}
|
|
}
|