private static void CalculateSolidVelocity(SolidRigidbody solid) { solid.ProcessingData.CalcVel = solid.Velocity; if (solid.Velocity == Vector2.Zero) { return; // Early exit if no velocity. } // Regional check against all static rigidbodies foreach (var staticbody in AllStatics) { foreach (var collider in solid.Colliders) { if (solid.ProcessingData.CalcVel == Vector2.Zero) { return; } if (PhysicsMath.IsOverlapping(collider, staticbody.MainCollider)) { if (!PhysicsMath.IsSlidingCorner(collider, staticbody.MainCollider)) { solid.ProcessingData.CalcVel = VelocityMath.IntoPlane(solid.ProcessingData.CalcVel, PhysicsMath.GetNormal(collider, staticbody.MainCollider)); Console.WriteLine($"Solid collision against {staticbody.Entity} ({collider.LocalPosition}) to yield {solid.ProcessingData.CalcVel}"); } } } } // Regional check against other solids foreach (var otherSolid in AllSolids) { if (solid.ProcessingData.CalcVel == Vector2.Zero) { return; } // Skip self if (ReferenceEquals(solid, otherSolid)) { continue; } // Skip if other solid has already processed this solid if (otherSolid.ProcessingData.CheckedAgainst.Contains(solid)) { continue; } if (PhysicsMath.IsOverlapping(solid.MainCollider, otherSolid.MainCollider)) { if (!PhysicsMath.IsSlidingCorner(solid.MainCollider, otherSolid.MainCollider)) { VelocityPair result = Ruleset.Get(solid, otherSolid); Console.WriteLine($"Collided {solid.Entity} against {otherSolid.Entity} to yield {result.left} and {result.right}"); solid.ProcessingData.CalcVel = result.left; otherSolid.ProcessingData.CalcVel = result.right; solid.ProcessingData.CheckedAgainst.Add(otherSolid); otherSolid.ProcessingData.CheckedAgainst.Add(solid); } } } }
public VelocityPair(VelocityPair other) { left = other.left; right = other.right; }