not work
This commit is contained in:
32
Code/Base/Wheel/Suspension/MacPhersonSuspension.cs
Normal file
32
Code/Base/Wheel/Suspension/MacPhersonSuspension.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Sandbox;
|
||||
using System;
|
||||
|
||||
namespace VeloX;
|
||||
public class MacPhersonSuspension
|
||||
{
|
||||
public readonly Vector3 WheelOffset;
|
||||
public readonly Vector3 UprightTop;
|
||||
public readonly Vector3 UprightAxis;
|
||||
private readonly Hinge Hinge;
|
||||
|
||||
public MacPhersonSuspension( Vector3 wheel, Vector3 strutBody, Vector3 strutWheel, Vector3 hingeBody )
|
||||
{
|
||||
WheelOffset = wheel - strutWheel;
|
||||
UprightTop = strutBody;
|
||||
UprightAxis = (strutBody - strutWheel).Normal;
|
||||
Hinge = new( hingeBody, strutWheel - hingeBody );
|
||||
}
|
||||
|
||||
public void GetWheelTransform( float travel, out Rotation rotation, out Vector3 position )
|
||||
{
|
||||
Vector3 hingeEnd = Hinge.Rotate( travel );
|
||||
Vector3 uprightAxisNew = (UprightTop - hingeEnd).Normal;
|
||||
|
||||
rotation = Rotation.FromAxis(
|
||||
Vector3.Cross( UprightAxis, uprightAxisNew ),
|
||||
MathF.Acos( Vector3.Dot( UprightAxis, uprightAxisNew ) ).RadianToDegree()
|
||||
);
|
||||
|
||||
position = hingeEnd + WheelOffset.Transform( rotation );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user