return !(outsideY || outsideX);
}
else if(dynamic_cast<const CollisionCircle*>(c)){
- c->collision(this, cPos, pos);/// \todo this flips a shit!!!!!!
+ return c->collision(this, cPos, pos);
}
-
+ //if something breaks bad
return false;
}
bool CollisionCircle::collision(const CollisionRectangle* c, const Point2D cPos, const Point2D pos) const {
///check rect vs circle \todo implement
+ Point2D rectCent = cPos + c->mPos;//center of rect
+ Point2D tl = rectCent + Point2D(-c->width/2,-c->height/2);//top left of rect
+ Point2D bl = rectCent + Point2D(-c->width/2, c->height/2);//bottom left of rect
+ Point2D tr = rectCent + Point2D( c->width/2,-c->height/2);//top right of rect
+ Point2D br = rectCent + Point2D( c->width/2, c->height/2);//bottom right of rect
+ //Are any of the points inside the circle?
+ if( ((tl.x - mPos.x)*(tl.x - mPos.x) + (tl.y - mPos.y)*(tl.y - mPos.y) - radius*radius) <= 0 ||
+ ((tr.x - mPos.x)*(tr.x - mPos.x) + (tr.y - mPos.y)*(tr.y - mPos.y) - radius*radius) <= 0 ||
+ ((bl.x - mPos.x)*(bl.x - mPos.x) + (bl.y - mPos.y)*(bl.y - mPos.y) - radius*radius) <= 0 ||
+ ((br.x - mPos.x)*(br.x - mPos.x) + (br.y - mPos.y)*(br.y - mPos.y) - radius*radius) <= 0 )
+ return true;
+ //Is the circle inside the rectangle? (considers bounds)
+ else if( !(
+ mPos.x + radius < tl.x ||
+ mPos.x - radius > tr.x ||
+ mPos.y + radius < tl.y ||
+ mPos.y - radius > bl.y ))
+ return true;
+ //It's not in there
return false;
-}
\ No newline at end of file
+}