bugfix/workaround for problem with hard-coded collision margins being too large.
authorErwin Coumans <blender@erwincoumans.com>
Sun, 18 Jun 2006 22:10:00 +0000 (22:10 +0000)
committerErwin Coumans <blender@erwincoumans.com>
Sun, 18 Jun 2006 22:10:00 +0000 (22:10 +0000)
source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
source/gameengine/Ketsji/KX_BulletPhysicsController.h
source/gameengine/Ketsji/KX_GameObject.cpp
source/gameengine/Ketsji/KX_GameObject.h
source/gameengine/Ketsji/KX_IPhysicsController.h
source/gameengine/Ketsji/KX_SumoPhysicsController.cpp
source/gameengine/Ketsji/KX_SumoPhysicsController.h
source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
source/gameengine/Physics/Bullet/CcdPhysicsController.h

index e0ec09ffdd5686e61899233e8dbb45f02570d236..c974b9b6828b33c33a57a28221d8f83b276c2650 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "PHY_IPhysicsEnvironment.h"
 
+
 KX_BulletPhysicsController::KX_BulletPhysicsController (const CcdConstructionInfo& ci, bool dyna)
 : KX_IPhysicsController(dyna,(PHY_IPhysicsController*)this),
 CcdPhysicsController(ci)
@@ -58,6 +59,10 @@ void KX_BulletPhysicsController::SetObject (SG_IObject* object)
 
 }
 
