BGE bug #17688 fixed: Near Sensor Reset not working (for Gamekit)
authorBenoit Bolsee <benoit.bolsee@online.be>
Wed, 1 Oct 2008 07:55:02 +0000 (07:55 +0000)
committerBenoit Bolsee <benoit.bolsee@online.be>
Wed, 1 Oct 2008 07:55:02 +0000 (07:55 +0000)
Implementation of the PHY_IPhysicsController::SetMargin(),
GetMargin(), SetRadius() and GetRadius() for Bullet and Sumo
to allow resetting the Near sensor radius. For bullet use
the new setUnscaledRadius() function to change sphere radius.

In pPreparation of a Fh constraint actuator:
- Add KX_IPhysicsController::GetRadius()
- Fix implementation of KX_BulletPhysicsController::GetVelocity()
  (velocity at a point in geometric coordinate)
- Don't try to set velocity on static object (Bullet will assert)
- Add KX_GameObject::GetVelocity() for C access to local velocity

15 files changed:
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_NearSensor.cpp
source/gameengine/Ketsji/KX_OdePhysicsController.cpp
source/gameengine/Ketsji/KX_OdePhysicsController.h
source/gameengine/Ketsji/KX_SumoPhysicsController.cpp
source/gameengine/Ketsji/KX_SumoPhysicsController.h
source/gameengine/Physics/BlOde/OdePhysicsController.h
source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
source/gameengine/Physics/Bullet/CcdPhysicsController.h
source/gameengine/Physics/Sumo/SumoPhysicsController.h
source/gameengine/Physics/common/PHY_IPhysicsController.h

index 3d20ce8a3a558d0a9067c4d687997c4f2579a76f..bf838e60210744078c07bbdf60092e77a45b74f6 100644 (file)
@@ -115,7 +115,7 @@ MT_Vector3 KX_BulletPhysicsController::GetAngularVelocity()
 MT_Vector3 KX_BulletPhysicsController::GetVelocity(const MT_Point3& pos)
 {
        float linVel[3];
-       CcdPhysicsController::GetLinearVelocity(linVel[0],linVel[1],linVel[2]);
+       CcdPhysicsController::GetVelocity(pos[0], pos[1], pos[2], linVel[0],linVel[1],linVel[2]);
        return MT_Vector3(linVel[0],linVel[1],linVel[2]);
 }
 
@@ -160,6 +160,12 @@ MT_Scalar  KX_BulletPhysicsController::GetMass()
        return 0.f;
 
 }
+
+MT_Scalar KX_BulletPhysicsController::GetRadius()
+{
+       return MT_Scalar(CcdPhysicsController::GetRadius());
+}
+
 MT_Vector3     KX_BulletPhysicsController::getReactionForce()
 {
        assert(0);
index 2efe0474b30589196032edd8b11f9b734fdf8423..cdcb82c87caf27dc658af5c0406f8f4481afcada 100644 (file)
@@ -49,9 +49,7 @@ public:
 
        virtual SG_Controller*  GetReplica(class SG_Node* destnode);
 
-       void    SetDyna(bool isDynamic) {
-               m_bDyna = isDynamic;
-       }
+       virtual MT_Scalar GetRadius();
 
 
        virtual void    SetSumoTransform(bool nondynaonly);
index 15055a9cf93d21e8a19071ebec4ccdbfa0726b88..1b57b9acc1d9e5b8022ce6d6e6a80702f69ad9ff 100644 (file)
@@ -772,7 +772,14 @@ MT_Vector3 KX_GameObject::GetAngularVelocity(bool local)
        return velocity;        
 }
 
-
+MT_Vector3 KX_GameObject::GetVelocity(const MT_Point3& point)
+{
+       if (m_pPhysicsController1)
+       {
+               return m_pPhysicsController1->GetVelocity(point);
+       }
+       return MT_Vector3(0.0,0.0,0.0);
+}
 
 // scenegraph node stuff
 
