public RayCast ( |
||
output | The ray-cast results. | |
input | The ray-cast input parameters. | |
childIndex | int | Index of the child. |
return | bool |
/// <summary> /// Ray-cast the world for all fixtures in the path of the ray. Your callback /// controls whether you get the closest point, any point, or n-points. /// The ray-cast ignores shapes that contain the starting point. /// /// Inside the callback: /// return -1: ignore this fixture and continue /// return 0: terminate the ray cast /// return fraction: clip the ray to this point /// return 1: don't clip the ray and continue /// </summary> /// <param name="callback">A user implemented callback class.</param> /// <param name="point1">The ray starting point.</param> /// <param name="point2">The ray ending point.</param> public void RayCast(RayCastCallback callback, Vector2 point1, Vector2 point2) { RayCastInput input = new RayCastInput(); input.MaxFraction = 1.0f; input.Point1 = point1; input.Point2 = point2; this.ContactManager.BroadPhase.RayCast((rayCastInput, proxyId) => { FixtureProxy proxy = this.ContactManager.BroadPhase.GetProxy(proxyId); Fixture fixture = proxy.Fixture; int index = proxy.ChildIndex; RayCastOutput output; bool hit = fixture.RayCast(out output, ref rayCastInput, index); if (hit) { float fraction = output.Fraction; Vector2 point = (1.0f - fraction) * rayCastInput.Point1 + fraction * rayCastInput.Point2; return(callback(fixture, point, output.Normal, fraction)); } return(rayCastInput.MaxFraction); //input.MaxFraction; }, ref input); }
private float RayCastCallbackWrapper(ref RayCastInput input, int proxyId) { FixtureProxy proxy = ContactManager.BroadPhase.GetUserData <FixtureProxy>(proxyId); Fixture fixture = proxy.Fixture; int index = proxy.ChildIndex; RayCastOutput output; bool hit = fixture.RayCast(out output, ref input, index); if (hit) { float fraction = output.Fraction; Vector2 point = (1.0f - fraction) * input.Point1 + fraction * input.Point2; return(_rayCastCallback(fixture, point, output.Normal, fraction)); } return(input.MaxFraction); }