new powertrain смерть чуркам
This commit is contained in:
79
Code/Base/Powertrain/Differential/BaseDifferential.cs
Normal file
79
Code/Base/Powertrain/Differential/BaseDifferential.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using Sandbox;
|
||||
using System;
|
||||
|
||||
namespace VeloX.Powertrain;
|
||||
|
||||
[Category( "VeloX/Powertrain/Gearbox" )]
|
||||
public abstract class BaseDifferential : PowertrainComponent
|
||||
{
|
||||
[Property] public float FinalDrive { get; set; } = 3.392f;
|
||||
[Property] public override float Inertia { get; set; } = 0.01f;
|
||||
//[Property] public float CoastRamp { get; set; } = 1f;
|
||||
//[Property] public float PowerRamp { get; set; } = 1f;
|
||||
//[Property] public float Stiffness { get; set; } = 0.1f;
|
||||
//[Property] public float SlipTorque { get; set; } = 0f;
|
||||
//[Property] public float SteerLock { get; set; } = 45f;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The PowertrainComponent this component will output to.
|
||||
/// </summary>
|
||||
[Property]
|
||||
public PowertrainComponent OutputB
|
||||
{
|
||||
get => _outputb;
|
||||
set
|
||||
{
|
||||
if ( value == this )
|
||||
{
|
||||
_outputb = null;
|
||||
return;
|
||||
}
|
||||
|
||||
_outputb = value;
|
||||
if ( _outputb != null )
|
||||
_outputb.Input = this;
|
||||
}
|
||||
|
||||
}
|
||||
private PowertrainComponent _outputb;
|
||||
|
||||
public override bool HasOutput => Output.IsValid() && OutputB.IsValid();
|
||||
|
||||
public override float QueryAngularVelocity( float angularVelocity )
|
||||
{
|
||||
this.angularVelocity = angularVelocity;
|
||||
|
||||
if ( !HasOutput )
|
||||
return angularVelocity;
|
||||
|
||||
float aW = Output.QueryAngularVelocity( angularVelocity );
|
||||
float bW = OutputB.QueryAngularVelocity( angularVelocity );
|
||||
|
||||
return (aW + bW) * FinalDrive * 0.5f;
|
||||
}
|
||||
|
||||
public abstract void SplitTorque( float aW, float bW, float aI, float bI, out float tqA, out float tqB );
|
||||
|
||||
public override float ForwardStep( float torque, float inertia )
|
||||
{
|
||||
if ( !HasOutput )
|
||||
return torque;
|
||||
|
||||
float aW = Output.QueryAngularVelocity( angularVelocity );
|
||||
float bW = OutputB.QueryAngularVelocity( angularVelocity );
|
||||
|
||||
float aI = Output.QueryInertia();
|
||||
float bI = OutputB.QueryInertia();
|
||||
|
||||
Torque = torque * FinalDrive;
|
||||
|
||||
SplitTorque( aW, bW, aI, bI, out float tqA, out float tqB );
|
||||
|
||||
tqA = Output.ForwardStep( tqA, inertia * 0.5f * MathF.Pow( FinalDrive, 2 ) + aI );
|
||||
tqB = OutputB.ForwardStep( tqB, inertia * 0.5f * MathF.Pow( FinalDrive, 2 ) + bI );
|
||||
|
||||
return tqA + tqB;
|
||||
}
|
||||
|
||||
}
|
||||
13
Code/Base/Powertrain/Differential/OpenDifferential.cs
Normal file
13
Code/Base/Powertrain/Differential/OpenDifferential.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Sandbox;
|
||||
|
||||
namespace VeloX.Powertrain;
|
||||
|
||||
public class OpenDifferential : BaseDifferential
|
||||
{
|
||||
[Property] public float BiasAB { get; set; } = 0.5f;
|
||||
public override void SplitTorque( float aW, float bW, float aI, float bI, out float tqA, out float tqB )
|
||||
{
|
||||
tqA = Torque * (1 - BiasAB);
|
||||
tqB = Torque * BiasAB;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user