class Rectangle{
public:
float x, y, width, height;
// (x,y) is the lower left corner of the rectangle
};
这个算法正确吗?
bool Rectangle::colidesWith(Rectangle other) {
if (x+width < other.x) return false; // "other" is on the far right
if (other.x+other.width < x) return false; //"other" is on the far left
if (y+height < other.y) return false // "other" is up
if (other.y+other.height < y) return false // "other" is down
return true;
}
最佳答案
如果矩形被填充(即,如果其中一个在另一个矩形内,则算作碰撞)。
关于c++ - 矩形碰撞检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13919303/