BGE patch: fix transform bug on compound shape: child shape didn't take into account...
authorBenoit Bolsee <benoit.bolsee@online.be>
Sat, 13 Sep 2008 11:46:07 +0000 (11:46 +0000)
committerBenoit Bolsee <benoit.bolsee@online.be>
Sat, 13 Sep 2008 11:46:07 +0000 (11:46 +0000)
source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
source/gameengine/Physics/Bullet/CcdPhysicsController.h

index 9607489497d2d12f1611b231bd291a7dcdd63a69..6507bf501e4b097cbf77535d6dd2e1995e98a278 100644 (file)
@@ -801,11 +801,29 @@ void      KX_ConvertBulletObject( class   KX_GameObject* gameobj,
                        assert(colShape->isCompound());
                        btCompoundShape* compoundShape = (btCompoundShape*)colShape;
 
                        assert(colShape->isCompound());
                        btCompoundShape* compoundShape = (btCompoundShape*)colShape;
 
-                       MT_Point3 childPos = gameobj->GetSGNode()->GetLocalPosition();
-                       MT_Matrix3x3 childRot = gameobj->GetSGNode()->GetLocalOrientation();
-                       MT_Vector3 childScale = gameobj->GetSGNode()->GetLocalScale();
+                       // compute the local transform from parent, this may include a parent inverse node
+                       SG_Node* gameNode = gameobj->GetSGNode();
+                       SG_Node* parentInverseNode = gameNode->GetSGParent();
+                       if (parentInverseNode && parentInverseNode->GetSGClientObject() != NULL)
+                               // this is not a parent inverse node, cancel it
+                               parentInverseNode = NULL;
+                       // now combine the parent inverse node and the game node
+                       MT_Point3 childPos = gameNode->GetLocalPosition();
+                       MT_Matrix3x3 childRot = gameNode->GetLocalOrientation();
+                       MT_Vector3 childScale = gameNode->GetLocalScale();
+                       if (parentInverseNode)
+                       {
+                               const MT_Point3& parentInversePos = parentInverseNode->GetLocalPosition();
+                               const MT_Matrix3x3& parentInverseRot = parentInverseNode->GetLocalOrientation();
+                               const MT_Vector3& parentInverseScale = parentInverseNode->GetLocalScale();
+                               childRot =  parentInverseRot * childRot;
+                               childScale = parentInverseScale * childScale;
+                               childPos = parentInversePos+parentInverseScale*(parentInverseRot*childPos);
+                       }
 
 
-                       bm->setLocalScaling(btVector3(childScale.x(),childScale.y(),childScale.z()));
+                       shapeInfo->m_childScale.setValue(childScale.x(),childScale.y(),childScale.z());
+                       bm->setLocalScaling(shapeInfo->m_childScale);
+                       
                        shapeInfo->m_childTrans.setOrigin(btVector3(childPos.x(),childPos.y(),childPos.z()));
                        float rotval[12];
                        childRot.getValue(rotval);
                        shapeInfo->m_childTrans.setOrigin(btVector3(childPos.x(),childPos.y(),childPos.z()));
                        float rotval[12];
                        childRot.getValue(rotval);
index b67cf0425c5f9cce2358659ea88450a3e0995221..b9266bb9b0ec283b083ff4874c166d6838134e00 100644 (file)
@@ -924,6 +924,7 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape()
                                collisionShape = nextShapeInfo->CreateBulletShape();
                                if (collisionShape)
                                {
                                collisionShape = nextShapeInfo->CreateBulletShape();
                                if (collisionShape)
                                {
+                                       collisionShape->setLocalScaling(nextShapeInfo->m_childScale);
                                        compoundShape->addChildShape(nextShapeInfo->m_childTrans, collisionShape);
                                }
                        }
                                        compoundShape->addChildShape(nextShapeInfo->m_childTrans, collisionShape);
                                }
                        }
index a3fbb502c0805e4086637b3e43a0ec8e1485433d..d6f0867e01d1ba84f0dd37972273c2ca99747f8c 100644 (file)
@@ -47,6 +47,7 @@ public:
                m_radius(1.0),
                m_height(1.0),
                m_halfExtend(0.f,0.f,0.f),
                m_radius(1.0),
                m_height(1.0),
                m_halfExtend(0.f,0.f,0.f),
+               m_childScale(1.0f,1.0f,1.0f),
                m_nextShape(NULL),
                m_refCount(1)
        {
                m_nextShape(NULL),
                m_refCount(1)
        {
@@ -96,6 +97,7 @@ public:
        btScalar                                m_height;
        btVector3                               m_halfExtend;
        btTransform                             m_childTrans;
        btScalar                                m_height;
        btVector3                               m_halfExtend;
        btTransform                             m_childTrans;
+       btVector3                               m_childScale;
        std::vector<btPoint3>   m_vertexArray;  // Contains both vertex array for polytope shape and
                                                                                        // triangle array for concave mesh shape.
                                                                                        // In this case a triangle is made of 3 consecutive points
        std::vector<btPoint3>   m_vertexArray;  // Contains both vertex array for polytope shape and
                                                                                        // triangle array for concave mesh shape.
                                                                                        // In this case a triangle is made of 3 consecutive points