本文整理汇总了C#中FarseerPhysics.Dynamics.World.FixtureCut方法的典型用法代码示例。如果您正苦于以下问题:C# World.FixtureCut方法的具体用法?C# World.FixtureCut怎么用?C# World.FixtureCut使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FarseerPhysics.Dynamics.World
的用法示例。
在下文中一共展示了World.FixtureCut方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Cut
/// <summary>
/// This is a high-level function to cuts fixtures inside the given world, using the start and end points.
/// Note: We don't support cutting when the start or end is inside a shape.
/// </summary>
/// <param name="world">The world.</param>
/// <param name="start">The startpoint.</param>
/// <param name="end">The endpoint.</param>
/// <param name="thickness">The thickness of the cut</param>
public static Vector2 Cut(World world, Vector2 start, Vector2 end, float thickness, Category collisionCategories = Category.None)
{
// The left side of the cut will remain part of the existing body;
// the right side will be made into a new body
List<Fixture> fixtures = new List<Fixture>();
List<Vector2> entryPoints = new List<Vector2>();
List<Vector2> exitPoints = new List<Vector2>();
List<RayCastResult> results = new List<RayCastResult>();
//float blockingFraction = float.MaxValue;
Vector2 stoppingPoint = end;
//We don't support cutting when the start or end is inside a shape.
//if (world.TestPoint(start) != null || world.TestPoint(end) != null)
// return;
//Get the entry points
world.RayCast((f, p, n, fr) =>
{
RayCastResult r = new RayCastResult();
r.f = f;
r.p = p;
r.fr = fr;
results.Add(r);
return 1;
}, start, end);
results = results.OrderBy(p => p.fr).ToList();
foreach (RayCastResult r in results)
{
if ((r.f.CollisionCategories & collisionCategories) != Category.None)
{
stoppingPoint = r.p;
break;
}
if (!r.f.TestPoint(ref end))
{
if (world.FixtureCut != null)
world.FixtureCut(r.f);
fixtures.Add(r.f);
entryPoints.Add(r.p);
}
}
//Reverse the ray to get the exitpoints
world.RayCast((f, p, n, fr) =>
{
if (fixtures.Contains(f))
{
exitPoints.Add(p);
}
return 1;
}, end, start);
Debug.Assert(entryPoints.Count == exitPoints.Count && entryPoints.Count == fixtures.Count);
//Fixture containsEnd = world.TestPoint(end);
//if (containsEnd != null)
//{
// entryPoints.RemoveAt(0);
// fixtures.Remove(containsEnd);
//}
//Fixture containsStart = world.TestPoint(start);
//if (containsStart != null)
//{
// exitPoints.RemoveAt(exitPoints.Count - 1);
// fixtures.Remove(containsStart);
//}
//We only have a single point. We need at least 2
if (entryPoints.Count + exitPoints.Count < 2)
return stoppingPoint;
var query =
(from fix in fixtures
select fix.Body).Distinct();
foreach (Body b in query)
{
if (b == null || b.BodyType == BodyType.Static)
continue;
//.........这里部分代码省略.........