本文整理汇总了C#中Project290.Physics.Dynamics.World.RayCast方法的典型用法代码示例。如果您正苦于以下问题:C# World.RayCast方法的具体用法?C# World.RayCast怎么用?C# World.RayCast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Project290.Physics.Dynamics.World
的用法示例。
在下文中一共展示了World.RayCast方法的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 void Cut(World world, Vector2 start, Vector2 end, float thickness)
{
List<Fixture> fixtures = new List<Fixture>();
List<Vector2> entryPoints = new List<Vector2>();
List<Vector2> exitPoints = new List<Vector2>();
//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) =>
{
fixtures.Add(f);
entryPoints.Add(p);
return 1;
}, start, end);
//Reverse the ray to get the exitpoints
world.RayCast((f, p, n, fr) =>
{
exitPoints.Add(p);
return 1;
}, end, start);
//We only have a single point. We need at least 2
if (entryPoints.Count + exitPoints.Count < 2)
return;
for (int i = 0; i < fixtures.Count; i++)
{
// can't cut circles yet !
if (fixtures[i].Shape.ShapeType != ShapeType.Polygon)
continue;
if (fixtures[i].Body.BodyType != BodyType.Static)
{
//Split the shape up into two shapes
Vertices first;
Vertices second;
SplitShape(fixtures[i], entryPoints[i], exitPoints[i], thickness, out first, out second);
//Delete the original shape and create two new. Retain the properties of the body.
if (SanityCheck(first))
{
Fixture firstFixture = FixtureFactory.CreatePolygon(world, first, fixtures[i].Shape.Density,
fixtures[i].Body.Position);
firstFixture.Body.Rotation = fixtures[i].Body.Rotation;
firstFixture.Body.LinearVelocity = fixtures[i].Body.LinearVelocity;
firstFixture.Body.AngularVelocity = fixtures[i].Body.AngularVelocity;
firstFixture.Body.BodyType = BodyType.Dynamic;
}
if (SanityCheck(second))
{
Fixture secondFixture = FixtureFactory.CreatePolygon(world, second, fixtures[i].Shape.Density,
fixtures[i].Body.Position);
secondFixture.Body.Rotation = fixtures[i].Body.Rotation;
secondFixture.Body.LinearVelocity = fixtures[i].Body.LinearVelocity;
secondFixture.Body.AngularVelocity = fixtures[i].Body.AngularVelocity;
secondFixture.Body.BodyType = BodyType.Dynamic;
}
world.RemoveBody(fixtures[i].Body);
}
}
}