New collision detection
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user