Query whether a co-ordinate is occupied in Space

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
al9191
Posts: 68
Joined: Wed Nov 16, 2011 11:19 pm

Query whether a co-ordinate is occupied in Space

Post by al9191 »

In the space object I can access the entities and then loop through them and get all the points contained within them, and then try and work out if a certain co-ordinate is taken. (I need to do this in order to do path-finding.)

However, is there a way using the BEPU API to test a space with a co-ordinate to see if it is occupied by something?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Query whether a co-ordinate is occupied in Space

Post by Norbo »

The Space.BroadPhase.QueryAccelerator supports volume queries which could be used. A tiny BoundingBox could be checked against every other object in the space, returning all AABB overlaps.

Since the query accelerator only considers bounding boxes, additional tests would be necessary if you wanted to test the point's position against the geometry of the shapes themselves. One option would be something like the CharacterController's QueryManager, which performs pairwise tests for contacts with an overlapped set of objects. The query object could be a small sphere representing the point. This leverages the NarrowPhase and NarrowPhaseHelper, so the complexity of different entity types or static meshes is abstracted away.
al9191
Posts: 68
Joined: Wed Nov 16, 2011 11:19 pm

Re: Query whether a co-ordinate is occupied in Space

Post by al9191 »

How do you use the QueryAccelerator to query a position?
Is there any demos/samples that do anything like this?

Also, what is the CharacterController and it's QueryManager and can't find them in the API or the Sample demos?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Query whether a co-ordinate is occupied in Space

Post by Norbo »

How do you use the QueryAccelerator to query a position?
Is there any demos/samples that do anything like this?
There is no demo that does exactly this, but using the QueryAccelerator is quite simple. Just use the Space.BroadPhase.QueryAccelerator.GetOverlaps method. There is no overload that accepts only a point, so instead create a small BoundingSphere or BoundingBox that represents the point.

The result of calling that method will be a list of BroadPhaseEntry objects. StaticMesh, InstancedMesh, Terrain, and all the Entity.CollisionInformation objects are BroadPhaseEntries.
Also, what is the CharacterController and it's QueryManager and can't find them in the API or the Sample demos?
The CharacterController and its QueryManager can be found in the BEPUphysicsDemos in the main source download. It is in the BEPUphysicsDemos project in the folder Alternate Movement/Character. The CharacterController is used in the demos for FPS-like control. You can run around, jump, step up and down, crouch, and so on. The QueryManager is used by the CharacterController to do shape queries for crouching or stepping, among other things.
al9191
Posts: 68
Joined: Wed Nov 16, 2011 11:19 pm

Re: Query whether a co-ordinate is occupied in Space

Post by al9191 »

Norbo wrote: There is no demo that does exactly this, but using the QueryAccelerator is quite simple. Just use the Space.BroadPhase.QueryAccelerator.GetOverlaps method. There is no overload that accepts only a point, so instead create a small BoundingSphere or BoundingBox that represents the point.
Ok thanks for the help this is exactly what I need. The QueryAccelerator only seems to have a method called GetEntries and it takes a bounding shape argument and an IList argument but returns nothing. I have tried passing in an IList but it is abstract class so can't instansiate one to pass in. Am I doing it right?

Code: Select all

IList<BroadPhaseEntry> list;
BoundingSphere sphere = new BoundingSphere(point, accuracy);
space.BroadPhase.QueryAccelerator.GetEntries(sphere, list);
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Query whether a co-ordinate is occupied in Space

Post by Norbo »

The QueryAccelerator only seems to have a method called GetEntries
Woops, sorry- yes, it's GetEntries, not GetOverlaps :)
it takes a bounding shape argument and an IList argument but returns nothing. I have tried passing in an IList but it is abstract class so can't instansiate one to pass in. Am I doing it right?
The GetEntries method will dump the entries it finds overlapping the given bounding volume into the IList<BroadPhaseEntry> you provide. Any type which implements IList<BroadPhaseEntry> will work. So List<BroadPhaseEntry> could be used.
al9191
Posts: 68
Joined: Wed Nov 16, 2011 11:19 pm

Re: Query whether a co-ordinate is occupied in Space

Post by al9191 »

Ok I am using the right method then! Thanks very much.

I will carry on with this approach for now. :).

Thanks.
Post Reply