Code: Select all
{
const btScalar x=1;
const btScalar y=1;
const btScalar z=1;
const btScalar ox=1; // offset
const btScalar oy=1; // offset
const btScalar oz=1; // offset
const btVector3 points[] = {
btVector3(ox+x,oy+y,oz+z),
btVector3(ox-x,oy+y,oz+z),
btVector3(ox+x,oy-y,oz+z),
btVector3(ox-x,oy-y,oz+z),
btVector3(ox+x,oy+y,oz-z),
btVector3(ox-x,oy+y,oz-z),
btVector3(ox+x,oy-y,oz-z),
btVector3(ox-x,oy-y,oz-z)
};
btConvexHullShape* shape = new btConvexHullShape(&points[0].x(),sizeof(points)/sizeof(points[0]));
//m_collisionShapes.push_back(shape);
btTransform transform;transform.setIdentity();
transform.setOrigin(btVector3(-10,2*y,-20));transform.setRotation(btQuaternion(btVector3(0,1,0),btRadians(60)));
const btScalar mass(1.);
const bool isDynamic = (mass != 0.f);
btVector3 localInertia(0,0,0);
if (isDynamic) shape->calculateLocalInertia(mass,localInertia);
btDefaultMotionState* myMotionState = new btDefaultMotionState(transform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,shape,localInertia);
btRigidBody* body = new btRigidBody(rbInfo);
btWorld->addRigidBody(body); // aabb OK
// Clone with uniform scaling:
{
btUniformScalingShape* scaledShape = new btUniformScalingShape(shape,2);
//m_collisionShapes.push_back(shape);
const btScalar mass(2.);
transform.setOrigin(btVector3(10,4*y,-20));
const bool isDynamic = (mass != 0.f);
btVector3 localInertia(0,0,0);
if (isDynamic) shape->calculateLocalInertia(mass,localInertia);
btDefaultMotionState* myMotionState = new btDefaultMotionState(transform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,scaledShape,localInertia);
btRigidBody* body = new btRigidBody(rbInfo);
btWorld->addRigidBody(body); // aabb too small!
}
}
the weird behavior is that the new compound shape (actually bodies using it...) keeps jumping (although sometimes its aabb looks correct when the child shapes are centered in their own center).
In short I would like to be able to make something like a btUniformScalingCompoundShape, and I hope that, if that problem gets solved, I can make it.