/// <summary> /// Raycast (Closest Result) /// </summary> /// <param name="raio">The raio.</param> /// <param name="filter"></param> /// <param name="maxDistance">The max distance.</param> /// <returns></returns> public override SegmentInterceptInfo SegmentIntersect(Ray raio, Func <IPhysicObject, bool> filter, float maxDistance) { RayCastResult result; if (space.RayCast(raio, maxDistance, (a) => { return(filter(BepuEntityObject.RecoverIPhysicObjectFromBroadPhase(a))); }, out result)) { SegmentInterceptInfo resp = new SegmentInterceptInfo(); resp.Distance = Vector3.Distance(result.HitData.Location, raio.Position); resp.ImpactNormal = result.HitData.Normal; resp.ImpactPosition = result.HitData.Location; resp.PhysicObject = BepuEntityObject.RecoverIPhysicObjectFromBroadPhase(result.HitObject); return(resp); } return(null); }
public override void GetPhysicsObjectsInRange(Vector3 position, float distance, CullerConditionAvaliator <IPhysicObject, IObject> CullerAvaliator, List <IPhysicObject> resp) { resp.Clear(); List <BroadPhaseEntry> ent = new List <BroadPhaseEntry>(); space.BroadPhase.QueryAccelerator.GetEntries(new BoundingSphere(position, distance), ent); foreach (var item in ent) { IPhysicObject phyObj = BepuEntityObject.RecoverIPhysicObjectFromBroadPhase(item); if (phyObj != null) { if (CullerAvaliator(phyObj, phyObj.ObjectOwner)) { resp.Add(phyObj); } } } }
/// <summary> /// Gets the Iobjects in range. /// </summary> /// <param name="frustrum">The frustrum.</param> /// <param name="condition">The condition.</param> /// <param name="resp">The resp.</param> public void GetIObjectsInRange(BoundingFrustum frustrum, CullerConditionAvaliator <IPhysicObject, IObject> condition, List <IObject> resp) { resp.Clear(); List <BroadPhaseEntry> ent = new List <BroadPhaseEntry>(); space.BroadPhase.QueryAccelerator.GetEntries(frustrum, ent); foreach (var item in ent) { IPhysicObject phyObj = BepuEntityObject.RecoverIPhysicObjectFromBroadPhase(item); if (phyObj != null) { if (condition(phyObj, phyObj.ObjectOwner)) { resp.Add(phyObj.ObjectOwner); } } } }
/// <summary> /// Raycast (Multiples Results) /// </summary> /// <param name="raio">The raio.</param> /// <param name="filter">The filter.</param> /// <param name="maxDistance">The max distance.</param> /// <returns></returns> public List <SegmentInterceptInfo> SegmentIntersectMultiple(Ray raio, Func <IPhysicObject, bool> filter, float maxDistance) { List <SegmentInterceptInfo> rp = new List <SegmentInterceptInfo>(); List <RayCastResult> result = new List <RayCastResult>(); if (space.RayCast(raio, maxDistance, (a) => { return(filter(BepuEntityObject.RecoverIPhysicObjectFromBroadPhase(a))); }, result)) { for (int i = 0; i < result.Count; i++) { SegmentInterceptInfo resp = new SegmentInterceptInfo(); resp.Distance = Vector3.Distance(result[i].HitData.Location, raio.Position); resp.ImpactNormal = result[i].HitData.Normal; resp.ImpactPosition = result[i].HitData.Location; resp.PhysicObject = BepuEntityObject.RecoverIPhysicObjectFromBroadPhase(result[i].HitObject); rp.Add(resp); } } return(rp); }