Is it possible to run a collision detection for a given object and space?
Velocity is not important, all I want to is the answer if the given object in the given position intersects anything within the space (and of course get relevant info if it is...)
Note: The object is not in the space, and I don't want it to be (unless there's a way to enable/disable it, but didn't see one), it's just a '1-time' check that happens here and then.
Hope I managed to make myself clear? :S
1-time Collision detection
Re: 1-time Collision detection
Yup, the process looks like this.Is it possible to run a collision detection for a given object and space?
First, use the bounding box of the object in question to query the broad phase. The given list will be filled with any BroadPhaseEntry objects which have bounding boxes which overlap the bounding shape.
Then, create pairs between those BroadPhaseEntry objects and your object's BroadPhaseEntry. If your object is an Entity, you can get its associated BroadPhaseEntry from the entity.CollisionInformation property (it is the collision proxy of the entity). StaticMeshes, Terrains, and InstancedMeshes all inherit from BroadPhaseEntry (through inherting Collidable). The NarrowPhaseHelper can help like so:Space.BroadPhase.QueryAccelerator.GetEntries(boundingBox, entriesList);
Code: Select all
var pair = NarrowPhaseHelper.GetPair(yourObjectEntry, entryFromBroadPhaseQuery);
When a pair becomes irrelevant, its CleanUp method should be called and it should be given back to the factory that spawned it:
Code: Select all
pair.CleanUp();
pair.Factory.GiveBack(pair);
Re: 1-time Collision detection
Hmm... can I use collision events with that? I can't seem to catch events that way. Maybe I'm doing something wrong?
I don't catch any events for the cylinder...
I tried doing it without events (as you explained), and It seems I catch collisions, but the number of collisions does not match the real one.
I tried updating more than 0 (though I really don't need to) and it's the same.
BTW, I noticed there are two identical classes: Contact and ContactData (both in namespace BEPUphysics.CollisionTests).
You might wanna get rid of one of them...
As always, thanks for your help.
Code: Select all
IList<BroadPhaseEntry> overlaps = new List<BroadPhaseEntry>();
space.BroadPhase.QueryAccelerator.GetEntries(Cylinder.CollisionInformation.BoundingBox, overlaps);
foreach (var entry in overlaps)
{
var pair = NarrowPhaseHelper.GetPair(Cylinder.CollisionInformation, entry);
pair.UpdateCollision(0);
pair.CleanUp();
pair.Factory.GiveBack(pair);
}
I tried doing it without events (as you explained), and It seems I catch collisions, but the number of collisions does not match the real one.
Code: Select all
//This goes inside the last loop
var collidablePair = pair as CollidablePairHandler;
if (collidablePair != null)
{
foreach (var contactInfo in collidablePair.Contacts)
{
var contact = contactInfo.Contact;
if (contact.PenetrationDepth >= 0f)
{
//Do something...
}
}
}
BTW, I noticed there are two identical classes: Contact and ContactData (both in namespace BEPUphysics.CollisionTests).
You might wanna get rid of one of them...
As always, thanks for your help.
Re: 1-time Collision detection
Deferred events cannot be used in such isolated queries. Any collision event which has a past tense name requires a deferred event dispatcher to be hooked up. You can, however, use present-tense collision events. Such 'immediate' events are called directly from inside the collision handler. More information can be found here: http://bepuphysics.codeplex.com/wikipag ... umentationHmm... can I use collision events with that? I can't seem to catch events that way. Maybe I'm doing something wrong?
In this kind of use case, it's typically easier to analyze the contacts list directly rather than hooking up indirect contact events.
The contacts list is the 'real' representation of the collision state as far as the narrow phase collision detection system is concerned. What does not match?I tried doing it without events (as you explained), and It seems I catch collisions, but the number of collisions does not match the real one.
While they have the same fields, they are not functionally identical. One is a class and is designed to persist. The other is a struct and is designed to be a snapshot of the state of a contact or a contact candidate not yet accepted into the main manifold.BTW, I noticed there are two identical classes: Contact and ContactData (both in namespace BEPUphysics.CollisionTests).
You might wanna get rid of one of them...
Re: 1-time Collision detection
Hey, sorry for the late reply, been busy with some stuff...
Anyways, what I meant is that this method doesn't seem to take into account my static meshes...
But I think I'm over-doing things.... I don't want to write all that code myself, that's why I'm using your library!
Is there any way to insert a "ghost" shape (one that does not interact) into space and check for collisions?
This way, every time I need to check for collision I'll do this:
space.Add(myGhostShape)
//testForCollision???
space.Remove(myGhostShape)
I just wonder if I'll be able to test for collisions using events this way (since, for example, the object may be inserted inside another object, and the collision event won't fire since they didn't actually collided).
Otherwise, what other ways are there for checking collisions (except the already discussed one)?
Any thoughts?
Anyways, what I meant is that this method doesn't seem to take into account my static meshes...
But I think I'm over-doing things.... I don't want to write all that code myself, that's why I'm using your library!

Is there any way to insert a "ghost" shape (one that does not interact) into space and check for collisions?
This way, every time I need to check for collision I'll do this:
space.Add(myGhostShape)
//testForCollision???
space.Remove(myGhostShape)
I just wonder if I'll be able to test for collisions using events this way (since, for example, the object may be inserted inside another object, and the collision event won't fire since they didn't actually collided).
Otherwise, what other ways are there for checking collisions (except the already discussed one)?
Any thoughts?
Re: 1-time Collision detection
It should not miss anything; it's basically doing a query-formatted version of what the engine does internally.Anyways, what I meant is that this method doesn't seem to take into account my static meshes...
A Space.Update() must occur between the Add and Remove in order for the collisions to be tested. So, if the ghost shape is kept within the Space rather than being added/removed around each individual query, it would work.But I think I'm over-doing things.... I don't want to write all that code myself, that's why I'm using your library!
Is there any way to insert a "ghost" shape (one that does not interact) into space and check for collisions?
This way, every time I need to check for collision I'll do this:
space.Add(myGhostShape)
//testForCollision???
space.Remove(myGhostShape)
Yes. Immediate events would work with the other query method too. (Though again, it's often more convenient for queries to just look directly at the contact list instead of using events.)I just wonder if I'll be able to test for collisions using events this way
CollisionRules can be used to turn off solving for the object (e.g. entity.CollisionInformation.CollisionRules.Personal = CollisionRules.NoSolver;).
Any method which ends up creating or using pairs (internally or explicitly) can be used to check collisions.Otherwise, what other ways are there for checking collisions (except the already discussed one)?
Any thoughts?
For objects which perform frequent similar queries, keeping the detector 'ghost' object in the space is generally the easiest and individual queries are cheaper since they are performed as a natural part of the pipeline.
For objects which perform rare, individually unique queries, using a one-shot pair collection analysis like the character is a better fit and is a bit faster since it avoids keeping objects in the Space unnecessarily.