+void   KX_BulletPhysicsController::SetMargin (float collisionMargin)
+{
+       CcdPhysicsController::SetMargin(collisionMargin);
+}
 void   KX_BulletPhysicsController::RelativeTranslate(const MT_Vector3& dloc,bool local)
 {
        CcdPhysicsController::RelativeTranslate(dloc[0],dloc[1],dloc[2],local);
index 2251c3b1f9051b2ae00dfcbbf48b94c6f1a2b15a..272868459d0b2ea1be75039a7c735b7bac134f03 100644 (file)
@@ -19,7 +19,7 @@ public:
 
        virtual void    applyImpulse(const MT_Point3& attach, const MT_Vector3& impulse);
        virtual void    SetObject (SG_IObject* object);
-
+       virtual void    SetMargin (float collisionMargin);
        virtual void    RelativeTranslate(const MT_Vector3& dloc,bool local);
        virtual void    RelativeRotate(const MT_Matrix3x3& drot,bool local);
        virtual void    ApplyTorque(const MT_Vector3& torque,bool local);
index 3b1e4f7ce59c4965fec06953803aad54dd9cce1c..6e53cb4d25f61c027df95308deb8cc19313a06bf 100644 (file)
@@ -627,6 +627,7 @@ PyMethodDef KX_GameObject::Methods[] = {
        {"getMass", (PyCFunction) KX_GameObject::sPyGetMass, METH_VARARGS},
        {"getReactionForce", (PyCFunction) KX_GameObject::sPyGetReactionForce, METH_VARARGS},
        {"applyImpulse", (PyCFunction) KX_GameObject::sPyApplyImpulse, METH_VARARGS},
+       {"setCollisionMargin", (PyCFunction) KX_GameObject::sPySetCollisionMargin, METH_VARARGS},
        {"suspendDynamics", (PyCFunction)KX_GameObject::sPySuspendDynamics,METH_VARARGS},
        {"restoreDynamics", (PyCFunction)KX_GameObject::sPyRestoreDynamics,METH_VARARGS},
        {"enableRigidBody", (PyCFunction)KX_GameObject::sPyEnableRigidBody,METH_VARARGS},
@@ -979,6 +980,29 @@ PyObject* KX_GameObject::PyGetMesh(PyObject* self,
 }
 
 
+
+
+
+PyObject* KX_GameObject::PySetCollisionMargin(PyObject* self, 
+                                                                               PyObject* args, 
+                                                                               PyObject* kwds)
+{
+       float collisionMargin;
+       if (PyArg_ParseTuple(args, "f", &collisionMargin))
+       {
+               if (m_pPhysicsController1)
+               {
+                       m_pPhysicsController1->SetMargin(collisionMargin);
+                       Py_Return;
+               }
+
+       }
+       
+       return NULL;
+}
+
+
+
 PyObject* KX_GameObject::PyApplyImpulse(PyObject* self, 
                                                                                PyObject* args, 
                                                                                PyObject* kwds)
index 0b65109cb8dff3983b4e557e10cb5242fbcf6f06..f3bf529a37db392eaf8e7df0f07f655390bd1a63 100644 (file)
@@ -604,6 +604,7 @@ public:
        KX_PYMETHOD(KX_GameObject,EnableRigidBody);
        KX_PYMETHOD(KX_GameObject,DisableRigidBody);
        KX_PYMETHOD(KX_GameObject,ApplyImpulse);
+       KX_PYMETHOD(KX_GameObject,SetCollisionMargin);
        KX_PYMETHOD(KX_GameObject,GetMesh);
        KX_PYMETHOD(KX_GameObject,GetParent);
        KX_PYMETHOD(KX_GameObject,GetPhysicsId);
index ca64888fd55ff6876e464a61e0fd179447acdae8..9a64be7f99cb2c1e69039f75a49e039a1c75d654 100644 (file)
@@ -60,6 +60,7 @@ public:
 
        virtual void    applyImpulse(const MT_Point3& attach, const MT_Vector3& impulse)=0;
        virtual void    SetObject (SG_IObject* object)=0;
+       virtual void    SetMargin (float collisionMargin)=0;
 
        virtual void    RelativeTranslate(const MT_Vector3& dloc,bool local)=0;
        virtual void    RelativeRotate(const MT_Matrix3x3& drot,bool local)=0;
index 11a09a12e1e6c92d768eef04348b82acb4511e19..d042a302eda81f98092dc6b5765c0848a49db1ab 100644 (file)
@@ -164,6 +164,11 @@ gameobj->SetPhysicsController(this,gameobj->IsDynamic());
 GetSumoObject()->setClientObject(gameobj->getClientInfo());
 }
 
+void   KX_SumoPhysicsController::SetMargin(float collisionMargin)
+{
+       SumoPhysicsController::SetMargin(collisionMargin);
+}
+
 
 void KX_SumoPhysicsController::setOrientation(const MT_Quaternion& orn)
 {
index b4b0f8a4cd0468dcced2e9a28f0a6192b0ce58ae..ea803d964c8e1d709f61219ab0b35638797c1ae0 100644 (file)
@@ -64,7 +64,7 @@ public:
 
        void    applyImpulse(const MT_Point3& attach, const MT_Vector3& impulse);
        virtual void    SetObject (SG_IObject* object);
-
+       virtual void    SetMargin (float collisionMargin);
        
        void    RelativeTranslate(const MT_Vector3& dloc,bool local);
        void    RelativeRotate(const MT_Matrix3x3& drot,bool local);
index cddc780aff4f82e2811431f2c572933ab1e339bc..60b8dbbf86271fea0500528e717a795ca513a16f 100644 (file)
@@ -210,6 +210,28 @@ void               CcdPhysicsController::PostProcessReplica(class PHY_IMotionState* motionsta
 
 }
 
+void CcdPhysicsController::SetMargin(float margin)
+{
+       if (m_body && m_body->GetCollisionShape())
+       {
+               m_body->GetCollisionShape()->SetMargin(margin);
+       }
+
+
+}
+
+float CcdPhysicsController::GetMargin() const
+{
+       if (m_body && m_body->GetCollisionShape())
+       {
+               return m_body->GetCollisionShape()->GetMargin();
+       }
+
+       return 0.f;
+
+}
+
+
                // kinematic methods
 void           CcdPhysicsController::RelativeTranslate(float dlocX,float dlocY,float dlocZ,bool local)
 {
index 056feba652c47d1e738c2a3a71bf6a76ed906841..7488e74db0128ba8fb267dff023e8483f38b4015 100644 (file)
@@ -160,8 +160,8 @@ class CcdPhysicsController : public PHY_IPhysicsController
                
 
                virtual void    calcXform() {} ;
-               virtual void SetMargin(float margin) {};
-               virtual float GetMargin() const {return 0.f;};
+               virtual void SetMargin(float margin);
+               virtual float GetMargin() const;
 
 
                bool    wantsSleeping();