This commit is contained in:
Syntriax 2023-12-05 17:39:38 +03:00
parent a417d2d753
commit a05fb3ba33
3 changed files with 57 additions and 11 deletions

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Syntriax.Engine.Core.Abstract; using Syntriax.Engine.Core.Abstract;
@ -11,15 +12,8 @@ public interface ICollider2D : IBehaviour, IAssignableTransform
{ {
IRigidBody2D? RigidBody2D { get; } IRigidBody2D? RigidBody2D { get; }
Action<ICollider2D, ICollider2D>? OnCollision { get; set; } Action<ICollider2D, ICollider2D>? OnCollisionPreResolve { get; set; }
Vector2 OffsetPosition { get; set; } bool CheckCollision(Vector2 point, ICollider2D otherCollider);
Vector2 OffsetScale { get; set; } void Recalculate();
float OffsetRotation { get; set; }
IReadOnlyList<Vector2> Vertices { get; }
bool CheckCollision(Vector2 point, ICollider2D otherCollider, out CollisionInformation? collisionInformation);
void RecalculateVertices();
} }

View File

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Syntriax.Engine.Core;
using Syntriax.Engine.Core.Abstract;
using Syntriax.Engine.Physics2D.Abstract;
namespace Syntriax.Engine.Physics2D;
public class Collider2DAABBBehaviour(Vector2 lowerBound, Vector2 upperBound) : BehaviourOverride, ICollider2D
{
public Vector2 LowerBound { get; } = lowerBound;
public Vector2 UpperBound { get; } = upperBound;
private IRigidBody2D? _rigidBody2D = null;
public IRigidBody2D? RigidBody2D
{
get
{
if (_rigidBody2D is null)
BehaviourController.TryGetBehaviour(out _rigidBody2D);
return _rigidBody2D;
}
}
public Action<ICollider2D, ICollider2D>? OnCollisionPreResolve { get; set; } = null;
public Action<IAssignableTransform>? OnTransformAssigned { get => GameObject.OnTransformAssigned; set => GameObject.OnTransformAssigned = value; }
ITransform IAssignableTransform.Transform => Transform;
public bool Assign(ITransform transform) => GameObject.Assign(transform);
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)
return true;
return false;
}
public void Recalculate()
{
throw new NotImplementedException();
}
}

View File

@ -1,7 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Pong; using Pong;
using Syntriax.Engine.Core; using Syntriax.Engine.Core;
using Syntriax.Engine.Core.Abstract; using Syntriax.Engine.Core.Abstract;
using Syntriax.Engine.Graphics.TwoDimensional; using Syntriax.Engine.Graphics.TwoDimensional;
@ -49,7 +52,7 @@ public class PhysicsEngine2D : IPhysicsEngine2D
foreach (var collider in colliders) foreach (var collider in colliders)
collider.RecalculateVertices(); collider.Recalculate();
} }
} }