Revision: 16502
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16502
Author:   ben2610
Date:     2008-09-13 13:46:07 +0200 (Sat, 13 Sep 2008)

Log Message:
-----------
BGE patch: fix transform bug on compound shape: child shape didn't take into 
account parent inverse node. Fix scaling bug on instantiation of compound 
shape: child shape didn't have correct shape. Note: global scaling doesn't work 
on compound shape (limitation of Bullet); don't set any scale on the top 
dynamic object.

Modified Paths:
--------------
    trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
    trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
    trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.h

Modified: trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp 
2008-09-13 11:43:01 UTC (rev 16501)
+++ trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp 
2008-09-13 11:46:07 UTC (rev 16502)
@@ -801,11 +801,29 @@
                        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);

Modified: 
trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
===================================================================
--- trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp     
2008-09-13 11:43:01 UTC (rev 16501)
+++ trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp     
2008-09-13 11:46:07 UTC (rev 16502)
@@ -924,6 +924,7 @@
                                collisionShape = 
nextShapeInfo->CreateBulletShape();
                                if (collisionShape)
                                {
+                                       
collisionShape->setLocalScaling(nextShapeInfo->m_childScale);
                                        
compoundShape->addChildShape(nextShapeInfo->m_childTrans, collisionShape);
                                }
                        }

Modified: trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.h
===================================================================
--- trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.h       
2008-09-13 11:43:01 UTC (rev 16501)
+++ trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.h       
2008-09-13 11:46:07 UTC (rev 16502)
@@ -47,6 +47,7 @@
                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)
        {
@@ -96,6 +97,7 @@
        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


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to