diff --git a/Game/Physics2D/Collider2DAABBBehaviour.cs b/Game/Physics2D/Collider2DAABBBehaviour.cs index cfabc2a..bd1f73c 100644 --- a/Game/Physics2D/Collider2DAABBBehaviour.cs +++ b/Game/Physics2D/Collider2DAABBBehaviour.cs @@ -14,6 +14,11 @@ public class Collider2DAABBBehaviour(Vector2 lowerBound, Vector2 upperBound) : B public Vector2 LowerBound { get; } = lowerBound; public Vector2 UpperBound { get; } = upperBound; + + private Vector2 worldLowerBound = lowerBound; + private Vector2 worldUpperBound = upperBound; + + private IRigidBody2D? _rigidBody2D = null; public IRigidBody2D? RigidBody2D @@ -35,8 +40,8 @@ public class Collider2DAABBBehaviour(Vector2 lowerBound, Vector2 upperBound) : B public bool CheckCollision(Vector2 point, ICollider2D otherCollider) { - if (point.X >= LowerBound.X + Transform.Position.X && point.X <= UpperBound.X + Transform.Position.X && - point.Y >= LowerBound.Y + Transform.Position.Y && point.Y <= UpperBound.Y + Transform.Position.Y) + if (point.X >= worldLowerBound.X && point.X <= worldUpperBound.X && + point.Y >= worldLowerBound.Y && point.Y <= worldUpperBound.Y) return true; return false; @@ -44,6 +49,7 @@ public class Collider2DAABBBehaviour(Vector2 lowerBound, Vector2 upperBound) : B public void Recalculate() { - throw new NotImplementedException(); + worldLowerBound = LowerBound + Transform.Position; + worldUpperBound = UpperBound + Transform.Position; } } diff --git a/Game/Physics2D/PhysicsEngine2D.cs b/Game/Physics2D/PhysicsEngine2D.cs index c0a4ad7..59b1d93 100644 --- a/Game/Physics2D/PhysicsEngine2D.cs +++ b/Game/Physics2D/PhysicsEngine2D.cs @@ -45,7 +45,7 @@ public class PhysicsEngine2D : IPhysicsEngine2D { float intervalDeltaTime = deltaTime / IterationCount; - for (int i = 0; i < IterationCount; i++) + for (int iterationIndex = 0; iterationIndex < IterationCount; iterationIndex++) { foreach (var rigidBody in rigidBodies) StepRigidBody(rigidBody, intervalDeltaTime); @@ -54,6 +54,15 @@ public class PhysicsEngine2D : IPhysicsEngine2D foreach (var collider in colliders) collider.Recalculate(); + for (int ix = colliders.Count - 1; ix >= 0; ix--) + { + ICollider2D colliderX = colliders[ix]; + for (int iy = colliders.Count - 1; iy >= ix + 1; iy--) + { + ICollider2D colliderY = colliders[iy]; + + } + } } }