index 12e29cf32946b1d70d0983ad763198d04cd3c63e..472d31362dd6409dff0528c947ab9f27cc2a9251 100644 (file)
@@ -264,6 +264,15 @@ public:
                bool local=false
        );
 
+       /** 
+        * Return the linear velocity of a given point in world coordinate
+        * but relative to center of object ([0,0,0]=center of object)
+        */
+               MT_Vector3 
+       GetVelocity(
+               const MT_Point3& position
+       );
+
        /**
         * Return the mass of the object
         */
index ecfdb8c4275867cf1203041762c73bb06b504f3c..4ea283e9f98071ca07e21a2c4fdf2bacbe2428dd 100644 (file)
@@ -88,7 +88,11 @@ public:
                m_bDyna = isDynamic;
        }
 
+       bool    IsDyna(void) {
+               return m_bDyna;
+       }
 
+       virtual MT_Scalar GetRadius()=0;
        virtual void    SetSumoTransform(bool nondynaonly)=0;
        // todo: remove next line !
        virtual void    SetSimulatedTime(double time)=0;
index 140dd37f5c6c54cbcb3176a27d4ad84fe1419b65..b00cd616a5ba4d3375adf721062c818e8aaa64b8 100644 (file)
@@ -190,13 +190,13 @@ bool KX_NearSensor::Evaluate(CValue* event)
                {
                        if (m_physCtrl)
                        {
-                               m_physCtrl->SetMargin(m_ResetMargin);
+                               m_physCtrl->SetRadius(m_ResetMargin);
                        }
                } else
                {
                        if (m_physCtrl)
                        {
-                               m_physCtrl->SetMargin(m_Margin);
+                               m_physCtrl->SetRadius(m_Margin);
                        }
 
                }
index 05feb11a2bcb17b6f49f1137e6b4b1cb9fde6ed8..6a701a5f25b72e05b42a70f08bd859acd929b3e2 100644 (file)
@@ -169,6 +169,11 @@ MT_Scalar  KX_OdePhysicsController::GetMass()
        return ODEPhysicsController::getMass();
 }
 
+MT_Scalar      KX_OdePhysicsController::GetRadius()
+{
+       return MT_Scalar(0.f);
+}
+
 MT_Vector3     KX_OdePhysicsController::getReactionForce()
 {
        return MT_Vector3(0,0,0);
index 18f9edc68355a909369bc93be2abc4377ce36daa..53050f6ce3e6ed89d6f1e258eda36bd1198cdc22 100644 (file)
@@ -76,7 +76,7 @@ public:
 
        virtual void    SuspendDynamics(bool);
        virtual void    RestoreDynamics();
-       
+       virtual MT_Scalar GetRadius();
 
        virtual SG_Controller*  GetReplica(class SG_Node* destnode);
 
index 4032a795ce3892f4a7fed2c97618712f630d7dca..c842ca1ee14b3a390fcb69903ead909318e6f396 100644 (file)
@@ -205,6 +205,11 @@ MT_Scalar  KX_SumoPhysicsController::GetMass()
        return SumoPhysicsController::getMass();
 }
 
