Answers:
我知道这个问题很旧,但是我觉得它缺少一个简单的基于代码的答案。所以这里是:
/// <summary>
/// Return if a given position is inside the physical body.
/// </summary>
/// <param name="body">Body to test.</param>
/// <param name="position">Position to check if inside the body.</param>
/// <returns>If given point is inside the physical body.</returns>
public bool TestPointCollision(FarseerPhysics.Dynamics.Body body, Vector2 position)
{
// get body transformation
FarseerPhysics.Common.Transform trans;
body.GetTransform(out trans);
// iterate fixtures to see if any of them hit the point
foreach (var fix in body.FixtureList)
{
if (fix.Shape.TestPoint(ref trans, ref position))
return true;
}
// if there are no hits, return false
return false;
}
请注意,这不是普通的Box2D,而是Farseer(和C#),但它应该具有完全相同的API。