void BasicOECakeReader::addNewCollisionShape(int numParticles, btVector3* particlePositions, btScalar* radii, int materialType, int objectIndex,int color ) { //create Bullet stuff btCompoundShape* colShape = 0; btScalar mass = 0.f; bool addConstraint = false; if (materialType&0x800000) { addConstraint = true; } if ((materialType & 0x20000) ||(materialType & 0x12)) { mass = 1.f; } btTransform startTransform; startTransform.setIdentity(); { btTransform localTrans; localTrans.setIdentity(); //static btCompoundShape* compound = new btCompoundShape(); for (int i=0;i<numParticles;i++) { localTrans.setOrigin(particlePositions[i]); btSphereShape* particle = new btSphereShape(radii[i]); compound->addChildShape(localTrans,particle); } if (mass) { //shift the center of mass, based on all spheres btCompoundShape* newCompound = shiftTransform(compound,mass,startTransform); colShape = newCompound; } else { //use unmodified colShape = compound; } } btDefaultMotionState* myMotionState = 0; if (colShape) { createBodyForCompoundShape(colShape,addConstraint,startTransform,mass); } }
btCompoundShape* btFractureBody::shiftTransformDistributeMass(btCompoundShape* boxCompound,btScalar mass,btTransform& shift) { btVector3 principalInertia; btScalar* masses = new btScalar[boxCompound->getNumChildShapes()]; for (int j=0;j<boxCompound->getNumChildShapes();j++) { //evenly distribute mass masses[j]=mass/boxCompound->getNumChildShapes(); } return shiftTransform(boxCompound,masses,shift,principalInertia); }