private xna.Vector3 SingleRaycast(xna.Vector3 from, xna.Vector3 to) { var rayResult = PhysicsEngine.Raycast2D( RaycastProperties.FromSingleRay( TypeConversion.FromXNA(from), TypeConversion.FromXNA(to) ) ); RaycastResult result = null; // // !Warning! this code is relying on the Raycast operation being // fundementally synchronous, wrapped in an async API. // if (rayResult.Test(out result)) { if (result.ImpactPoints.Count == 1) { var impact = result.ImpactPoints[0].Position; return(new xna.Vector3( impact.X, impact.Y, impact.Z )); } } return(to); }
private void SingleRaycastAsync(xna.Vector3 from, xna.Vector3 to, int index, Port <OcclusionRay> resultPort) { var rayResult = PhysicsEngine.Raycast2D( RaycastProperties.FromSingleRay( TypeConversion.FromXNA(from), TypeConversion.FromXNA(to) ) ); Activate( Arbiter.Receive(false, rayResult, delegate(RaycastResult result) { xna.Vector3 hitPoint; if (result.ImpactPoints.Count == 1) { var impact = result.ImpactPoints[0].Position; hitPoint = new xna.Vector3( impact.X, impact.Y, impact.Z ); } else { hitPoint = to; } float distance = (hitPoint - to).Length(); resultPort.Post( new OcclusionRay { Index = index, Point = from, Impact = hitPoint, Distance = distance, Occluded = distance > OcclusionThreshold, Run = 0 } ); } ) ); }