So I've created a function like this that will create a new compound object:
Code: Select all
void oaCompoundObj::AddChild(oaObject * obj, Pose p){
Trace("oaCompoundObj::AddChild(oaObject * obj, Pose p)");
// obj->onCompound=true;
children.push_back(obj);
#ifdef WITH_BULLET
btCompoundShape * shape = new btCompoundShape();;
if (collisionShape) {
Trace("oaCompoundObj::AddChild(oaObject * obj, Pose p)2");
shape=(btCompoundShape *)collisionShape;
btTransform objtrans;
objtrans.setIdentity();
objtrans.setOrigin(btVector3(p.tx,p.ty,p.tz));
objtrans.setRotation(btQuaternion(p.angle/180.0*M_PI, 0, 0, 0));
shape->addChildShape(objtrans , obj->collisionShape);
}
#endif
}
I'm creating the collision shape for the compound like this:
Code: Select all
void oaObject::initPhysics(){
Trace("oaObject::initPhysics");
if (!collisionShape)
buildCollisionShape();
if (!motionState)
motionState=
new btDefaultMotionState(btTransform(btQuaternion(btVector3(pose.rx,pose.ry,pose.rz),pose.angle/180.0*M_PI), btVector3(pose.tx,pose.ty,pose.tz)));
btVector3 bodyInertia(0,0,0);
if (mass!=0)
collisionShape->calculateLocalInertia(mass,bodyInertia);
btRigidBody::btRigidBodyConstructionInfo
rigidBodyCI(mass,motionState,collisionShape,bodyInertia);
rigidBody = new btRigidBody(rigidBodyCI);
}
InitPhysics() do the same as localCreateRigidBody(mass,pose,object).