rigidbody, forces and collision testing
This commit is contained in:
44
PhysicsEngine/Physics/Bodies/Circle.cs
Normal file
44
PhysicsEngine/Physics/Bodies/Circle.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user