BGE bug #21947: Softbodies not using object size. Fixed by scaling the shape before...
authorBenoit Bolsee <benoit.bolsee@online.be>
Sun, 5 Feb 2012 09:32:35 +0000 (09:32 +0000)
committerBenoit Bolsee <benoit.bolsee@online.be>
Sun, 5 Feb 2012 09:32:35 +0000 (09:32 +0000)
source/gameengine/Physics/Bullet/CcdPhysicsController.cpp

index 22aa781..4b3e2ea 100644 (file)
@@ -231,6 +231,8 @@ bool CcdPhysicsController::CreateSoftbody()
                        if (trimeshshape->getMeshInterface()->getNumSubParts()==1)
                        {
                                unsigned char* vertexBase;
+                               btScalar* scaledVertexBase;
+                               btVector3 localScaling;
                                PHY_ScalarType vertexType;
                                int numverts;
                                int vertexstride;
@@ -238,8 +240,16 @@ bool CcdPhysicsController::CreateSoftbody()
                                int indexstride;
                                PHY_ScalarType indexType;
                                trimeshshape->getMeshInterface()->getLockedVertexIndexBase(&vertexBase,numverts,vertexType,vertexstride,&indexbase,indexstride,numtris,indexType);
-                               
-                               psb = btSoftBodyHelpers::CreateFromTriMesh(worldInfo,(const btScalar*)vertexBase,(const int*)indexbase,numtris,false);
+                               localScaling = scaledtrimeshshape->getLocalScaling();
+                               scaledVertexBase = new btScalar[numverts*3];
+                               for (int i=0; i<numverts*3; i+=3)
+                               {
+                                       scaledVertexBase[i] = ((const btScalar*)vertexBase)[i] * localScaling.getX();
+                                       scaledVertexBase[i+1] = ((const btScalar*)vertexBase)[i+1] * localScaling.getY();
+                                       scaledVertexBase[i+2] = ((const btScalar*)vertexBase)[i+2] * localScaling.getZ();
+                               }
+                               psb = btSoftBodyHelpers::CreateFromTriMesh(worldInfo,scaledVertexBase,(const int*)indexbase,numtris,false);
+                               delete [] scaledVertexBase;
                        }
                } else
                {