我有这样的课:
class Point
{
public:
int x;
int y;
bool operator==( Point& other )
{
return (x == other.x) && (y = other.y);
}
};
然后我有一个基本的 Sprite 类,它有一个点向量,以及许多其他我没有在下面显示的成员/方法:
class Sprite
{
std::vector<Point> points;
};
现在,如何使用 Point 类中的 operator== 找到 Sprite 对象的向量中与另一个 Sprite 对象的向量中的任何其他点发生碰撞的任何点?我已经尝试过类似以下的方法,但效果不太好。Size()返回点向量中的点总数,Points()返回点向量:
bool Sprite::CollidesWith( Sprite* other )
{
for ( int ixThis = 0; ixThis < Size(); ixThis++ ) {
for ( int ixOther = 0; ixOther < other->Size(); ixOther++ ) {
if ( points->at(ixThis) == other->Points()->at(ixOther) )
return true;
}
}
return false;
}
有任何想法吗?