Raycasting efficiency?
Raycasting efficiency?
Just getting to grips with raycasting in bepu using space.RayCast and I'm seeing that there are quite a few overloads for it. I'm wondering what the most efficient method is for example, if I know my target body is always less than X metres away? Could you also give me a quick example of how the filtering works. For example, I'm using an RTS type camera that adjusts to the height of the terrain beneath it. How do I have a raycast that ignores the other bodies that are on the terrain and just returns the results for the terrain beneath them?
Re: Raycasting efficiency?
If you know something must be less than a certain distance away, use an overload which accepts a maximumLength parameter. Note that the length is specified in units of the ray direction's length. So, if the ray direction is 10 units long, a maximumLength of 5 would mean the ray can travel up to 50 units.
An example of the filter can be found in the BEPUphysicsDemos Camera class. The call looks like this:
The delegate rayCastFilter is created from the function:
This filter ignores the entity the camera is following and ignores intangible objects (as defined by their personal collision rule.)
An example of the filter can be found in the BEPUphysicsDemos Camera class. The call looks like this:
Code: Select all
if (entityToChase.Space.RayCast(new Ray(lookAt, backwards), distanceToTarget, rayCastFilter, out result))...
Code: Select all
bool RayCastFilter(BroadPhaseEntry entry)
{
return entry != entityToChase.CollisionInformation && (entry.CollisionRules.Personal <= CollisionRule.Normal);
}
If you already know the specific object you'd like to ray cast against and you want to ignore all other objects, you can skip the Space.RayCast entirely. Instead, use that specific object's ray cast method. All entities have an EntityCollidable stored within the entity.CollisionInformation property; that EntityCollidable, like all Collidables, has a RayCast method. Terrains and other static geometry, being Collidables themselves, have RayCast methods as well.How do I have a raycast that ignores the other bodies that are on the terrain and just returns the results for the terrain beneath them?
Re: Raycasting efficiency?
Excellent. Just wanted to check it was working before thanking you! Haven't got round to needing the filter yet but the terrain's working just fine. (the BEPU logo on my game's splashscreen keeps getting bigger)