Terrain collision and btBvhTriangleMeshShape

toastie
Posts: 8
Joined: Tue Jun 17, 2008 10:00 pm

Terrain collision and btBvhTriangleMeshShape

Post by toastie »

Hello!

I am using Bullet for collision detection and so far I've been using it only with btBoxShape, where I would only use one of the contacts of one of the manifolds and then translate the colliding shape the colliding distance along the collision vector and it's been working well.

Now I'm trying to setup a terrain using btBvhTriangleMeshShape using the same system, now averaging out all the collision vectors and distances into one. So I'm testing with a large box lowering down onto the terrain and when it comes in contact with it, it begins to shift around like crazy, I'm assuming because it gets all kinds of collision vectors and distances and averaging them out doesn't do the trick.

So my question is: What would be the correct way of checking the collision vectors/distances in such a scenario so that I could automatically make the other shape stop when it touches the terrain?
toastie
Posts: 8
Joined: Tue Jun 17, 2008 10:00 pm

Re: Terrain collision and btBvhTriangleMeshShape

Post by toastie »

Ahmm... I'm supposed to be using rays, aren't I?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Terrain collision and btBvhTriangleMeshShape

Post by Erwin Coumans »

You can use the btCollisionWorld::convexSweepTest to detect the first hit, given a non-penetrating begin transform and end transform.

See Bullet/Demos/ConcaveConvexcastDemo.
Hope this helps,
Erwin
toastie
Posts: 8
Joined: Tue Jun 17, 2008 10:00 pm

Re: Terrain collision and btBvhTriangleMeshShape

Post by toastie »

Thanks Erwin, that works great!

I have one more question though. How do I get the penetration depth from convexSweepTest? ClosestConvexResultCallback doesn't seem to have it. Or am I missing something?

I can see it was added at some point, but I can't figure out how to actually get the depth.

Thank you!
toastie
Posts: 8
Joined: Tue Jun 17, 2008 10:00 pm

Re: Terrain collision and btBvhTriangleMeshShape

Post by toastie »

Oh, help me, almighty Coumans!
pico
Posts: 229
Joined: Sun Sep 30, 2007 7:58 am

Re: Terrain collision and btBvhTriangleMeshShape

Post by pico »

Hi,

there is no penetration depth because you get the point of first contact. If you want to know where on the 'sweep line' the collision happends you can use m_closestHitFraction.

regards