New collision detection

This commit is contained in:
2021-03-13 15:05:16 +01:00
parent 258ce51cfe
commit d2cf54556e
12 changed files with 186 additions and 125 deletions
+10 -3
View File
@@ -1,4 +1,5 @@
#include "sdlpp_collision.hpp"
#include "sdlpp_geometry.hpp"
namespace SDLPP {
CollisionPolygon::CollisionPolygon( double x, double y )
@@ -53,8 +54,14 @@ bool infinityIntersection( const SDLPP::CollisionPolygon &infinite,
bool intersects( const SDLPP::CollisionPolygon &p1,
const SDLPP::CollisionPolygon &p2 ) {
return !(
p1.rightmost() < p2.leftmost() || p2.rightmost() < p1.leftmost() ||
p1.topmost() > p2.bottommost() || p2.topmost() > p1.bottommost() );
if(p1.rightmost() < p2.leftmost() || p2.rightmost() < p1.leftmost() || p1.bottommost() < p2.topmost() || p2.bottommost() < p1.topmost())
return false;
for(auto &line : p1.getLines()) {
for(auto &line2 : p2.getLines()) {
if(linesCross(line, line2))
return true;
}
}
return false;
}
} // namespace SDLPP