From ee3e231be5c2e1660a8698f93bd2449c2537ed6a Mon Sep 17 00:00:00 2001 From: rponom Date: Thu, 28 Jan 2010 23:41:09 +0000 Subject: [PATCH] + more consistent 'setLocalScaling' for the btCompoundShape. Full non-uniform scaling is not supported when child shapes have a rotation. If any child shapes have rotation, the best you can do is either uniform scaling, or 'baking' the non-uniform scaling into the child geometry (vertices of a convex hull for example) + fixed an issue with BulletWorldImporter, btBoxShape implicitShapeDimensions already includes local scaling. --- .../Serialize/BulletWorldImporter/btBulletWorldImporter.cpp | 4 +++- src/BulletCollision/CollisionShapes/btCompoundShape.cpp | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.cpp b/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.cpp index 6afa4ceea..041f44a9f 100644 --- a/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.cpp +++ b/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.cpp @@ -64,12 +64,14 @@ btCollisionShape* btBulletWorldImporter::convertCollisionShape( btCollisionShap btConvexInternalShapeData* bsd = (btConvexInternalShapeData*)shapeData; btVector3 implicitShapeDimensions; implicitShapeDimensions.deSerializeFloat(bsd->m_implicitShapeDimensions); + btVector3 localScaling; + localScaling.deSerializeFloat(bsd->m_localScaling); btVector3 margin(bsd->m_collisionMargin,bsd->m_collisionMargin,bsd->m_collisionMargin); switch (shapeData->m_shapeType) { case BOX_SHAPE_PROXYTYPE: { - shape = createBoxShape(implicitShapeDimensions+margin); + shape = createBoxShape(implicitShapeDimensions/localScaling+margin); break; } case SPHERE_SHAPE_PROXYTYPE: diff --git a/src/BulletCollision/CollisionShapes/btCompoundShape.cpp b/src/BulletCollision/CollisionShapes/btCompoundShape.cpp index 22fb2c981..cd0e436ca 100644 --- a/src/BulletCollision/CollisionShapes/btCompoundShape.cpp +++ b/src/BulletCollision/CollisionShapes/btCompoundShape.cpp @@ -267,18 +267,19 @@ void btCompoundShape::calculatePrincipalAxisTransform(btScalar* masses, btTransf void btCompoundShape::setLocalScaling(const btVector3& scaling) { - m_localScaling = scaling; for(int i = 0; i < m_children.size(); i++) { btTransform childTrans = getChildTransform(i); btVector3 childScale = m_children[i].m_childShape->getLocalScaling(); - childScale = childScale * (childTrans.getBasis() * scaling); +// childScale = childScale * (childTrans.getBasis() * scaling); + childScale = childScale * scaling / m_localScaling; m_children[i].m_childShape->setLocalScaling(childScale); childTrans.setOrigin((childTrans.getOrigin())*scaling); updateChildTransform(i, childTrans); recalculateLocalAabb(); } + m_localScaling = scaling; }