This commit is contained in:
Syntriax 2023-12-06 16:52:48 +03:00
parent 8f3573100a
commit 73c939805f
1 changed files with 6 additions and 27 deletions

View File

@ -37,7 +37,6 @@ public class PhysicsEngine2D : IPhysicsEngine2D
rigidBodies.Remove(rigidBody); rigidBodies.Remove(rigidBody);
} }
// List<IGameObject> gameObjects = new List<IGameObject>();
private List<Line> lines = new List<Line>(32); private List<Line> lines = new List<Line>(32);
public void Step(float deltaTime) public void Step(float deltaTime)
@ -53,39 +52,19 @@ public class PhysicsEngine2D : IPhysicsEngine2D
foreach (var collider in colliders) foreach (var collider in colliders)
collider.Recalculate(); collider.Recalculate();
// foreach (var gameObject in gameObjects)
// Game1.gameManager.RemoveGameObject(gameObject);
// gameObjects.Clear();
// foreach (var collider in colliders)
// foreach (var vertex in collider.Vertices)
// {
// GameObject gameObject = Game1.gameManager.InstantiateGameObject<GameObject>();
// gameObject.BehaviourController.AddBehaviour<DisplayableSpriteBehaviour>().Assign(Game1.spriteBox);
// gameObject.Transform.Position = vertex;
// gameObjects.Add(gameObject);
// }
for (int i = colliders.Count - 1; i >= 0; i--) for (int i = colliders.Count - 1; i >= 0; i--)
CheckCollisions(colliders[i], colliders, (c1, c2, v) => CheckCollisions(colliders[i], colliders, (collider1, collider2, collisionVertex) =>
{ {
// Console.WriteLine($"c1: {c1.BehaviourController.GameObject.Name}, c2: {c2.BehaviourController.GameObject.Name}"); ResolveCollision(collider1, collider2, collisionVertex, intervalDeltaTime);
NewMethod(c1, c2, v, intervalDeltaTime); ResolveCollision(collider2, collider1, collisionVertex, intervalDeltaTime);
NewMethod(c2, c1, v, intervalDeltaTime);
// if (c2.RigidBody2D is IRigidBody2D) collider1.Recalculate();
// { collider2.Recalculate();
// c2.RigidBody2D.Velocity = -c2.RigidBody2D.Velocity;
// StepRigidBody(c2.RigidBody2D, intervalDeltaTime);
// }
c1.Recalculate();
c2.Recalculate();
}); });
} }
} }
private void NewMethod(ICollider2D c1, ICollider2D c2, Vector2 vertex, float intervalDeltaTime) private void ResolveCollision(ICollider2D c1, ICollider2D c2, Vector2 vertex, float intervalDeltaTime)
{ {
if (c1.RigidBody2D is not IRigidBody2D) if (c1.RigidBody2D is not IRigidBody2D)
return; return;