Scan area for intersecting shapes.

Post Reply
Crayder
Posts: 15
Joined: Mon Aug 10, 2015 10:18 pm

Scan area for intersecting shapes.

Post by Crayder »

Hello.

I've got a pretty simple question, how can I test whether there are any shapes that intersect a given area? The area will be defined as a prism, possibly rotated.

What I'm trying to do is test whether there are any obstacles in front of a vehicle. The vehicles are many sizes, all which I have. The world is 3 dimensional. The vehicle is not tracked by Bullet, but I have the position and rotation (in quat) for input. If any more extra information is needed let me know, I just feel like this is simpler than I'm making it to be.

EDIT: I was thinking of using contactTest with a vehicle-sized 'box' shape, but wouldn't that only test the faces of the box? I need to detect everything that touches the box and everything inside the box.
Last edited by Crayder on Fri Mar 18, 2016 2:21 am, edited 1 time in total.
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: Scan area for intersecting shapes.

Post by Basroil »

You can always make a ghost shape (same shape you want to test, but doesn't really collide) and see if there's collision. If you don't care too much about exact quality you might even be able to just use broadphase, which will likely be faster
Crayder
Posts: 15
Joined: Mon Aug 10, 2015 10:18 pm

Re: Scan area for intersecting shapes.

Post by Crayder »

Basroil wrote:You can always make a ghost shape (same shape you want to test, but doesn't really collide) and see if there's collision. If you don't care too much about exact quality you might even be able to just use broadphase, which will likely be faster
Yeah but would that work with objects that are encompassed by the box? Like, the faces of the box wouldn't touch those objects since it is completely inside, so would it be detected? The system I need would need to be able to detect everything inside the solid box.

The ghost object would work with my contactTest idea too right? So basically I was on the same track you're on but I'm not sure if it'll work as described above.

EDIT: Just to confirm, yes the shapes can be inside each other. The entire base world is static.
Crayder
Posts: 15
Joined: Mon Aug 10, 2015 10:18 pm

Re: Scan area for intersecting shapes.

Post by Crayder »

Bump
kermado
Posts: 20
Joined: Tue Jan 12, 2016 11:20 am

Re: Scan area for intersecting shapes.

Post by kermado »

You should get contact points when one shape intersects with another, either partially or fully. From the btPersistentManifold you can get the pair of collision objects involved. Unless I have misunderstood what you're after, this is really very simple.

You can use contactTest, which executes outside of Bullet's simulation step. To perform the detection inside of the physics step you can use a btGhostObject (which is the preferred option for performance reasons), or alternatively you can use a btCollisionObject and set the contact point's distance property to be some large value so that Bullet doesn't create the contact constraint.
hyyou
Posts: 96
Joined: Wed Mar 16, 2016 10:11 am

Re: Scan area for intersecting shapes.

Post by hyyou »

I used btRigidBody & disable collision response :-

body->setCollisionFlags(
(
body->getCollisionFlags() |
btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK
) | btCollisionObject::CF_NO_CONTACT_RESPONSE
)

GhostBody is a bit harder to use (at least for me) and using RigidBody alone is easier for Bullet encapsulation.

(my old wrong statement->) It is pity that Bullet don't have AABB query like Box2D.
Edit: Thank Flix (the following post) to correct me, Bullet seem to have AABB.
Last edited by hyyou on Thu Mar 24, 2016 4:08 pm, edited 1 time in total.
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Scan area for intersecting shapes.

Post by Flix »

hyyou wrote:It is pity that Bullet don't have AABB query like Box2D.
I haven't read the whole series of posts, but maybe you can try:

Code: Select all

btDbvtBroadphase::aabbTest (const btVector3 &aabbMin, const btVector3 &aabbMax, btBroadphaseAabbCallback &callback)
P.S. I have never tried it and I don't know if it works and/or if it's suitable for your case.
Crayder
Posts: 15
Joined: Mon Aug 10, 2015 10:18 pm

Re: Scan area for intersecting shapes.

Post by Crayder »

kermado wrote:You should get contact points when one shape intersects with another, either partially or fully. From the btPersistentManifold you can get the pair of collision objects involved. Unless I have misunderstood what you're after, this is really very simple.

You can use contactTest, which executes outside of Bullet's simulation step. To perform the detection inside of the physics step you can use a btGhostObject (which is the preferred option for performance reasons), or alternatively you can use a btCollisionObject and set the contact point's distance property to be some large value so that Bullet doesn't create the contact constraint.
So... If I created a box object... Then positioned it to the area I need to test (position, scaled, and rotated)...

Could I test whether any other world object is either colliding with any of the box's faces or is within the box completely?

Basically I'm not sure whether contactTest tests the inside of the box too. The world objects that need to be tested may or may not be completely inside the box.
kermado
Posts: 20
Joined: Tue Jan 12, 2016 11:20 am

Re: Scan area for intersecting shapes.

Post by kermado »

Yes, you should get contact points even when the other object's collision shape is completely inside of your box collision shape. To be clear, the collision detection detects when pairs of shapes are overlapping/intersecting. This includes cases where one shape completely encompasses another.
Post Reply