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

PickShape() public method

Performs a physical picking operation and returns the shape in which the specified world coordinate is located in.
public PickShape ( System.Vector2 worldCoord ) : Duality.Components.Physics.ShapeInfo
worldCoord System.Vector2
return Duality.Components.Physics.ShapeInfo
        public ShapeInfo PickShape(Vector2 worldCoord)
        {
            if (this.body == null) return null;

            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)) return f.UserData as ShapeInfo;
            }
            return null;
        }

Usage Example

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