我最近在stackoverflow上找到了代碼,用於處理多邊形和圓形之間的碰撞,它的工作原理。問題是因爲我不太明白,所以如果有人能夠給我簡單的解釋,我會很感激。libGDX多邊形 - 圓形碰撞
// Check if Polygon intersects Circle
private boolean isCollision(Polygon p, Circle c) {
float[] vertices = p.getTransformedVertices();
Vector2 center = new Vector2(c.x, c.y);
float squareRadius = c.radius * c.radius;
for (int i = 0; i < vertices.length; i += 2) {
if (i == 0) {
if (Intersector.intersectSegmentCircle(new Vector2(
vertices[vertices.length - 2],
vertices[vertices.length - 1]), new Vector2(
vertices[i], vertices[i + 1]), center, squareRadius))
return true;
} else {
if (Intersector.intersectSegmentCircle(new Vector2(
vertices[i - 2], vertices[i - 1]), new Vector2(
vertices[i], vertices[i + 1]), center, squareRadius))
return true;
}
}
return false;
}
我沒有得到它的部分是for循環。
確保您檢查圓形是否包含在多邊形內。 http://stackoverflow.com/a/29938608/2900738 –