synched with trunk at revision 32129
[blender.git] / source / gameengine / Ketsji / KX_BulletPhysicsController.cpp
index e22edfd1306f2f2331f5708fda36b3be90bb6d4c..1b2ceae6560ec2630f56fbed3ddc2a2a1f5036e1 100644 (file)
@@ -92,7 +92,13 @@ void KX_BulletPhysicsController::SetObject (SG_IObject* object)
        gameobj->SetPhysicsController(this,gameobj->IsDynamic());
        CcdPhysicsController::setNewClientInfo(gameobj->getClientInfo());
 
-
+       if (m_bSensor)
+       {
+               // use a different callback function for sensor object, 
+               // bullet will not synchronize, we must do it explicitely
+               SG_Callbacks& callbacks = gameobj->GetSGNode()->GetCallBackFunctions();
+               callbacks.m_updatefunc = KX_GameObject::SynchronizeTransformFunc;
+       } 
 }
 
 MT_Scalar KX_BulletPhysicsController::GetRadius()
@@ -273,13 +279,15 @@ void    KX_BulletPhysicsController::AddCompoundChild(KX_IPhysicsController* chil
        // we will need this to make sure that we remove the right proxy later when unparenting
        proxyShapeInfo->m_userData = childCtrl;
        proxyShapeInfo->SetProxy(childCtrl->GetShapeInfo()->AddRef());
-       // add to parent compound shapeinfo
+       // add to parent compound shapeinfo (increments ref count)
        GetShapeInfo()->AddShape(proxyShapeInfo);
        // create new bullet collision shape from the object shapeinfo and set scaling
-       btCollisionShape* newChildShape = proxyShapeInfo->CreateBulletShape(childCtrl->GetMargin());
+       btCollisionShape* newChildShape = proxyShapeInfo->CreateBulletShape(childCtrl->GetMargin(), childCtrl->getConstructionInfo().m_bGimpact, true);
        newChildShape->setLocalScaling(relativeScale);
        // add bullet collision shape to parent compound collision shape
        compoundShape->addChildShape(proxyShapeInfo->m_childTrans,newChildShape);
+       // proxyShapeInfo is not needed anymore, release it
+       proxyShapeInfo->Release();
        // remember we created this shape
        childCtrl->m_bulletChildShape = newChildShape;
        // recompute inertia of parent
@@ -396,6 +404,8 @@ void        KX_BulletPhysicsController::RestoreDynamics()
        btRigidBody *body = GetRigidBody();
        if (body && m_suspended)
        {
+               // before make sure any position change that was done in this logic frame are accounted for
+               SetTransform();
                GetPhysicsEnvironment()->updateCcdPhysicsController(this, 
                        m_savedMass,
                        m_savedCollisionFlags,