stable collisions
This commit is contained in:
@@ -39,34 +39,27 @@ namespace PhysicsEngine
|
||||
float speed = Velocity.Length();
|
||||
if (speed < 0.01f) return;
|
||||
|
||||
// 1. Oncoming relative wind direction (opposite to velocity)
|
||||
Vector2 windDir = -Velocity / speed;
|
||||
|
||||
float cos = MathF.Cos(Rotation);
|
||||
float sin = MathF.Sin(Rotation);
|
||||
|
||||
// Box local axes transformed into world space (Assuming Size.Y is length/major axis)
|
||||
Vector2 worldAxisY = new Vector2(-sin, cos); // Major axis vector
|
||||
Vector2 worldAxisX = new Vector2(cos, sin); // Minor axis vector
|
||||
|
||||
// 2. Calculate effective frontal width (projected area in 2D) based on current orientation
|
||||
Vector2 windPerp = new Vector2(-windDir.Y, windDir.X);
|
||||
float projX = MathF.Abs(Vector2.Dot(worldAxisX, windPerp));
|
||||
float projY = MathF.Abs(Vector2.Dot(worldAxisY, windPerp));
|
||||
float effectiveWidth = Size.X * projX + Size.Y * projY;
|
||||
|
||||
// 3. Translational Drag Force (scales with dynamic pressure and current effective width)
|
||||
float dragMagnitude = 0.5f * airDensity * speed * speed * DragCoefficient * effectiveWidth;
|
||||
Vector2 dragForce = windDir * dragMagnitude;
|
||||
ApplyForce(dragForce);
|
||||
|
||||
// 4. Weathercock / Fin-Effect Restoring Torque
|
||||
// Measures angular misalignment between the box's major axis and the wind direction
|
||||
float cross = worldAxisY.X * windDir.Y - worldAxisY.Y * windDir.X;
|
||||
float restoringTorque = cross * 0.5f * airDensity * speed * speed * DragCoefficient * Size.X * Size.Y;
|
||||
ApplyTorque(restoringTorque);
|
||||
|
||||
// 5. Angular Damping (Quadratic Rotational Drag)
|
||||
float angularSpeed = MathF.Abs(AngularVelocity);
|
||||
if (angularSpeed > 0.0001f)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user