How to properly use compound shape

Dez
Posts: 1
Joined: Fri Oct 11, 2013 7:06 am

How to properly use compound shape

Post by Dez »

Hi!
I'm currently working on something like tank simulator, and i want all parts of tank (like turret, gun etc.) to be physical. At first i used hingeconstraints to connect parts, but parts penetrate each other, and when i'm rotating tank hull, turret didn't rotate :(

I've tried setParam values(erp, cfm) but it didn't help.

So i want to try compound shape.
Actually i'm making hull & turret as rigid body with compound collision shapes, next i'm adding convex shapes like in this code:

Code: Select all

hull.module->collShape = new btConvexHullShape(hull.cnv_mesh->positions.data(), hull.cnv_mesh->positions.size()/3, 3*sizeof(float));
  hull.module->collShape->setLocalScaling(btVector3(1,1,1)*SCALE);
  hull.module->compound = new btCompoundShape();
			
  btTransform localTrans;
  localTrans.setIdentity();
  localTrans.setOrigin(btVector3(0,0,0));
  hull.module->compound->addChildShape(localTrans,hull.module->collShape);
  tr.setOrigin(btVector3(0,0,0));

  hull.module->rgBody = bulletWorld.createRigidBody(hull.node["mass"].as<float>(),tr,hull.module->compound);

Code: Select all

  turret.module->collShape = new btConvexHullShape(it.cnv_mesh->positions.data(), turret.cnv_mesh->positions.size()/3, 3*sizeof(float));
  it.module->rgBody = bulletWorld.createRigidBody(it.node["mass"].as<float>(),tr,it.module->collShape);
  localTrans.setOrigin(pivotA);
  hull.module->compound->addChildShape(localTrans, compound);
When i'm moving tank i'm add forces only to hull rigidBody and now turret is falling from tank :)

My question is:
how to move childs of compound shape with respects to their parents, or how to move bodies connected via hingeConstraint respects to their parents and how to disable moving along axis when i'm using higeConstraint.

Karol
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: How to properly use compound shape

Post by Erwin Coumans »

The new btMultiBody (Featherstone) or btMLCPSolver in Bullet 2.82 (to be released later this week) could help with a better quality tank simulation. It is non-trivial to build it, we'll add some tank demo in a future Bullet release.