mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-16 07:12:27 +02:00
* Physics worlds * Paul's a good boy * Build working * Ingame and not lagging to hell * Why didn't you commit ahhhhh * Hard collisions working * Solver parity * Decent broadphase work done * BroadPhase outline done * BroadPhase working * waiting for pvs * Fix static PVS AABB * Stop static bodies from awakening * Optimise a bunch of stuff * Even more broadphase stuff * I'm fucking stupid * Optimise fixture updates * Collision solver start * Building * A is for Argumentative * Fix contact caching island flags * Circle shapes actually workeded * Damping * DS2 consumables only * Slightly more stable * Even slightlier more stablier * VV your heart out * Initial joint support * 90% of joints I just wanted to push as I'd scream if I lost progress * JOINT PURGATORY * Joints barely functional lmao * Okay these joints slightly more functional * Remove station FrictionJoint * Also that * Some Box2D ports * Cleanup mass * Edge shape * Active contacts * Fix active contacts * Optimise active contacts even more * Boxes be stacking * I would die for smug oh my fucking god * In which everything is fixed * Distance joints working LETS GO * Remove frequency on distancejoint * Fix some stuff and break joints * Crashing fixed mehbeh * ICollideSpecial and more resilience * auto-clear * showbb vera * Slap that TODO in there * Fix restartround crash * Random fixes * Fix fixture networking * Add intersection method for broadphase * Fix contacts * Licenses done * Optimisations * Fix wall clips * Config caching for island * allocations optimisations * Optimise casts * Optimise events queue for physics * Contact manager optimisations * Optimise controllers * Sloth joint or something idk * Controller graph * Remove content cvar * Random cleanup * Finally remove VirtualController * Manifold structs again * Optimise this absolute retardation * Optimise * fix license * Cleanup physics interface * AHHHHHHHHHHHHH * Fix collisions again * snivybus * Fix potential nasty manifold bug * Tests go snivy * Disable prediction for now * Spans * Fix ShapeTypes * fixes * ch ch changeesss * Kinematic idea * Prevent static bodies from waking * Pass WorldAABB to MoveEvent * Fix collisions * manifold structs fucking WOOORRKKKINNGGG * Better pushing * Fix merge ickies * Optimise MoveEvents * Use event for collisions performance * Fix content tests * Do not research tests * Fix most conflicts * Paul's trying to kill me * Maybe collisions work idk * Make us whole again * Smug is also trying to kill me * nani * shitty collisions * Settling * Do not research collisions * SHIP IT * Fix joints * PVS moment * Fix other assert * Fix locker collisions * serializable sleeptime * Aether2D contacts * Physics is no longer crashing (and burning) * Add to the TODO list Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
116 lines
3.4 KiB
C#
116 lines
3.4 KiB
C#
using System;
|
|
using Robust.Shared.Maths;
|
|
|
|
namespace Robust.Shared.Physics.Collision
|
|
{
|
|
/// <summary>
|
|
/// A rectangle that is always axis-aligned.
|
|
/// </summary>
|
|
[Serializable]
|
|
internal readonly struct AlignedRectangle : IEquatable<AlignedRectangle>
|
|
{
|
|
/// <summary>
|
|
/// Center point of the rectangle in world space.
|
|
/// </summary>
|
|
public readonly Vector2 Center;
|
|
|
|
/// <summary>
|
|
/// Half of the total width and height of the rectangle.
|
|
/// </summary>
|
|
public readonly Vector2 HalfExtents;
|
|
|
|
/// <summary>
|
|
/// A 1x1 unit rectangle with the origin centered on the world origin.
|
|
/// </summary>
|
|
public static readonly AlignedRectangle UnitCentered = new(new Vector2(0.5f, 0.5f));
|
|
|
|
/// <summary>
|
|
/// The lower X coordinate of the left edge of the box.
|
|
/// </summary>
|
|
public float Left => Center.X - HalfExtents.X;
|
|
|
|
/// <summary>
|
|
/// The higher X coordinate of the right edge of the box.
|
|
/// </summary>
|
|
public float Right => Center.X + HalfExtents.X;
|
|
|
|
/// <summary>
|
|
/// The lower Y coordinate of the top edge of the box.
|
|
/// </summary>
|
|
public float Bottom => Center.Y - HalfExtents.Y;
|
|
|
|
/// <summary>
|
|
/// The higher Y coordinate of the bottom of the box.
|
|
/// </summary>
|
|
public float Top => Center.Y + HalfExtents.Y;
|
|
|
|
public AlignedRectangle(Box2 box)
|
|
{
|
|
var halfWidth = box.Width / 2;
|
|
var halfHeight = box.Height / 2;
|
|
|
|
HalfExtents = new Vector2(halfWidth, halfHeight);
|
|
Center = new Vector2(box.Left + halfWidth, box.Height + halfHeight);
|
|
}
|
|
|
|
public AlignedRectangle(Vector2 halfExtents)
|
|
{
|
|
Center = default;
|
|
HalfExtents = halfExtents;
|
|
}
|
|
|
|
public AlignedRectangle(Vector2 center, Vector2 halfExtents)
|
|
{
|
|
Center = center;
|
|
HalfExtents = halfExtents;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Given a point, returns the closest point to it inside the box.
|
|
/// </summary>
|
|
public Vector2 ClosestPoint(in Vector2 position)
|
|
{
|
|
// clamp the point to the border of the box
|
|
var cx = MathHelper.Clamp(position.X, Left, Right);
|
|
var cy = MathHelper.Clamp(position.Y, Bottom, Top);
|
|
|
|
return new Vector2(cx, cy);
|
|
}
|
|
|
|
#region Equality members
|
|
|
|
public bool Equals(AlignedRectangle other)
|
|
{
|
|
return Center.Equals(other.Center) && HalfExtents.Equals(other.HalfExtents);
|
|
}
|
|
|
|
public override bool Equals(object? obj)
|
|
{
|
|
return obj is AlignedRectangle other && Equals(other);
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return HashCode.Combine(Center, HalfExtents);
|
|
}
|
|
|
|
public static bool operator ==(AlignedRectangle left, AlignedRectangle right) {
|
|
return left.Equals(right);
|
|
}
|
|
|
|
public static bool operator !=(AlignedRectangle left, AlignedRectangle right) {
|
|
return !left.Equals(right);
|
|
}
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// Returns the string representation of this object.
|
|
/// </summary>
|
|
public override string ToString()
|
|
{
|
|
return $"({Left}, {Bottom}, {Right}, {Top})";
|
|
}
|
|
}
|
|
}
|