44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using System;
|
|
using System.Numerics;
|
|
using Raylib_cs;
|
|
|
|
namespace PhysicsEngine
|
|
{
|
|
public class Circle : Body
|
|
{
|
|
public float Radius;
|
|
|
|
public Circle(Vector2 position, float radius, float mass)
|
|
{
|
|
Position = position;
|
|
Radius = radius;
|
|
Mass = mass;
|
|
|
|
if (mass > 0.0f)
|
|
{
|
|
MomentOfInertia = 0.5f * mass * radius * radius;
|
|
}
|
|
}
|
|
|
|
public override void Draw(float pixelsPerMeter = 100.0f)
|
|
{
|
|
DrawHelper.DrawCircleBody(Position, Radius, Rotation, BaseColor, pixelsPerMeter);
|
|
}
|
|
|
|
public override void ApplyAerodynamicDrag(float dt)
|
|
{
|
|
if (DragCoefficient <= 0.0f) return;
|
|
|
|
const float airDensity = 1.225f;
|
|
float area = Radius * 2.0f;
|
|
float speed = Velocity.Length();
|
|
|
|
if (speed > 0.0001f)
|
|
{
|
|
Vector2 dragDir = -Vector2.Normalize(Velocity);
|
|
float dragMagnitude = 0.5f * airDensity * speed * speed * DragCoefficient * area;
|
|
ApplyForce(dragDir * dragMagnitude);
|
|
}
|
|
}
|
|
}
|
|
} |