Duality.Components.Physics.RigidBody.PickShapes C# (CSharp) Method

PickShapes() public method

Performs a physical picking operation and returns the shapes that intersect the specified world coordinate.
public PickShapes ( System.Vector2 worldCoord ) : List
worldCoord System.Vector2
return List
        public List<ShapeInfo> PickShapes(Vector2 worldCoord)
        {
            if (this.body == null) return new List<ShapeInfo>();

            List<ShapeInfo> picked = new List<ShapeInfo>();
            Vector2 fsWorldCoord = PhysicsConvert.ToPhysicalUnit(worldCoord);

            for (int i = 0; i < this.body.FixtureList.Count; i++)
            {
                Fixture f = this.body.FixtureList[i];
                if (f.TestPoint(ref fsWorldCoord)) picked.Add(f.UserData as ShapeInfo);
            }

            return picked;
        }

Same methods

RigidBody::PickShapes ( System.Vector2 worldCoord, System.Vector2 size ) : List

Usage Example

        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;
        }
All Usage Examples Of Duality.Components.Physics.RigidBody::PickShapes