major rework

This commit is contained in:
max
2026-02-16 18:32:48 +01:00
parent bbd82da07e
commit 932734e5b4
24 changed files with 1706 additions and 893 deletions

View File

@@ -0,0 +1,38 @@
namespace Car_simulation.Core.Physics
{
public struct Vector2
{
public float X, Y;
public Vector2(float x, float y) { X = x; Y = y; }
public float Length => MathF.Sqrt(X * X + Y * Y);
public float LengthSquared => X * X + Y * Y;
public Vector2 Normalized()
{
float length = Length;
if (length > 0.0001f)
return new Vector2(X / length, Y / length);
return new Vector2(0, 0);
}
public void Normalize()
{
float length = Length;
if (length > 0.0001f)
{
X /= length;
Y /= length;
}
}
public static Vector2 Normalize(Vector2 v) => v.Normalized();
public static Vector2 operator *(Vector2 v, float s) => new Vector2(v.X * s, v.Y * s);
public static Vector2 operator *(float s, Vector2 v) => new Vector2(v.X * s, v.Y * s);
public static Vector2 operator /(Vector2 v, float s) => new Vector2(v.X / s, v.Y / s);
public static Vector2 operator +(Vector2 a, Vector2 b) => new Vector2(a.X + b.X, a.Y + b.Y);
public static Vector2 operator -(Vector2 a, Vector2 b) => new Vector2(a.X - b.X, a.Y - b.Y);
}
}