Page 1 of 1

[SOLVED] btHeightfieldTerrainShape wont collide, raycast ok

Posted: Tue Feb 28, 2017 8:22 pm
by aeroflyluby
Hello,

I faced a problem with btHeightfieldTerrainShape which doesn't collide with anything, not even btSphereShape.
Suprisingly raycasting with this shape enabled results in nice raycast positions, matching the terrain perfectly :shock: .
If I raycast and create a sphere some meters above, it will fall through.

I recorded a video of that issue https://youtu.be/ZK2d4dQB3w0
Here is the code I use to initialize physics, very standard setting https://github.com/achlubek/venginenati ... hysics.cpp

Please if you can help I will be very thankful!

Re: btHeightfieldTerrainShape doesn't collide but raycast go

Posted: Wed Mar 01, 2017 4:47 am
by ktfh
At a glance it looks like your using rigid bodies for everything, should use btCollisionObject for static concave collision shapes like btBvhTriangleMeshShape and btHeightfieldTerrainShape. I'm not sure that's the source of the problem though. Things to check would be collision groups and filters, and activation state. I am not sure what else could be wrong if ray test works but not collision.

Re: btHeightfieldTerrainShape doesn't collide but raycast go

Posted: Wed Mar 01, 2017 11:17 am
by aeroflyluby
ktfh wrote:At a glance it looks like your using rigid bodies for everything, should use btCollisionObject for static concave collision shapes like btBvhTriangleMeshShape and btHeightfieldTerrainShape. I'm not sure that's the source of the problem though. Things to check would be collision groups and filters, and activation state. I am not sure what else could be wrong if ray test works but not collision.
Thank you for your response. I was indeed threating everything as btRigidBody, but changing terrain to use btCollisionObject doesn't make any change. I also reviewed collision groups and masks, also collision objects flags, everything seems ok.
It seems like a bug somewhere in btHeightfieldTerrainShape collision detection, but I have no idea how it works internally.

Re: btHeightfieldTerrainShape doesn't collide but raycast go

Posted: Wed Mar 01, 2017 2:17 pm
by ktfh
I just tried the height field out it seems fine. Can you try some minimal implementation and drop a ball on it?

Code: Select all

void* data = calloc(100*100, sizeof(float));
btHeightfieldTerrainShape* hf = new btHeightfieldTerrainShape(100, 100, data, 1, 0, 1, 1, PHY_FLOAT, flase);
btCollisionObject* body = new btCollisionObject();
body->setCollisionShape(hf);
dynamicsWorld->addCollisionObject(body);

Re: btHeightfieldTerrainShape doesn't collide but raycast go

Posted: Wed Mar 01, 2017 4:44 pm
by aeroflyluby
ktfh wrote:I just tried the height field out it seems fine. Can you try some minimal implementation and drop a ball on it?

Code: Select all

void* data = calloc(100*100, sizeof(float));
btHeightfieldTerrainShape* hf = new btHeightfieldTerrainShape(100, 100, data, 1, 0, 1, 1, PHY_FLOAT, flase);
btCollisionObject* body = new btCollisionObject();
body->setCollisionShape(hf);
dynamicsWorld->addCollisionObject(body);
I have tried your code and it worked beautifully.
I messed with my code and I found out that I missed heightMin/Max parameters, now I detect it while loading parameters. Also I needed to translate mesh afterwards to accomodate its recentering along minmax height.
It now works great! http://i.imgur.com/e9wC0rc.jpg

Thank you very much ktfh :)