+MT_Scalar      KX_SumoPhysicsController::GetRadius()
+{
+       return SumoPhysicsController::GetRadius();
+}
+
 MT_Vector3     KX_SumoPhysicsController::getReactionForce()
 {
        float force[3];
index 1dd930bf3d971e2b07ea4cf3351abad2315a0ba8..abe48d99043ee640e5fa0d7a11fc0b5fc960449e 100644 (file)
@@ -84,6 +84,7 @@ public:
        virtual void setPosition(const MT_Point3& pos);
        virtual void setScaling(const MT_Vector3& scaling);
        virtual MT_Scalar       GetMass();
+       virtual MT_Scalar       GetRadius();
        virtual MT_Vector3      getReactionForce();
        virtual void    setRigidBody(bool rigid);
        
index d3eb443ed3a76a82886fc8ebbb0afd3fb56c235b..925f5b6686a2d6b409f9a22e80cd80989482db7e 100644 (file)
@@ -111,6 +111,8 @@ public:
        virtual void    calcXform(){}
        virtual void SetMargin(float margin) {}
        virtual float GetMargin() const {return 0.f;}
+       virtual float GetRadius() const {return 0.f;}
+       virtual void  SetRadius(float margin) {}
 
                // clientinfo for raycasts for example
        virtual void*                           getNewClientInfo() { return m_clientInfo;}
index 47329235517965ad49f35ce7a610e8b8b684cc0e..c9c30c1b4500d25f5eba1e50eaf482ef8a50f9fa 100644 (file)
@@ -980,7 +980,7 @@ void                CcdPhysicsController::SetAngularVelocity(float ang_velX,float ang_velY,flo
                if (m_object->isStaticObject())
                {
                        m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
-               }
+               } else
                {
                        btTransform xform = m_object->getWorldTransform();
                        if (local)
@@ -1005,6 +1005,7 @@ void              CcdPhysicsController::SetLinearVelocity(float lin_velX,float lin_velY,floa
                if (m_object->isStaticObject())
                {
                        m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
+                       return;
                }
                
                btSoftBody* soft = GetSoftBody();
@@ -1093,8 +1094,7 @@ void              CcdPhysicsController::GetVelocity(const float posX,const float posY,const
        btRigidBody* body = GetRigidBody();
        if (body)
        {
-               btVector3 rel_pos = pos-body->getCenterOfMassPosition();
-               btVector3 linvel = body->getVelocityInLocalPoint(rel_pos);
+               btVector3 linvel = body->getVelocityInLocalPoint(pos);
                linvX = linvel.x();
                linvY = linvel.y();
                linvZ = linvel.z();
index a1245f6a3e9d429f5d6514a0051d2ef708cb7ace..054ec91122af81e463e31c29236bbbe63c3a2202 100644 (file)
@@ -413,8 +413,29 @@ 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) 
+               {
+                       if (m_collisionShape)
+                               m_collisionShape->setMargin(btScalar(margin));
+               }
+               virtual float GetMargin() const 
+               {
+                       return (m_collisionShape) ? m_collisionShape->getMargin() : 0.f;
+               }
+               virtual float GetRadius() const 
+               { 
+                       // this is not the actual shape radius, it's only used for Fh support
+                       return m_cci.m_radius;
+               }
+               virtual void  SetRadius(float margin) 
+               {
+                       if (m_collisionShape && m_collisionShape->getShapeType() == SPHERE_SHAPE_PROXYTYPE)
+                       {
+                               btSphereShape* sphereShape = static_cast<btSphereShape*>(m_collisionShape);
+                               sphereShape->setUnscaledRadius(margin);
+                       }
+                       m_cci.m_radius = margin;
+               }
 
 
                bool    wantsSleeping();
index 95f01b45f2b2ad58fcbc2268a67884070f0a2e82..d8ee54935d7d18e1ad1b8fd0122023a4c9cb87ad 100644 (file)
@@ -120,6 +120,7 @@ public:
        virtual void SetMargin(float margin) ;
        virtual float GetMargin() const;
        virtual float GetRadius() const ;
+       virtual void  SetRadius(float margin) { SetMargin(margin); }
 
 
        // clientinfo for raycasts for example
index ca8edea114a1c230d6df466ba2854ad0685c1ee4..884e14cfb5af124482a068ca0fae4311cb87f547 100644 (file)
@@ -90,7 +90,8 @@ class PHY_IPhysicsController
                virtual void    calcXform() =0;
                virtual void SetMargin(float margin) =0;
                virtual float GetMargin() const=0;
-               virtual float GetRadius() const { return 0.f;}
+               virtual float GetRadius() const=0;
+               virtual void  SetRadius(float margin) = 0;
                PHY__Vector3    GetWorldPosition(PHY__Vector3& localpos);
 
 };