rigidbody, forces and collision testing
This commit is contained in:
63
PhysicsEngine/UI/DrawHelper.cs
Normal file
63
PhysicsEngine/UI/DrawHelper.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using Raylib_cs;
|
||||
|
||||
namespace PhysicsEngine
|
||||
{
|
||||
public static class DrawHelper
|
||||
{
|
||||
public static Color GetDarkerColor(Color color, float factor = 0.5f)
|
||||
{
|
||||
return new Color(
|
||||
(byte)(color.R * factor),
|
||||
(byte)(color.G * factor),
|
||||
(byte)(color.B * factor),
|
||||
color.A
|
||||
);
|
||||
}
|
||||
|
||||
public static void DrawRotatedBox(Vector2 position, Vector2 size, float rotationRadians, Color fillColor, float pixelsPerMeter = 100.0f, float outlineThickness = 3.0f)
|
||||
{
|
||||
Vector2 sizePixels = size * pixelsPerMeter;
|
||||
Vector2 positionPixels = position * pixelsPerMeter;
|
||||
float rotationDegrees = rotationRadians * (180.0f / MathF.PI);
|
||||
|
||||
Color outlineColor = GetDarkerColor(fillColor);
|
||||
|
||||
// 1. Draw the outer outline rectangle (exact original size, outline colour)
|
||||
Vector2 outerSizePixels = sizePixels;
|
||||
Vector2 outerOrigin = outerSizePixels * 0.5f;
|
||||
Rectangle outerRec = new Rectangle(positionPixels.X, positionPixels.Y, outerSizePixels.X, outerSizePixels.Y);
|
||||
Raylib.DrawRectanglePro(outerRec, outerOrigin, rotationDegrees, outlineColor);
|
||||
|
||||
// 2. Draw the inner fill rectangle, reduced by outlineThickness on all sides
|
||||
Vector2 innerSizePixels = new Vector2(
|
||||
MathF.Max(0, sizePixels.X - outlineThickness),
|
||||
MathF.Max(0, sizePixels.Y - outlineThickness)
|
||||
);
|
||||
Vector2 innerOrigin = innerSizePixels * 0.5f;
|
||||
Rectangle innerRec = new Rectangle(positionPixels.X, positionPixels.Y, innerSizePixels.X, innerSizePixels.Y);
|
||||
Raylib.DrawRectanglePro(innerRec, innerOrigin, rotationDegrees, fillColor);
|
||||
}
|
||||
|
||||
public static void DrawCircleBody(Vector2 position, float radius, float rotationRadians, Color fillColor, float pixelsPerMeter = 100.0f, float outlineThickness = 3.0f)
|
||||
{
|
||||
Vector2 positionPixels = position * pixelsPerMeter;
|
||||
float radiusPixels = radius * pixelsPerMeter;
|
||||
Color outlineColor = GetDarkerColor(fillColor);
|
||||
|
||||
// 1. Draw outer circle (outline colour, exact radius)
|
||||
Raylib.DrawCircleV(positionPixels, radiusPixels, outlineColor);
|
||||
|
||||
// 2. Draw inner circle (fill colour, radius reduced by outlineThickness)
|
||||
float innerRadius = MathF.Max(0, radiusPixels - outlineThickness);
|
||||
Raylib.DrawCircleV(positionPixels, innerRadius, fillColor);
|
||||
|
||||
// Draw rotation indicator line inside the fill (same as before, but from centre to inner edge)
|
||||
float cos = MathF.Cos(rotationRadians);
|
||||
float sin = MathF.Sin(rotationRadians);
|
||||
Vector2 edge = positionPixels + new Vector2(cos, sin) * innerRadius;
|
||||
Raylib.DrawLineEx(positionPixels, edge, 2.0f, outlineColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
44
PhysicsEngine/UI/MuiDarkColor.cs
Normal file
44
PhysicsEngine/UI/MuiDarkColor.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Raylib_cs;
|
||||
|
||||
namespace PhysicsEngine
|
||||
{
|
||||
public enum MuiDarkColor : uint
|
||||
{
|
||||
// Backgrounds & Surfaces
|
||||
BackgroundDefault = 0x121212FF, // #121212
|
||||
SurfacePaper = 0x121212FF,
|
||||
SurfaceVariant = 0x1E1E1EFF, // #1E1E1E
|
||||
|
||||
// Text Colors
|
||||
TextPrimary = 0xFFFFFFFF, // #FFFFFF
|
||||
TextSecondary = 0xFFFFFFB3,
|
||||
TextDisabled = 0xFFFFFF80,
|
||||
|
||||
// Actions & States
|
||||
ActionHover = 0xFFFFFF14,
|
||||
ActionSelected = 0xFFFFFF29,
|
||||
Divider = 0xFFFFFF1F,
|
||||
|
||||
// Brand / Theme Accents
|
||||
PrimaryMain = 0x90CAF9FF, // #90CAF9
|
||||
SecondaryMain = 0xCE93D8FF, // #CE93D8
|
||||
ErrorMain = 0xEF5350FF, // #EF5350
|
||||
WarningMain = 0xFF9800FF, // #FF9800
|
||||
SuccessMain = 0x66BB6AFF // #66BB6A
|
||||
}
|
||||
|
||||
public static class MuiDarkColorExtensions
|
||||
{
|
||||
public static Color ToColor(this MuiDarkColor colorEnum)
|
||||
{
|
||||
uint packedValue = (uint)colorEnum;
|
||||
|
||||
byte r = (byte)(packedValue >> 24);
|
||||
byte g = (byte)((packedValue >> 16) & 0xFF);
|
||||
byte b = (byte)((packedValue >> 8) & 0xFF);
|
||||
byte a = (byte)(packedValue & 0xFF);
|
||||
|
||||
return new Color(r, g, b, a);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user