本文整理汇总了C#中Duality.Components.Physics.RigidBody.PickShapes方法的典型用法代码示例。如果您正苦于以下问题:C# RigidBody.PickShapes方法的具体用法?C# RigidBody.PickShapes怎么用?C# RigidBody.PickShapes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Duality.Components.Physics.RigidBody
的用法示例。
在下文中一共展示了RigidBody.PickShapes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PickShapes
private List<ShapeInfo> PickShapes(RigidBody body, Vector2 worldCoord, Vector2 worldSize)
{
Rect worldRect = new Rect(worldCoord.X, worldCoord.Y, worldSize.X, worldSize.Y);
// Do a physical picking operation
List<ShapeInfo> result = body.PickShapes(worldCoord, worldSize);
// Special case for LoopShapes, because they are by definition unpickable
foreach (LoopShapeInfo loop in body.Shapes.OfType<LoopShapeInfo>())
{
bool hit = false;
for (int i = 0; i < loop.Vertices.Length; i++)
{
Vector2 worldV1 = body.GameObj.Transform.GetWorldPoint(loop.Vertices[i]);
Vector2 worldV2 = body.GameObj.Transform.GetWorldPoint(loop.Vertices[(i + 1) % loop.Vertices.Length]);
hit = hit || MathF.LinesCross(
worldRect.TopLeft.X,
worldRect.TopLeft.Y,
worldRect.TopRight.X,
worldRect.TopRight.Y,
worldV1.X, worldV1.Y, worldV2.X, worldV2.Y);
hit = hit || MathF.LinesCross(
worldRect.TopLeft.X,
worldRect.TopLeft.Y,
worldRect.BottomLeft.X,
worldRect.BottomLeft.Y,
worldV1.X, worldV1.Y, worldV2.X, worldV2.Y);
hit = hit || MathF.LinesCross(
worldRect.BottomRight.X,
worldRect.BottomRight.Y,
worldRect.TopRight.X,
worldRect.TopRight.Y,
worldV1.X, worldV1.Y, worldV2.X, worldV2.Y);
hit = hit || MathF.LinesCross(
worldRect.BottomRight.X,
worldRect.BottomRight.Y,
worldRect.BottomLeft.X,
worldRect.BottomLeft.Y,
worldV1.X, worldV1.Y, worldV2.X, worldV2.Y);
hit = hit || worldRect.Contains(worldV1) || worldRect.Contains(worldV2);
if (hit) break;
}
if (hit)
{
result.Add(loop);
continue;
}
}
return result;
}
示例2: PickShapes
private List<ShapeInfo> PickShapes(RigidBody body, Vector2 worldCoord, Vector2 worldSize)
{
Rect worldRect = new Rect(worldCoord.X, worldCoord.Y, worldSize.X, worldSize.Y);
// Do a physical picking operation
List<ShapeInfo> result = body.PickShapes(worldCoord, worldSize);
// Special case for Loop- and ChainShapes, because they are by definition unpickable
foreach (ShapeInfo shape in body.Shapes)
{
LoopShapeInfo loop = shape as LoopShapeInfo;
ChainShapeInfo chain = shape as ChainShapeInfo;
Vector2[] vertices = null;
if (loop != null) vertices = loop.Vertices;
if (chain != null) vertices = chain.Vertices;
if (vertices != null && IsOutlineBoxIntersection(body.GameObj.Transform, vertices, worldRect))
{
result.Add(shape);
continue;
}
}
return result;
}