dilating/expanding a shape in a single direction

gjaegy
Posts: 178
Joined: Fri Apr 18, 2008 2:20 pm

dilating/expanding a shape in a single direction

Post by gjaegy »

Hi,

I am not sure how I could solve the following problem.

I have two shapes:
- a box shape
- a convex decomposition shape (using ConvexBuilder)

Basically, I want to test wether the box shape (shown in blue) collide with the convex decomposition shape (shown in black below) + some dilatation in front of the object (shown in red).

I don't need the collision points or any information other than a boolean (collide or not).

Image

I am not sure how I can handle this. I thought I could use btCollisionWorld::convexSweepTest(), however, this method does perform the test on the whole world, not between two shapes.

I have also tried to find a solution using btGjkPairDetector::getClosestPoints(), but I couldn't find any way to achieve this.

Any help would be appreciated !

Thanks.
Greg
Last edited by gjaegy on Thu Apr 12, 2012 6:34 am, edited 1 time in total.
gjaegy
Posts: 178
Joined: Fri Apr 18, 2008 2:20 pm

Re: collision between a box shape and a dilated shape

Post by gjaegy »

Maybe there is no way to achieve this ?
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: dilating/expanding a shape in a single direction

Post by Flix »

gjaegy wrote:I want to test wether the box shape (shown in blue) collide with the convex decomposition shape (shown in black below) + some dilatation in front of the object (shown in red).
I don't need the collision points or any information other than a boolean (collide or not).
I've never used btCollisionWorld::convexSweepTest() so far, but I think it can probably be customized (with collision masks or custom 'needsCollision' like methods) to reduce the perfomance penalty of testing against the whole world. The problem is that your shape is NOT convex, so I don't think you can't use this method with compound shapes.

You can use btCollisionWorld::contactPairTest:

Code: Select all

  ///contactTest performs a discrete collision test between two collision objects and calls the resultCallback if overlap if detected.
   ///it reports one or more contact points (including the one with deepest penetration)
   void   btCollisionWorld::contactPairTest(btCollisionObject* colObjA, btCollisionObject* colObjB, ContactResultCallback& resultCallback);
It should be possible to create the 'moved' btCollisionObject on the stack easily with just its btCollisionShape and a world transform (it doesn't need to be added to the world).
The problem in this case is that it will work in the case of the image you've attached, but in the general case it won't work as expected, because you need an 'enlarged' collision shape of the plane to do the test, and I don't think it's easy to create it on the fly (you could try scaling (a 'static' copy of the) the btCompoundShape and adjust its position accordingly, but I don't think that btCompoundShape::setLocalScaling(...) is reliable enough...(I usually avoid using it)).

So in short I think a good solution to your problem would be something like a btCollisionWorld::compoundShapeSweepPairTest(), but it does not exist in Bullet as far as I know :roll:
gjaegy
Posts: 178
Joined: Fri Apr 18, 2008 2:20 pm

Re: dilating/expanding a shape in a single direction

Post by gjaegy »

Flix,

thanks a lot for your answer, really appreciated (I mean, the fact that you've answered, not your answer saying there is no solution :lol:).

I guess I will have to let my customer know, there is no way to achieve what he asks for :(

Thanks once again.
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: dilating/expanding a shape in a single direction

Post by Flix »

gjaegy wrote: there is no way to achieve what he asks for
Still, if the sweep-test can be replaced by a collision test with a constant scaled version of the plane (i.e. the enlargement is the same at each test) I would try creating (and caching) a scaled version of the plane (better doing that manually, without using btCompoundShape::setLocalScaling(...): also using an accurate "ad-hoc" sweep-test-like shape would be better) and using btCollisionWorld::contactPairTest(...).
If this is not the case you could approximate the plane shape with a convex shape and use a proper btCollisionWorld::convexSweepTest().

However it all depends on the program you're making :) .
gjaegy
Posts: 178
Joined: Fri Apr 18, 2008 2:20 pm

Re: dilating/expanding a shape in a single direction

Post by gjaegy »

I forgot to mention that the dilatation is in the direction of the aircraft move... Hence fully dynamic, not sure I can affort rebuilding the convex shape decomposition process each frame...
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: dilating/expanding a shape in a single direction

Post by Flix »

gjaegy wrote:I forgot to mention that the dilatation is in the direction of the aircraft move... Hence fully dynamic, not sure I can affort rebuilding the convex shape decomposition process each frame...
No, you shouldn't do that... anyway if the dilatation is constant at each simulation step (but I guess it should depend on the plane speed) you could reuse the same dilatated shape, position it correctly through a new btRigidBody (not added to the world, it can be cached or built on the stack each time) and perform a contactPairTest between the body and the blue box in your image.

Alternatively (if the dilatation is not constant) you can perform multiple convex sweep tests each step (one per each child shape of your plane compound shape) and get an accurate result.
However it would be much easier and fast, to perform a single convex sweep test with the convex hull shape of the plane (a btConvexHullShape made with all the vertices of the plane mesh),even if the result shouldn't be so accurate.
gjaegy
Posts: 178
Joined: Fri Apr 18, 2008 2:20 pm

Re: dilating/expanding a shape in a single direction

Post by gjaegy »

Yes, the dilatation changes according to the speed of the aircraft.

Interesting Flix, thanks for that !