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

RayCast() public static method

Performs a 2d physical raycast in world coordinates.
public static RayCast ( System.Vector2 worldCoordA, System.Vector2 worldCoordB, RayCastCallback callback = null ) : List
worldCoordA System.Vector2 The starting point.
worldCoordB System.Vector2 The desired end point.
callback RayCastCallback /// The callback that is invoked for each hit on the raycast. Note that the order in which each hit occurs isn't deterministic /// and may appear random. Return -1 to ignore the curret shape, 0 to terminate the raycast, data.Fraction to clip the ray for current hit, or 1 to continue. ///
return List
        public static List<RayCastData> RayCast(Vector2 worldCoordA, Vector2 worldCoordB, RayCastCallback callback = null)
        {
            if (callback == null) callback = Raycast_DefaultCallback;
            Vector2 fsWorldCoordA = PhysicsConvert.ToPhysicalUnit(worldCoordA);
            Vector2 fsWorldCoordB = PhysicsConvert.ToPhysicalUnit(worldCoordB);
            List<RayCastData> hitData = new List<RayCastData>();
            Scene.PhysicsWorld.RayCast(delegate(Fixture fixture, Vector2 pos, Vector2 normal, float fraction)
            {
                RayCastData data = new RayCastData(
                    fixture.UserData as ShapeInfo,
                    PhysicsConvert.ToDualityUnit(pos),
                    normal,
                    fraction);
                float result = callback(data);
                if (result >= 0.0f) hitData.Add(data);
                return result;
            }, fsWorldCoordA, fsWorldCoordB);
            hitData.StableSort((d1, d2) => (int)(1000000.0f * (d1.Fraction - d2.Fraction)));
            return hitData;
        }