Box2DX.Dynamics.World.RaycastOne C# (CSharp) Method

RaycastOne() public method

Performs a raycast as with Raycast, finding the first intersecting shape.
public RaycastOne ( Segment segment, float &lambda, Vec2 &normal, bool solidShapes, object userData ) : Shape
segment Segment Defines the begin and end point of the ray cast, from p1 to p2. /// Use Segment.Extend to create (semi-)infinite rays.
lambda float Returns the hit fraction. You can use this to compute the contact point /// p = (1 - lambda) * segment.p1 + lambda * segment.p2.
normal Vec2 Returns the normal at the contact point. If there is no intersection, the normal is not set.
solidShapes bool Determines if shapes that the ray starts in are counted as hits.
userData object
return Shape
        public Shape RaycastOne(Segment segment, out float lambda, out Vec2 normal, bool solidShapes, object userData)
        {
            lambda = 0;
            normal = new Vec2(0, 0);

            int maxCount = 1;
            Shape[] shape = new Shape[maxCount];

            int count = Raycast(segment, shape, maxCount, solidShapes, userData);

            if (count == 0)
                return null;

            Box2DXDebug.Assert(count == 1);

            //Redundantly do TestSegment a second time, as the previous one's results are inaccessible

            XForm xf = shape[0].GetBody().GetXForm();
            shape[0].TestSegment(xf, out lambda, out normal, segment, 1);
            //We already know it returns true
            return shape[0];
        }