我正在研究用于2D游戏的Separting Axis定理的实现.它有点工作,但只是一种.
我这样使用它:
bool penetration = sat(c1, c2) && sat(c2, c1);
Run Code Online (Sandbox Code Playgroud)
其中c1和c2类型Convex,定义为:
class Convex
{
public:
float tx, ty;
public:
std::vector<Point> p;
void translate(float x, float y) {
tx = x;
ty = y;
}
};
Run Code Online (Sandbox Code Playgroud)
(Point是结构float x,float y)
这些点是顺时针输入的.
我当前的代码(忽略Qt调试):
bool sat(Convex c1, Convex c2, QPainter *debug)
{
//Debug
QColor col[] = {QColor(255, 0, 0), QColor(0, 255, 0), QColor(0, 0, 255), QColor(0, 0, 0)};
bool ret = …Run Code Online (Sandbox Code Playgroud)