mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 19:59:28 +02:00
distribute reg offset to compound children
This commit is contained in:
parent
19cd4648ad
commit
502146b171
1 changed files with 20 additions and 8 deletions
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue