Collision Rework, started adding directions to the collision (WIP)

This commit is contained in:
Bram Verhulst
2024-03-17 15:53:48 +01:00
parent d6c5cfa47b
commit 05f46b7eba
5 changed files with 42 additions and 21 deletions

View File

@@ -4,6 +4,9 @@
namespace Collision
{
TileCollisionRect::TileCollisionRect(const Point2f& pos, const Point2f& size, WorldTile* tile): pos(pos), size(size), tile(tile)
{}
bool PointVsRect(const Point2f p, const Collision::CollisionRect& r) {
return ( p.x >= r.pos.x && p.y >= r.pos.y && p.x < r.pos.x + r.size.x && p.y < r.pos.y + r.size.y );
}
@@ -99,16 +102,16 @@ namespace Collision
float contact_time = 0.0f;
if (DynamicRectVsRect(dynamicRectangle, ElapsedTime, *staticRectangle, contactPoint, contactNormal, contact_time)) {
if (contactNormal.y > 0) {
dynamicRectangle.contact[0] = staticRectangle;
dynamicRectangle.ContactMap[CollisionDirection::Bottom] = staticRectangle;
}
if (contactNormal.x < 0) {
dynamicRectangle.contact[1] = staticRectangle;
dynamicRectangle.ContactMap[CollisionDirection::Left] = staticRectangle;
}
if (contactNormal.y < 0) {
dynamicRectangle.contact[2] = staticRectangle;
dynamicRectangle.ContactMap[CollisionDirection::Top] = staticRectangle;
}
if (contactNormal.x > 0) {
dynamicRectangle.contact[3] = staticRectangle;
dynamicRectangle.ContactMap[CollisionDirection::Right] = staticRectangle;
}
//dynamicRectangle.vel = dynamicRectangle.vel + contactNormal * Point2f(std::abs(dynamicRectangle.vel.x), std::abs(dynamicRectangle.vel.y)) * ( 1 - contact_time );