mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2025-12-16 12:21:48 +01:00
Collision Rework, started adding directions to the collision (WIP)
This commit is contained in:
@@ -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 );
|
||||
|
||||
Reference in New Issue
Block a user