本文整理汇总了C#中FarseerPhysics.Dynamics.World.QueryAABB方法的典型用法代码示例。如果您正苦于以下问题:C# World.QueryAABB方法的具体用法?C# World.QueryAABB怎么用?C# World.QueryAABB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FarseerPhysics.Dynamics.World
的用法示例。
在下文中一共展示了World.QueryAABB方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFixtureCircleIntersections
public static FixtureCoord[] GetFixtureCircleIntersections(World world, Vector2 point, float radius)
{
List<Fixture> potentials = new List<Fixture>();
var box = new FarseerPhysics.Collision.AABB(new Xna.Vector2(point.X, point.Y), radius * 2, radius * 2);
world.QueryAABB(delegate (Fixture fixture)
{
potentials.Add(fixture);
return false;
}, ref box);
List<FixtureCoord> collisions = new List<FixtureCoord>();
foreach (Fixture f in potentials)
{
Xna.Vector2 relativePoint = f.Body.GetLocalPoint(new Xna.Vector2(point.X, point.Y));
switch (f.Shape.ShapeType)
{
case ShapeType.Polygon:
PolygonShape polygon = (PolygonShape)f.Shape;
for (int i = 0; i < polygon.Vertices.Count; i++)
{
int iNext = (i + 1) % polygon.Vertices.Count;
LineF edge = new LineF(polygon.Vertices[i], polygon.Vertices[iNext]);
IntersectCoord[] intersects = MathExt.LineCircleIntersect(new Vector2(relativePoint.X, relativePoint.Y), radius, edge, true);
for (int j = 0; i < intersects.Length; i++)
{
collisions.Add(new FixtureCoord(f, i, (float)intersects[j].TFirst));
}
/*if (intersects.Length > 0)
{
fixtureCollisions.Add(f);
break;
}*/
}
break;
default:
throw new NotImplementedException();
}
}
return collisions.ToArray();
}
示例2: FindTarget
private void FindTarget(World world)
{
Vector2 currentPosition = Owner.Position;
closestTarget = Owner.PlayWindow.GoodCellList.First();
closestDistance = (currentPosition - closestTarget.Position).LengthSquared();
float boxSideStep = 2;
targetFound = false;
while (boxSideStep < 64 && targetFound == false)
{
AABB boundingBox = new AABB(ConvertUnits.ToSimUnits(currentPosition), boxSideStep, boxSideStep);
world.QueryAABB(AABBCollision, ref boundingBox);
boxSideStep *= 4;
}
_target = closestTarget;
}