distribute reg offset to compound children

This commit is contained in:
Andrew Meadows 2016-08-24 17:50:13 -07:00
parent 19cd4648ad
commit 502146b171

View file

@ -346,14 +346,26 @@ const btCollisionShape* ShapeFactory::createShapeFromInfo(const ShapeInfo& info)
} }
if (shape) { if (shape) {
if (glm::length2(info.getOffset()) > MIN_SHAPE_OFFSET * MIN_SHAPE_OFFSET) { if (glm::length2(info.getOffset()) > MIN_SHAPE_OFFSET * MIN_SHAPE_OFFSET) {
// this shape has an offset, which we support by wrapping the true shape // we need to apply an offset
// in a btCompoundShape with a local transform btTransform offset;
auto compound = new btCompoundShape(); offset.setIdentity();
btTransform trans; offset.setOrigin(glmToBullet(info.getOffset()));
trans.setIdentity();
trans.setOrigin(glmToBullet(info.getOffset())); if (shape->getShapeType() == (int)COMPOUND_SHAPE_PROXYTYPE) {
compound->addChildShape(trans, shape); // this shape is already compound
shape = compound; // walk through the child shapes and adjust their transforms
btCompoundShape* compound = static_cast<btCompoundShape*>(shape);
int32_t numSubShapes = compound->getNumChildShapes();
for (int32_t i = 0; i < numSubShapes; ++i) {
compound->updateChildTransform(i, offset * compound->getChildTransform(i), false);
}
compound->recalculateLocalAabb();
} else {
// wrap this shape in a compound
auto compound = new btCompoundShape();
compound->addChildShape(offset, shape);
shape = compound;
}
} }
} }
return shape; return shape;