public PickShape ( System.Vector2 worldCoord ) : Duality.Components.Physics.ShapeInfo | ||
worldCoord | System.Vector2 | |
Résultat | Duality.Components.Physics.ShapeInfo |
private ShapeInfo PickShape(RigidBody body, Vector2 worldCoord) { // Special case for LoopShapes, because they are by definition unpickable foreach (LoopShapeInfo loop in body.Shapes.OfType<LoopShapeInfo>()) { 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]); float dist = MathF.PointLineDistance(worldCoord.X, worldCoord.Y, worldV1.X, worldV1.Y, worldV2.X, worldV2.Y); if (dist < 5.0f) return loop; } } // Do a physical picking operation return body.PickShape(worldCoord); }
private ShapeInfo PickShape(RigidBody body, Vector2 worldCoord) { // Special case for Loop- and ChainShapes, because they are by definition unpickable Rect worldRect = Rect.Align(Alignment.Center, worldCoord.X, worldCoord.Y, 10.0f, 10.0f); 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)) return shape; } // Do a physical picking operation return body.PickShape(worldCoord); }