BGE: new sensor object to generalize Near and Radar sensor, static-static collision...
authorBenoit Bolsee <benoit.bolsee@online.be>
Sun, 17 May 2009 12:51:51 +0000 (12:51 +0000)
committerBenoit Bolsee <benoit.bolsee@online.be>
Sun, 17 May 2009 12:51:51 +0000 (12:51 +0000)
A new type of "Sensor" physics object is available in the GE for advanced
collision management. It's called Sensor for its similarities with the
physics objects that underlie the Near and Radar sensors.
Like the Near and Radar object it is:
- static and ghost
- invisible by default
- always active to ensure correct collision detection
- capable of detecting both static and dynamic objects
- ignoring collision with their parent
- capable of broadphase filtering based on:
  * Actor option: the collisioning object must have the Actor flag set to be detected
  * property/material: as specified in the collision sensors attached to it
  Broadphase filtering is important for performance reason: the collision points
  will be computed only for the objects that pass the broahphase filter.
- automatically removed from the simulation when no collision sensor is active on it

Unlike the Near and Radar object it can:
- take any shape, including triangle mesh
- be made visible for debugging (just use the Visible actuator)
- have multiple collision sensors using it

Other than that, the sensor objects are ordinary objects. You can move them
freely or parent them. When parented to a dynamic object, they can provide
advanced collision control to this object.

The type of collision capability depends on the shape:
- box, sphere, cylinder, cone, convex hull provide volume detection.
- triangle mesh provides surface detection but you can give some volume
  to the suface by increasing the margin in the Advanced Settings panel.
  The margin applies on both sides of the surface.

Performance tip:
- Sensor objects perform better than Near and Radar: they do less synchronizations
  because of the Scenegraph optimizations and they can have multiple collision sensors
  on them (with different property filtering for example).
- Always prefer simple shape (box, sphere) to complex shape whenever possible.
- Always use broadphase filtering (avoid collision sensor with empty propery/material)
- Use collision sensor only when you need them. When no collision sensor is active
  on the sensor object, it is removed from the simulation and consume no CPU.

Known limitations:
- When running Blender in debug mode, you will see one warning line of the console:
  "warning btCollisionDispatcher::needsCollision: static-static collision!"
  In release mode this message is not printed.
- Collision margin has no effect on sphere, cone and cylinder shape.

Other performance improvements:
- Remove unnecessary interpolation for Near and Radar objects and by extension
  sensor objects.
- Use direct matrix copy instead of quaternion to synchronize orientation.

Other bug fix:
- Fix Near/Radar position error on newly activated objects. This was causing
  several detection problems in YoFrankie
- Fix margin not passed correctly to gImpact shape.
- Disable force/velocity actions on static objects

43 files changed:
source/blender/makesdna/DNA_object_types.h
source/blender/python/api2_2x/Object.c
source/blender/src/buttons_logic.c
source/gameengine/Converter/BL_BlenderDataConversion.cpp
source/gameengine/GameLogic/SCA_ISensor.h
source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
source/gameengine/Ketsji/KX_BulletPhysicsController.h
source/gameengine/Ketsji/KX_ClientObjectInfo.h
source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
source/gameengine/Ketsji/KX_GameObject.cpp
source/gameengine/Ketsji/KX_GameObject.h
source/gameengine/Ketsji/KX_IPhysicsController.cpp
source/gameengine/Ketsji/KX_IPhysicsController.h
source/gameengine/Ketsji/KX_MotionState.cpp
source/gameengine/Ketsji/KX_MotionState.h
source/gameengine/Ketsji/KX_NearSensor.cpp
source/gameengine/Ketsji/KX_NearSensor.h
source/gameengine/Ketsji/KX_OdePhysicsController.h
source/gameengine/Ketsji/KX_RadarSensor.cpp
source/gameengine/Ketsji/KX_RadarSensor.h
source/gameengine/Ketsji/KX_Scene.cpp
source/gameengine/Ketsji/KX_SumoPhysicsController.h
source/gameengine/Ketsji/KX_TouchEventManager.cpp
source/gameengine/Ketsji/KX_TouchSensor.cpp
source/gameengine/Ketsji/KX_TouchSensor.h
source/gameengine/Physics/BlOde/OdePhysicsController.cpp
source/gameengine/Physics/BlOde/OdePhysicsController.h
source/gameengine/Physics/BlOde/OdePhysicsEnvironment.h
source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
source/gameengine/Physics/Bullet/CcdPhysicsController.h
source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h
source/gameengine/Physics/Sumo/SumoPhysicsController.cpp
source/gameengine/Physics/Sumo/SumoPhysicsController.h
source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.cpp
source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h
source/gameengine/Physics/common/PHY_IMotionState.h
source/gameengine/Physics/common/PHY_IPhysicsController.h
source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h
source/gameengine/SceneGraph/SG_IObject.h
source/gameengine/SceneGraph/SG_Spatial.h

index 82da883..9121f38 100644 (file)
@@ -440,6 +440,7 @@ extern Object workob;
 #define OB_COLLISION   65536
 #define OB_SOFT_BODY   0x20000
 #define OB_OCCLUDER            0x40000
+#define OB_SENSOR              0x80000
 
 /* ob->gameflag2 */
 #define OB_NEVER_DO_ACTIVITY_CULLING   1
@@ -459,6 +460,7 @@ extern Object workob;
 #define OB_BODY_TYPE_RIGID                     3
 #define OB_BODY_TYPE_SOFT                      4
 #define OB_BODY_TYPE_OCCLUDER          5
+#define OB_BODY_TYPE_SENSOR                    6
 
 /* ob->scavisflag */
 #define OB_VIS_SENS            1
index 2de2906..c3f7a21 100644 (file)
@@ -3562,7 +3562,7 @@ static int Object_setRBMass( BPy_Object * self, PyObject * args )
 /* this is too low level, possible to add helper methods */
 
 #define GAMEFLAG_MASK ( OB_OCCLUDER | OB_COLLISION | OB_DYNAMIC | OB_CHILD | OB_ACTOR | OB_DO_FH | \
-               OB_ROT_FH | OB_ANISOTROPIC_FRICTION | OB_GHOST | OB_RIGID_BODY | OB_SOFT_BODY | \
+               OB_ROT_FH | OB_ANISOTROPIC_FRICTION | OB_GHOST | OB_RIGID_BODY | OB_SOFT_BODY | OB_SENSOR | \
                OB_BOUNDS | OB_COLLISION_RESPONSE | OB_SECTOR | OB_PROP | \
                OB_MAINACTOR )
 
@@ -5544,6 +5544,7 @@ static PyObject *M_Object_RBFlagsDict( void )
                BPy_constant *d = ( BPy_constant * ) M;
                PyConstant_Insert( d, "OCCLUDER", PyInt_FromLong( OB_OCCLUDER ) );
                PyConstant_Insert( d, "COLLISION", PyInt_FromLong( OB_COLLISION ) );
+               PyConstant_Insert( d, "SENSOR", PyInt_FromLong( OB_SENSOR ) );
                PyConstant_Insert( d, "DYNAMIC", PyInt_FromLong( OB_DYNAMIC ) );
                PyConstant_Insert( d, "CHILD", PyInt_FromLong( OB_CHILD ) );
                PyConstant_Insert( d, "ACTOR", PyInt_FromLong( OB_ACTOR ) );
index dccbc73..a537d32 100644 (file)
@@ -3064,29 +3064,33 @@ static void check_body_type(void *arg1_but, void *arg2_object)
        Object *ob = arg2_object;
 
        switch (ob->body_type) {
+       case OB_BODY_TYPE_SENSOR:
+               ob->gameflag |= OB_SENSOR|OB_COLLISION|OB_GHOST;
+               ob->gameflag &= ~(OB_OCCLUDER|OB_DYNAMIC|OB_RIGID_BODY|OB_ACTOR|OB_ANISOTROPIC_FRICTION|OB_DO_FH|OB_ROT_FH|OB_COLLISION_RESPONSE);
+               break;
        case OB_BODY_TYPE_OCCLUDER:
                ob->gameflag |= OB_OCCLUDER;
-               ob->gameflag &= ~(OB_COLLISION|OB_DYNAMIC);
+               ob->gameflag &= ~(OB_SENSOR|OB_COLLISION|OB_DYNAMIC);
                break;
        case OB_BODY_TYPE_NO_COLLISION:
-               ob->gameflag &= ~(OB_COLLISION|OB_OCCLUDER|OB_DYNAMIC);
+               ob->gameflag &= ~(OB_SENSOR|OB_COLLISION|OB_OCCLUDER|OB_DYNAMIC);
                break;
        case OB_BODY_TYPE_STATIC:
                ob->gameflag |= OB_COLLISION;
-               ob->gameflag &= ~(OB_DYNAMIC|OB_RIGID_BODY|OB_SOFT_BODY|OB_OCCLUDER);
+               ob->gameflag &= ~(OB_DYNAMIC|OB_RIGID_BODY|OB_SOFT_BODY|OB_OCCLUDER|OB_SENSOR);
                break;
        case OB_BODY_TYPE_DYNAMIC:
                ob->gameflag |= OB_COLLISION|OB_DYNAMIC|OB_ACTOR;
-               ob->gameflag &= ~(OB_RIGID_BODY|OB_SOFT_BODY|OB_OCCLUDER);
+               ob->gameflag &= ~(OB_RIGID_BODY|OB_SOFT_BODY|OB_OCCLUDER|OB_SENSOR);
                break;
        case OB_BODY_TYPE_RIGID:
                ob->gameflag |= OB_COLLISION|OB_DYNAMIC|OB_RIGID_BODY|OB_ACTOR;
-               ob->gameflag &= ~(OB_SOFT_BODY|OB_OCCLUDER);
+               ob->gameflag &= ~(OB_SOFT_BODY|OB_OCCLUDER|OB_SENSOR);
                break;
        default:
        case OB_BODY_TYPE_SOFT:
                ob->gameflag |= OB_COLLISION|OB_DYNAMIC|OB_SOFT_BODY|OB_ACTOR;
-               ob->gameflag &= ~(OB_RIGID_BODY|OB_OCCLUDER);
+               ob->gameflag &= ~(OB_RIGID_BODY|OB_OCCLUDER|OB_SENSOR);
                
                /* assume triangle mesh, if no bounds chosen for soft body */
                if ((ob->gameflag & OB_BOUNDS) && (ob->boundtype<OB_BOUND_POLYH))
@@ -3271,17 +3275,31 @@ static uiBlock *advanced_bullet_menu(void *arg_ob)
 static void buttons_bullet(uiBlock *block, Object *ob)
 {
        uiBut *but;
+       char *tip;
 
        /* determine the body_type setting based on flags */
-       if (!(ob->gameflag & OB_COLLISION))
-               ob->body_type = (ob->gameflag & OB_OCCLUDER) ? OB_BODY_TYPE_OCCLUDER : OB_BODY_TYPE_NO_COLLISION;
-       else if (!(ob->gameflag & OB_DYNAMIC))
+       if (!(ob->gameflag & OB_COLLISION)) {
+               if (ob->gameflag & OB_OCCLUDER) {
+                       tip = "Occluder";
+                       ob->body_type = OB_BODY_TYPE_OCCLUDER;
+               } else {
+                       tip = "Disable colision for this object";
+                       ob->body_type = OB_BODY_TYPE_NO_COLLISION;
+               }
+       } else if (ob->gameflag & OB_SENSOR) {
+               tip = "Collision Sensor, detects static and dynamic objects but not the other collision sensor objects";
+               ob->body_type = OB_BODY_TYPE_SENSOR;
+       } else if (!(ob->gameflag & OB_DYNAMIC)) {
+               tip = "Static";
                ob->body_type = OB_BODY_TYPE_STATIC;
-       else if (!(ob->gameflag & (OB_RIGID_BODY|OB_SOFT_BODY)))
+       } else if (!(ob->gameflag & (OB_RIGID_BODY|OB_SOFT_BODY))) {
+               tip = "Dynamic";
                ob->body_type = OB_BODY_TYPE_DYNAMIC;
-       else if (ob->gameflag & OB_RIGID_BODY)
+       } else if (ob->gameflag & OB_RIGID_BODY) {
+               tip = "Rigid body";
                ob->body_type = OB_BODY_TYPE_RIGID;
-       else {
+       } else {
+               tip = "Soft body";
                ob->body_type = OB_BODY_TYPE_SOFT;
                /* create the structure here because we display soft body buttons in the main panel */
                if (!ob->bsoft)
@@ -3292,28 +3310,36 @@ static void buttons_bullet(uiBlock *block, Object *ob)
 
        //only enable game soft body if Blender Soft Body exists
        but = uiDefButS(block, MENU, REDRAWVIEW3D, 
-                       "Object type%t|Occluder%x5|No collision%x0|Static%x1|Dynamic%x2|Rigid body%x3|Soft body%x4", 
-                       10, 205, 100, 19, &ob->body_type, 0, 0, 0, 0, "Selects the type of physical representation");
+                       "Object type%t|Occluder%x5|No collision%x0|Sensor%x6|Static%x1|Dynamic%x2|Rigid body%x3|Soft body%x4", 
+                       10, 205, 100, 19, &ob->body_type, 0, 0, 0, 0, tip);
        uiButSetFunc(but, check_body_type, but, ob);
 
        if (ob->gameflag & OB_COLLISION) {
 
-               uiDefButBitI(block, TOG, OB_ACTOR, 0, "Actor",
-                                       110, 205, 50, 19, &ob->gameflag, 0, 0, 0, 0,
-                                       "Objects that are detected by the Near and Radar sensor");
+               if (ob->gameflag & OB_SENSOR) {
+                       uiBlockEndAlign(block);
+                       uiDefBlockBut(block, advanced_bullet_menu, ob, 
+                                                 "Advanced Settings", 
+                                                 210, 205, 140, 19, "Display collision advanced settings");
+                       uiBlockBeginAlign(block);
+               } else {
+                       uiDefButBitI(block, TOG, OB_ACTOR, 0, "Actor",
+                                               110, 205, 50, 19, &ob->gameflag, 0, 0, 0, 0,
+                                               "Objects that are detected by the Near and Radar sensor and the collision sensor objects");
 
-                       
+                               
 
-               uiDefButBitI(block, TOG, OB_GHOST, B_REDR, "Ghost", 
-                                       160,205,50,19, 
-                                       &ob->gameflag, 0, 0, 0, 0, 
-                                       "Objects that don't restitute collisions (like a ghost)");
+                       uiDefButBitI(block, TOG, OB_GHOST, B_REDR, "Ghost", 
+                                               160,205,50,19, 
+                                               &ob->gameflag, 0, 0, 0, 0, 
+                                               "Objects that don't restitute collisions (like a ghost)");
 
-               //uiBlockSetCol(block, TH_BUT_SETTING1);
-               uiDefBlockBut(block, advanced_bullet_menu, ob, 
-                                         "Advanced Settings", 
-                                         210, 205, 140, 19, "Display collision advanced settings");
-               //uiBlockSetCol(block, TH_BUT_SETTING2);
+                       //uiBlockSetCol(block, TH_BUT_SETTING1);
+                       uiDefBlockBut(block, advanced_bullet_menu, ob, 
+                                                 "Advanced Settings", 
+                                                 210, 205, 140, 19, "Display collision advanced settings");
+                       //uiBlockSetCol(block, TH_BUT_SETTING2);
+               }
 
 
                if(ob->gameflag & OB_DYNAMIC) {
@@ -3394,7 +3420,7 @@ static void buttons_bullet(uiBlock *block, Object *ob)
 
                /* In Bullet, anisotripic friction can be applied to static objects as well, just not soft bodies */
 
-               if (!(ob->gameflag & OB_SOFT_BODY))
+               if (!(ob->gameflag & (OB_SOFT_BODY|OB_SENSOR)))
                {
                        uiDefButBitI(block, TOG, OB_ANISOTROPIC_FRICTION, B_REDR, "Anisotropic", 
                                230, 145, 120, 19,
index 9ea623f..d4cc047 100644 (file)
@@ -1413,6 +1413,7 @@ void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj,
        objprop.m_dyna = (blenderobject->gameflag & OB_DYNAMIC) != 0;
        objprop.m_softbody = (blenderobject->gameflag & OB_SOFT_BODY) != 0;
        objprop.m_angular_rigidbody = (blenderobject->gameflag & OB_RIGID_BODY) != 0;
+       objprop.m_sensor = (blenderobject->gameflag & OB_SENSOR) != 0;
        
        if (objprop.m_softbody)
        {
index 9aeda72..ad88652 100644 (file)
@@ -91,6 +91,15 @@ protected:
        std::vector<class SCA_IController*>             m_linkedcontrollers;
 
 public:
+
+       enum sensortype {
+               NONE = 0,
+               TOUCH,
+               NEAR,
+               RADAR,
+               // to be updated as needed
+       };
+
        SCA_ISensor(SCA_IObject* gameobj,
                                class SCA_EventManager* eventmgr,
                                PyTypeObject* T );;
@@ -138,6 +147,8 @@ public:
 
        virtual double GetNumber();
 
+       virtual sensortype GetSensorType() { return NONE; }
+
        /** Stop sensing for a while. */
        void Suspend();
 
index 300a790..e22edfd 100644 (file)
@@ -17,8 +17,8 @@
 #include "BulletSoftBody/btSoftBody.h"
 
 
-KX_BulletPhysicsController::KX_BulletPhysicsController (const CcdConstructionInfo& ci, bool dyna, bool compound)
-: KX_IPhysicsController(dyna,compound,(PHY_IPhysicsController*)this),
+KX_BulletPhysicsController::KX_BulletPhysicsController (const CcdConstructionInfo& ci, bool dyna, bool sensor, bool compound)
+: KX_IPhysicsController(dyna,sensor,compound,(PHY_IPhysicsController*)this),
 CcdPhysicsController(ci),
 m_savedCollisionFlags(0),
 m_savedCollisionFilterGroup(0),
@@ -174,6 +174,20 @@ void KX_BulletPhysicsController::setScaling(const MT_Vector3& scaling)
 {
        CcdPhysicsController::setScaling(scaling.x(),scaling.y(),scaling.z());
 }
+void KX_BulletPhysicsController::SetTransform()
+{
+       btVector3 pos;
+       btVector3 scale;
+       float ori[12];
+       m_MotionState->getWorldPosition(pos.m_floats[0],pos.m_floats[1],pos.m_floats[2]);
+       m_MotionState->getWorldScaling(scale.m_floats[0],scale.m_floats[1],scale.m_floats[2]);
+       m_MotionState->getWorldOrientation(ori);
+       btMatrix3x3 rot(ori[0], ori[4], ori[8],
+                                       ori[1], ori[5], ori[9],
+                                       ori[2], ori[6], ori[10]);
+       CcdPhysicsController::forceWorldTransform(rot, pos);
+}
+
 MT_Scalar      KX_BulletPhysicsController::GetMass()
 {
        if (GetSoftBody())
@@ -262,7 +276,7 @@ void    KX_BulletPhysicsController::AddCompoundChild(KX_IPhysicsController* chil
        // add to parent compound shapeinfo
        GetShapeInfo()->AddShape(proxyShapeInfo);
        // create new bullet collision shape from the object shapeinfo and set scaling
-       btCollisionShape* newChildShape = proxyShapeInfo->CreateBulletShape();
+       btCollisionShape* newChildShape = proxyShapeInfo->CreateBulletShape(childCtrl->GetMargin());
        newChildShape->setLocalScaling(relativeScale);
        // add bullet collision shape to parent compound collision shape
        compoundShape->addChildShape(proxyShapeInfo->m_childTrans,newChildShape);
@@ -359,7 +373,7 @@ void KX_BulletPhysicsController::SetMass(MT_Scalar newmass)
 void   KX_BulletPhysicsController::SuspendDynamics(bool ghost)
 {
        btRigidBody *body = GetRigidBody();
-       if (body && !m_suspended)
+       if (body && !m_suspended && !IsSensor())
        {
                btBroadphaseProxy* handle = body->getBroadphaseHandle();
                m_savedCollisionFlags = body->getCollisionFlags();
@@ -445,7 +459,7 @@ SG_Controller*      KX_BulletPhysicsController::GetReplica(class SG_Node* destnode)
 void   KX_BulletPhysicsController::SetSumoTransform(bool nondynaonly)
 {
 
-       if (!m_bDyna)
+       if (!m_bDyna && !m_bSensor)
        {
                btCollisionObject* object = GetRigidBody();
                object->setActivationState(ACTIVE_TAG);
index 9d2afad..755b1cb 100644 (file)
@@ -19,7 +19,7 @@ private:
 
 public:
 
-       KX_BulletPhysicsController (const CcdConstructionInfo& ci, bool dyna, bool compound);
+       KX_BulletPhysicsController (const CcdConstructionInfo& ci, bool dyna, bool sensor, bool compound);
        virtual ~KX_BulletPhysicsController ();
 
        ///////////////////////////////////
@@ -42,6 +42,7 @@ public:
        virtual void setOrientation(const MT_Matrix3x3& orn);
        virtual void setPosition(const MT_Point3& pos);
        virtual void setScaling(const MT_Vector3& scaling);
+       virtual void SetTransform();
        virtual MT_Scalar       GetMass();
        virtual void    SetMass(MT_Scalar newmass);
        virtual MT_Vector3      GetLocalInertia();
index 7345edb..74d463f 100644 (file)
@@ -50,8 +50,8 @@ struct KX_ClientObjectInfo
                STATIC,
                ACTOR,
                RESERVED1,
-               RADAR,
-               NEAR
+               SENSOR,
+               OBSENSOR
        }               m_type;
        KX_GameObject*  m_gameobject;
        void*           m_auxilary_info;
@@ -84,6 +84,7 @@ public:
        }
        
        bool isActor() { return m_type <= ACTOR; }
+       bool isSensor() { return m_type >= SENSOR && m_type <= OBSENSOR; }
 };
 
 #endif //__KX_CLIENTOBJECT_INFO_H
index 5b912a1..e48fddb 100644 (file)
@@ -83,6 +83,7 @@ struct KX_ObjectProperties
        bool    m_ghost;
        class KX_GameObject*    m_dynamic_parent;
        bool    m_isactor;
+       bool    m_sensor;
        bool    m_concave;
        bool    m_isdeformable;
        bool    m_disableSleeping;
index f18ffb5..73693e6 100644 (file)
@@ -808,12 +808,12 @@ void      KX_ConvertBulletObject( class   KX_GameObject* gameobj,
        
 
        bool isbulletdyna = false;
+       bool isbulletsensor = false;
        CcdConstructionInfo ci;
        class PHY_IMotionState* motionstate = new KX_MotionState(gameobj->GetSGNode());
        class CcdShapeConstructionInfo *shapeInfo = new CcdShapeConstructionInfo();
 
        
-
        if (!objprop->m_dyna)
        {
                ci.m_collisionFlags |= btCollisionObject::CF_STATIC_OBJECT;
@@ -832,6 +832,7 @@ void        KX_ConvertBulletObject( class   KX_GameObject* gameobj,
        ci.m_margin = objprop->m_margin;
        shapeInfo->m_radius = objprop->m_radius;
        isbulletdyna = objprop->m_dyna;
+       isbulletsensor = objprop->m_sensor;
        
        ci.m_localInertiaTensor = btVector3(ci.m_mass/3.f,ci.m_mass/3.f,ci.m_mass/3.f);
        
@@ -851,7 +852,7 @@ void        KX_ConvertBulletObject( class   KX_GameObject* gameobj,
 
                        //bm = new MultiSphereShape(inertiaHalfExtents,,&trans.getOrigin(),&radius,1);
                        shapeInfo->m_shapeType = PHY_SHAPE_SPHERE;
-                       bm = shapeInfo->CreateBulletShape();
+                       bm = shapeInfo->CreateBulletShape(ci.m_margin);
                        break;
                };
        case KX_BOUNDBOX:
@@ -864,7 +865,7 @@ void        KX_ConvertBulletObject( class   KX_GameObject* gameobj,
                        shapeInfo->m_halfExtend /= 2.0;
                        shapeInfo->m_halfExtend = shapeInfo->m_halfExtend.absolute();
                        shapeInfo->m_shapeType = PHY_SHAPE_BOX;
-                       bm = shapeInfo->CreateBulletShape();
+                       bm = shapeInfo->CreateBulletShape(ci.m_margin);
                        break;
                };
        case KX_BOUNDCYLINDER:
@@ -875,7 +876,7 @@ void        KX_ConvertBulletObject( class   KX_GameObject* gameobj,
                                objprop->m_boundobject.c.m_height * 0.5f
                        );
                        shapeInfo->m_shapeType = PHY_SHAPE_CYLINDER;
-                       bm = shapeInfo->CreateBulletShape();
+                       bm = shapeInfo->CreateBulletShape(ci.m_margin);
                        break;
                }
 
@@ -884,18 +885,18 @@ void      KX_ConvertBulletObject( class   KX_GameObject* gameobj,
                        shapeInfo->m_radius = objprop->m_boundobject.c.m_radius;
                        shapeInfo->m_height = objprop->m_boundobject.c.m_height;
                        shapeInfo->m_shapeType = PHY_SHAPE_CONE;
-                       bm = shapeInfo->CreateBulletShape();
+                       bm = shapeInfo->CreateBulletShape(ci.m_margin);
                        break;
                }
        case KX_BOUNDPOLYTOPE:
                {
                        shapeInfo->SetMesh(meshobj, dm,true,false);
-                       bm = shapeInfo->CreateBulletShape();
+                       bm = shapeInfo->CreateBulletShape(ci.m_margin);
                        break;
                }
        case KX_BOUNDMESH:
                {
-                       bool useGimpact = (ci.m_mass && !objprop->m_softbody);
+                       bool useGimpact = ((ci.m_mass || isbulletsensor) && !objprop->m_softbody);
 
                        // mesh shapes can be shared, check first if we already have a shape on that mesh
                        class CcdShapeConstructionInfo *sharedShapeInfo = CcdShapeConstructionInfo::FindMesh(meshobj, dm, false,useGimpact);
@@ -915,7 +916,7 @@ void        KX_ConvertBulletObject( class   KX_GameObject* gameobj,
                                shapeInfo->setVertexWeldingThreshold1(objprop->m_soft_welding); //todo: expose this to the UI
                        }
 
-                       bm = shapeInfo->CreateBulletShape();
+                       bm = shapeInfo->CreateBulletShape(ci.m_margin);
                        //should we compute inertia for dynamic shape?
                        //bm->calculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor);
 
@@ -933,7 +934,7 @@ void        KX_ConvertBulletObject( class   KX_GameObject* gameobj,
                return;
        }
 
-       bm->setMargin(ci.m_margin);
+       //bm->setMargin(ci.m_margin);
 
 
                if (objprop->m_isCompoundChild)
@@ -1103,26 +1104,39 @@ void    KX_ConvertBulletObject( class   KX_GameObject* gameobj,
        ci.m_soft_numclusteriterations= objprop->m_soft_numclusteriterations;   /* number of iterations to refine collision clusters*/
 
        ////////////////////
-
-       ci.m_collisionFilterGroup = (isbulletdyna) ? short(CcdConstructionInfo::DefaultFilter) : short(CcdConstructionInfo::StaticFilter);
-       ci.m_collisionFilterMask = (isbulletdyna) ? short(CcdConstructionInfo::AllFilter) : short(CcdConstructionInfo::AllFilter ^ CcdConstructionInfo::StaticFilter);
+       ci.m_collisionFilterGroup = 
+               (isbulletsensor) ? short(CcdConstructionInfo::SensorFilter) :
+               (isbulletdyna) ? short(CcdConstructionInfo::DefaultFilter) : 
+               short(CcdConstructionInfo::StaticFilter);
+       ci.m_collisionFilterMask = 
+               (isbulletsensor) ? short(CcdConstructionInfo::AllFilter ^ CcdConstructionInfo::SensorFilter) :
+               (isbulletdyna) ? short(CcdConstructionInfo::AllFilter) : 
+               short(CcdConstructionInfo::AllFilter ^ CcdConstructionInfo::StaticFilter);
        ci.m_bRigid = objprop->m_dyna && objprop->m_angular_rigidbody;
        ci.m_bSoft = objprop->m_softbody;
+       ci.m_bSensor = isbulletsensor;
        MT_Vector3 scaling = gameobj->NodeGetWorldScaling();
        ci.m_scaling.setValue(scaling[0], scaling[1], scaling[2]);
-       KX_BulletPhysicsController* physicscontroller = new KX_BulletPhysicsController(ci,isbulletdyna,objprop->m_hasCompoundChildren);
+       KX_BulletPhysicsController* physicscontroller = new KX_BulletPhysicsController(ci,isbulletdyna,isbulletsensor,objprop->m_hasCompoundChildren);
        // shapeInfo is reference counted, decrement now as we don't use it anymore
        if (shapeInfo)
                shapeInfo->Release();
 
-       if (objprop->m_in_active_layer)
+       gameobj->SetPhysicsController(physicscontroller,isbulletdyna);
+       if (isbulletsensor)
+       {
+               // 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;
+               // make sensor object invisible by default
+               gameobj->SetVisible(false, false);
+       } 
+       // don't add automatically sensor object, they are added when a collision sensor is registered
+       else if (objprop->m_in_active_layer)
        {
                env->addCcdPhysicsController( physicscontroller);
        }
-
-       
-
-       gameobj->SetPhysicsController(physicscontroller,isbulletdyna);
        physicscontroller->setNewClientInfo(gameobj->getClientInfo());          
        {
                btRigidBody* rbody = physicscontroller->GetRigidBody();
@@ -1181,7 +1195,9 @@ void      KX_ConvertBulletObject( class   KX_GameObject* gameobj,
        }
 
        bool isActor = objprop->m_isactor;
-       gameobj->getClientInfo()->m_type = (isActor ? KX_ClientObjectInfo::ACTOR : KX_ClientObjectInfo::STATIC);
+       gameobj->getClientInfo()->m_type = 
+               (isbulletsensor) ? KX_ClientObjectInfo::OBSENSOR : 
+               (isActor) ? KX_ClientObjectInfo::ACTOR : KX_ClientObjectInfo::STATIC;
        // store materialname in auxinfo, needed for touchsensors
        if (meshobj)
        {
index 79519bf..1d7bf56 100644 (file)
@@ -332,7 +332,7 @@ void KX_GameObject::ProcessReplica()
                
 }
 
-static void setGraphicController_recursive(SG_Node* node, bool v)
+static void setGraphicController_recursive(SG_Node* node)
 {
        NodeList& children = node->GetSGChildren();
 
@@ -341,24 +341,24 @@ static void setGraphicController_recursive(SG_Node* node, bool v)
                SG_Node* childnode = (*childit);
                KX_GameObject *clientgameobj = static_cast<KX_GameObject*>( (*childit)->GetSGClientObject());
                if (clientgameobj != NULL) // This is a GameObject
-                       clientgameobj->ActivateGraphicController(v, false);
+                       clientgameobj->ActivateGraphicController(false);
                
                // if the childobj is NULL then this may be an inverse parent link
                // so a non recursive search should still look down this node.
-               setGraphicController_recursive(childnode, v);
+               setGraphicController_recursive(childnode);
        }
 }
 
 
-void KX_GameObject::ActivateGraphicController(bool active, bool recurse)
+void KX_GameObject::ActivateGraphicController(bool recurse)
 {
        if (m_pGraphicController)
        {
-               m_pGraphicController->Activate(active);
+               m_pGraphicController->Activate(m_bVisible);
        }
        if (recurse)
        {
-               setGraphicController_recursive(GetSGNode(), active);
+               setGraphicController_recursive(GetSGNode());
        }
 }
 
@@ -538,6 +538,20 @@ void KX_GameObject::UpdateTransformFunc(SG_IObject* node, void* gameobj, void* s
        ((KX_GameObject*)gameobj)->UpdateTransform();
 }
 
+void KX_GameObject::SynchronizeTransform()
+{
+       // only used for sensor object, do full synchronization as bullet doesn't do it
+       if (m_pPhysicsController1)
+               m_pPhysicsController1->SetTransform();
+       if (m_pGraphicController)
+               m_pGraphicController->SetGraphicTransform();
+}
+
+void KX_GameObject::SynchronizeTransformFunc(SG_IObject* node, void* gameobj, void* scene)
+{
+       ((KX_GameObject*)gameobj)->SynchronizeTransform();
+}
+
 
 void KX_GameObject::SetDebugColor(unsigned int bgra)
 {
index e5b2653..e0e7891 100644 (file)
@@ -384,7 +384,7 @@ public:
        /*
         * @add/remove the graphic controller to the physic system
         */
-       void ActivateGraphicController(bool active, bool recurse);
+       void ActivateGraphicController(bool recurse);
 
        /**
         * @section Coordinate system manipulation functions
@@ -559,6 +559,13 @@ public:
 
        static void UpdateTransformFunc(SG_IObject* node, void* gameobj, void* scene);
 
+       /**
+        * only used for sensor objects
+        */
+       void SynchronizeTransform();
+
+       static void SynchronizeTransformFunc(SG_IObject* node, void* gameobj, void* scene);
+
        /**
         * Function to set IPO option at start of IPO
         */ 
index a38222c..673acab 100644 (file)
 
 #include "PHY_DynamicTypes.h"
 
-KX_IPhysicsController::KX_IPhysicsController(bool dyna, bool compound, void* userdata)
+KX_IPhysicsController::KX_IPhysicsController(bool dyna, bool sensor, bool compound, void* userdata)
 
 :      m_bDyna(dyna),
+       m_bSensor(sensor),
        m_bCompound(compound),
        m_suspendDynamics(false),
        m_userdata(userdata)
index 10b66da..81c0104 100644 (file)
@@ -49,11 +49,12 @@ class KX_IPhysicsController : public SG_Controller
 {
 protected:
        bool            m_bDyna;
+       bool            m_bSensor;
        bool            m_bCompound;
        bool            m_suspendDynamics;
        void*           m_userdata;
 public:
-       KX_IPhysicsController(bool dyna,bool compound, void* userdata);
+       KX_IPhysicsController(bool dyna,bool sensor,bool compound, void* userdata);
        virtual ~KX_IPhysicsController();
 
 
@@ -74,6 +75,7 @@ public:
 
        virtual void    getOrientation(MT_Quaternion& orn)=0;
        virtual void setOrientation(const MT_Matrix3x3& orn)=0;
+       virtual void SetTransform()=0;
        //virtual       void setOrientation(const MT_Quaternion& orn)=0;
        virtual void setPosition(const MT_Point3& pos)=0;
        virtual void setScaling(const MT_Vector3& scaling)=0;
@@ -100,10 +102,18 @@ public:
                m_bDyna = isDynamic;
        }
 
+       void    SetSensor(bool isSensor) {
+               m_bSensor = isSensor;
+       }
+
        bool    IsDyna(void) {
                return m_bDyna;
        }
 
+       bool    IsSensor(void) {
+               return m_bSensor;
+       }
+
        bool    IsCompound(void) {
                return m_bCompound;
        }
index b4d58dc..60455d3 100644 (file)
@@ -73,6 +73,11 @@ void KX_MotionState::getWorldOrientation(float* ori)
        mat.getValue(ori);
 }
        
+void   KX_MotionState::setWorldOrientation(const float* ori)
+{
+       m_node->SetLocalOrientation(ori);
+}
+       
 void   KX_MotionState::setWorldPosition(float posX,float posY,float posZ)
 {
        m_node->SetLocalPosition(MT_Point3(posX,posY,posZ));
index 7ba3ca2..0e43e88 100644 (file)
@@ -45,6 +45,7 @@ public:
        virtual void    setWorldPosition(float posX,float posY,float posZ);
        virtual void    setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal);
        virtual void    getWorldOrientation(float* ori);
+       virtual void    setWorldOrientation(const float* ori);
 
        virtual void    calculateWorldTransformations();
 };
index a3c4e95..44842b7 100644 (file)
@@ -36,6 +36,7 @@
 #include "KX_Scene.h" // needed to create a replica
 #include "PHY_IPhysicsEnvironment.h"
 #include "PHY_IPhysicsController.h"
+#include "PHY_IMotionState.h"
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -62,7 +63,7 @@ KX_NearSensor::KX_NearSensor(SCA_EventManager* eventmgr,
 {
 
        gameobj->getClientInfo()->m_sensors.remove(this);
-       m_client_info = new KX_ClientObjectInfo(gameobj, KX_ClientObjectInfo::NEAR);
+       m_client_info = new KX_ClientObjectInfo(gameobj, KX_ClientObjectInfo::SENSOR);
        m_client_info->m_sensors.push_back(this);
        
        //DT_ShapeHandle shape = (DT_ShapeHandle) vshape;
@@ -81,28 +82,14 @@ void KX_NearSensor::SynchronizeTransform()
        // not linked to the parent object, must synchronize it.
        if (m_physCtrl)
        {
+               PHY_IMotionState* motionState = m_physCtrl->GetMotionState();
                KX_GameObject* parent = ((KX_GameObject*)GetParent());
-               MT_Vector3 pos = parent->NodeGetWorldPosition();
-               MT_Quaternion orn = parent->NodeGetWorldOrientation().getRotation();
-               m_physCtrl->setPosition(pos.x(),pos.y(),pos.z());
-               m_physCtrl->setOrientation(orn.x(),orn.y(),orn.z(),orn.w());
-               m_physCtrl->calcXform();
-       }
-}
-
-void KX_NearSensor::RegisterSumo(KX_TouchEventManager *touchman)
-{
-       if (m_physCtrl)
-       {
-               touchman->GetPhysicsEnvironment()->addSensor(m_physCtrl);
-       }
-}
-
-void KX_NearSensor::UnregisterSumo(KX_TouchEventManager* touchman)
-{
-       if (m_physCtrl)
-       {
-               touchman->GetPhysicsEnvironment()->removeSensor(m_physCtrl);
+               const MT_Point3& pos = parent->NodeGetWorldPosition();
+               float ori[12];
+               parent->NodeGetWorldOrientation().getValue(ori);
+               motionState->setWorldPosition(pos[0], pos[1], pos[2]);
+               motionState->setWorldOrientation(ori);
+               m_physCtrl->WriteMotionStateToDynamics(true);
        }
 }
 
@@ -117,7 +104,7 @@ void KX_NearSensor::ProcessReplica()
 {
        KX_TouchSensor::ProcessReplica();
        
-       m_client_info = new KX_ClientObjectInfo(m_client_info->m_gameobject, KX_ClientObjectInfo::NEAR);
+       m_client_info = new KX_ClientObjectInfo(m_client_info->m_gameobject, KX_ClientObjectInfo::SENSOR);
        
        if (m_physCtrl)
        {
@@ -134,11 +121,11 @@ void KX_NearSensor::ProcessReplica()
 
 void KX_NearSensor::ReParent(SCA_IObject* parent)
 {
+       SCA_ISensor::ReParent(parent);
        m_client_info->m_gameobject = static_cast<KX_GameObject*>(parent); 
        m_client_info->m_sensors.push_back(this);
        //Synchronize here with the actual parent.
        SynchronizeTransform();
-       SCA_ISensor::ReParent(parent);
 }
 
 
index 35136b7..d98b464 100644 (file)
@@ -77,8 +77,8 @@ public:
        virtual bool    NewHandleCollision(void* obj1,void* obj2,
                                                 const PHY_CollData * coll_data); 
        virtual bool    BroadPhaseFilterCollision(void*obj1,void*obj2);
-       virtual void RegisterSumo(KX_TouchEventManager *touchman);
-       virtual void UnregisterSumo(KX_TouchEventManager* touchman);
+       virtual bool    BroadPhaseSensorFilterCollision(void*obj1,void*obj2) { return false; };
+       virtual sensortype GetSensorType() { return NEAR; }
 
        /* --------------------------------------------------------------------- */
        /* Python interface ---------------------------------------------------- */
index 21b7e63..8c3974c 100644 (file)
@@ -70,6 +70,7 @@ public:
        virtual void setOrientation(const MT_Matrix3x3& orn);
        virtual void setPosition(const MT_Point3& pos);
        virtual void setScaling(const MT_Vector3& scaling);
+       virtual void SetTransform() {}
        virtual MT_Scalar       GetMass();
        virtual MT_Vector3      getReactionForce();
        virtual void    setRigidBody(bool rigid);
index 4532224..064dc91 100644 (file)
@@ -30,6 +30,7 @@
 #include "KX_GameObject.h"
 #include "KX_PyMath.h"
 #include "PHY_IPhysicsController.h"
+#include "PHY_IMotionState.h"
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -66,7 +67,7 @@ KX_RadarSensor::KX_RadarSensor(SCA_EventManager* eventmgr,
                                m_coneheight(coneheight),
                                m_axis(axis)
 {
-       m_client_info->m_type = KX_ClientObjectInfo::RADAR;
+       m_client_info->m_type = KX_ClientObjectInfo::SENSOR;
        //m_client_info->m_clientobject = gameobj;
        //m_client_info->m_auxilary_info = NULL;
        //sumoObj->setClientObject(&m_client_info);
@@ -84,12 +85,6 @@ CValue* KX_RadarSensor::GetReplica()
        return replica;
 }
 
-void KX_RadarSensor::ProcessReplica()
-{
-       KX_NearSensor::ProcessReplica();
-       m_client_info->m_type = KX_ClientObjectInfo::RADAR;
-}
-
 /**
  *     Transforms the collision object. A cone is not correctly centered
  *     for usage.  */
@@ -169,11 +164,13 @@ void KX_RadarSensor::SynchronizeTransform()
 
        if (m_physCtrl)
        {
-               MT_Quaternion orn = trans.getRotation();
-               MT_Point3 pos = trans.getOrigin();
-               m_physCtrl->setPosition(pos[0],pos[1],pos[2]);
-               m_physCtrl->setOrientation(orn[0],orn[1],orn[2],orn[3]);
-               m_physCtrl->calcXform();
+               PHY_IMotionState* motionState = m_physCtrl->GetMotionState();
+               const MT_Point3& pos = trans.getOrigin();
+               float ori[12];
+               trans.getBasis().getValue(ori);
+               motionState->setWorldPosition(pos[0], pos[1], pos[2]);
+               motionState->setWorldOrientation(ori);
+               m_physCtrl->WriteMotionStateToDynamics(true);
        }
 
 }
index b426879..6779a9e 100644 (file)
@@ -76,7 +76,6 @@ public:
        virtual ~KX_RadarSensor();
        virtual void SynchronizeTransform();
        virtual CValue* GetReplica();
-       virtual void ProcessReplica();
 
        /* --------------------------------------------------------------------- */
        /* Python interface ---------------------------------------------------- */
@@ -93,6 +92,7 @@ public:
        virtual PyObject* py_getattro(PyObject *attr);
        virtual PyObject* py_getattro_dict();
        virtual int py_setattro(PyObject *attr, PyObject* value);
+       virtual sensortype GetSensorType() { return RADAR; }
 
        //Deprecated ----->
        KX_PYMETHOD_DOC_NOARGS(KX_RadarSensor,GetConeOrigin);
index 9502599..bb5e087 100644 (file)
@@ -737,7 +737,7 @@ void KX_Scene::DupliGroupRecurse(CValue* obj, int level)
                replica->GetSGNode()->SetBBox(gameobj->GetSGNode()->BBox());
                replica->GetSGNode()->SetRadius(gameobj->GetSGNode()->Radius());
                // we can now add the graphic controller to the physic engine
-               replica->ActivateGraphicController(true,true);
+               replica->ActivateGraphicController(true);
 
                // done with replica
                replica->Release();
@@ -850,7 +850,7 @@ SCA_IObject* KX_Scene::AddReplicaObject(class CValue* originalobject,
        replica->GetSGNode()->SetBBox(originalobj->GetSGNode()->BBox());
        replica->GetSGNode()->SetRadius(originalobj->GetSGNode()->Radius());
        // the size is correct, we can add the graphic controller to the physic engine
-       replica->ActivateGraphicController(true,true);
+       replica->ActivateGraphicController(true);
 
        // now replicate logic
        vector<KX_GameObject*>::iterator git;
index 083d898..278994c 100644 (file)
@@ -53,7 +53,7 @@ public:
                class SM_Object* sumoObj,       
                class PHY_IMotionState* motionstate
                ,bool dyna) 
-               : KX_IPhysicsController(dyna,false,NULL) ,
+               : KX_IPhysicsController(dyna,false,false,NULL) ,
                  SumoPhysicsController(sumoScene,/*solidscene,*/sumoObj,motionstate,dyna)
        {
        };
@@ -83,6 +83,7 @@ public:
 
        virtual void    getOrientation(MT_Quaternion& orn);
        virtual void setOrientation(const MT_Matrix3x3& orn);
+       virtual void SetTransform() {}
        
        virtual void setPosition(const MT_Point3& pos);
        virtual void setScaling(const MT_Vector3& scaling);
index 8ae5fae..4692754 100644 (file)
@@ -85,14 +85,34 @@ bool         KX_TouchEventManager::newBroadphaseResponse(void *client_data,
        PHY_IPhysicsController* ctrl = static_cast<PHY_IPhysicsController*>(object1);
        KX_ClientObjectInfo* info = (ctrl) ? static_cast<KX_ClientObjectInfo*>(ctrl->getNewClientInfo()) : NULL;
        // This call back should only be called for controllers of Near and Radar sensor
-       if (info &&
-        info->m_sensors.size() == 1 &&
-               (info->m_type == KX_ClientObjectInfo::NEAR ||
-                info->m_type == KX_ClientObjectInfo::RADAR))
+       if (!info)
+               return true;
+
+       switch (info->m_type)
        {
-               // only one sensor for this type of object
-               KX_TouchSensor* touchsensor = static_cast<KX_TouchSensor*>(*info->m_sensors.begin());
-               return touchsensor->BroadPhaseFilterCollision(object1,object2);
+       case KX_ClientObjectInfo::SENSOR:
+               if (info->m_sensors.size() == 1)
+               {
+                       // only one sensor for this type of object
+                       KX_TouchSensor* touchsensor = static_cast<KX_TouchSensor*>(*info->m_sensors.begin());
+                       return touchsensor->BroadPhaseFilterCollision(object1,object2);
+               }
+               break;
+       case KX_ClientObjectInfo::OBSENSOR:
+               // this object may have multiple collision sensors, 
+               // check is any of them is interested in this object
+               for(std::list<SCA_ISensor*>::iterator it = info->m_sensors.begin();
+                       it != info->m_sensors.end();
+                       ++it)
+               {
+                       if ((*it)->GetSensorType() == SCA_ISensor::TOUCH) 
+                       {
+                               KX_TouchSensor* touchsensor = static_cast<KX_TouchSensor*>(*it);
+                               if (touchsensor->BroadPhaseSensorFilterCollision(object1, object2))
+                                       return true;
+                       }
+               }
+               return false;
        }
        return true;
 }
index 8c0d559..509fc60 100644 (file)
@@ -173,19 +173,65 @@ void KX_TouchSensor::RegisterSumo(KX_TouchEventManager *touchman)
 {
        if (m_physCtrl)
        {
-               touchman->GetPhysicsEnvironment()->requestCollisionCallback(m_physCtrl);
-               // collision
-               // Deprecated   
-
+               if (touchman->GetPhysicsEnvironment()->requestCollisionCallback(m_physCtrl))
+               {
+                       KX_ClientObjectInfo* client_info = static_cast<KX_ClientObjectInfo*>(m_physCtrl->getNewClientInfo());
+                       if (client_info->isSensor())
+                               touchman->GetPhysicsEnvironment()->addSensor(m_physCtrl);
+               }
        }
 }
-
 void KX_TouchSensor::UnregisterSumo(KX_TouchEventManager* touchman)
 {
        if (m_physCtrl)
        {
-               touchman->GetPhysicsEnvironment()->removeCollisionCallback(m_physCtrl);
+               if (touchman->GetPhysicsEnvironment()->removeCollisionCallback(m_physCtrl))
+               {
+                       // no more sensor on the controller, can remove it if it is a sensor object
+                       KX_ClientObjectInfo* client_info = static_cast<KX_ClientObjectInfo*>(m_physCtrl->getNewClientInfo());
+                       if (client_info->isSensor())
+                               touchman->GetPhysicsEnvironment()->removeSensor(m_physCtrl);
+               }
+       }
+}
+
+// this function is called only for sensor objects
+// return true if the controller can collide with the object
+bool   KX_TouchSensor::BroadPhaseSensorFilterCollision(void*obj1,void*obj2)
+{
+       assert(obj1==m_physCtrl && obj2);
+
+       KX_GameObject* myobj = (KX_GameObject*)GetParent();
+       KX_GameObject* myparent = myobj->GetParent();
+       KX_ClientObjectInfo* client_info = static_cast<KX_ClientObjectInfo*>(((PHY_IPhysicsController*)obj2)->getNewClientInfo());
+       KX_GameObject* otherobj = ( client_info ? client_info->m_gameobject : NULL);
+
+       // first, decrement refcount as GetParent() increases it
+       if (myparent)
+               myparent->Release();
+
+       // we can only check on persistent characteristic: m_link and m_suspended are not
+       // good candidate because they are transient. That must be handled at another level
+       if (!otherobj ||
+               otherobj == myparent ||         // don't interact with our parent
+               client_info->m_type != KX_ClientObjectInfo::ACTOR)      // only with actor objects
+               return false;
+               
+       bool found = m_touchedpropname.IsEmpty();
+       if (!found)
+       {
+               if (m_bFindMaterial)
+               {
+                       if (client_info->m_auxilary_info)
+                       {
+                               found = (!strcmp(m_touchedpropname.Ptr(), (char*)client_info->m_auxilary_info));
+                       }
+               } else
+               {
+                       found = (otherobj->GetProperty(m_touchedpropname) != NULL);
+               }
        }
+       return found;
 }
 
 bool   KX_TouchSensor::NewHandleCollision(void*object1,void*object2,const PHY_CollData* colldata)
index 9c9c6bf..b62ec6e 100644 (file)
@@ -103,7 +103,8 @@ public:
        // obj1 = sensor physical controller, obj2 = physical controller of second object
        // return value = true if collision should be checked on pair of object
        virtual bool    BroadPhaseFilterCollision(void*obj1,void*obj2) { return true; }
-
+       virtual bool    BroadPhaseSensorFilterCollision(void*obj1,void*obj2);
+       virtual sensortype GetSensorType() { return TOUCH; }
   
 
        virtual bool IsPositiveTrigger() {
index efe4554..5efd099 100644 (file)
@@ -379,7 +379,10 @@ bool ODEPhysicsController::SynchronizeMotionStates(float time)
   return false; //it update the worldpos
 }
  
-
+PHY_IMotionState* ODEPhysicsController::GetMotionState()
+{
+       return m_MotionState;
+}
 
 
 // kinematic methods
index e97afdb..544d11d 100644 (file)
@@ -102,6 +102,7 @@ public:
 
        virtual void            WriteDynamicsToMotionState() {};
        virtual void    WriteMotionStateToDynamics(bool nondynaonly);
+       virtual class PHY_IMotionState* GetMotionState();
 
        /** 
                call from Scene Graph Node to 'update'.
index 82e26e0..54e4f7f 100644 (file)
@@ -64,8 +64,8 @@ public:
        virtual void addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user)
        {
        }
-       virtual void requestCollisionCallback(PHY_IPhysicsController* ctrl) {}
-       virtual void removeCollisionCallback(PHY_IPhysicsController* ctrl) {}
+       virtual bool requestCollisionCallback(PHY_IPhysicsController* ctrl) {return false;}
+       virtual bool removeCollisionCallback(PHY_IPhysicsController* ctrl) {return false;}
        virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) {return 0;}
        virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight) { return 0;}
 
index 01e8aa2..7302c47 100644 (file)
@@ -92,16 +92,19 @@ CcdPhysicsController::CcdPhysicsController (const CcdConstructionInfo& ci)
 
 }
 
-btTransform    CcdPhysicsController::GetTransformFromMotionState(PHY_IMotionState* motionState)
+btTransform&   CcdPhysicsController::GetTransformFromMotionState(PHY_IMotionState* motionState)
 {
-       btTransform trans;
-       float tmp[3];
-       motionState->getWorldPosition(tmp[0],tmp[1],tmp[2]);
-       trans.setOrigin(btVector3(tmp[0],tmp[1],tmp[2]));
-
-       btQuaternion orn;
-       motionState->getWorldOrientation(orn[0],orn[1],orn[2],orn[3]);
-       trans.setRotation(orn);
+       static btTransform trans;
+       btVector3 tmp;
+       motionState->getWorldPosition(tmp.m_floats[0], tmp.m_floats[1], tmp.m_floats[2]);
+       trans.setOrigin(tmp);
+
+       float ori[12];
+       motionState->getWorldOrientation(ori);
+       trans.getBasis().setFromOpenGLSubMatrix(ori);
+       //btQuaternion orn;
+       //motionState->getWorldOrientation(orn[0],orn[1],orn[2],orn[3]);
+       //trans.setRotation(orn);
        return trans;
 
 }
@@ -118,18 +121,18 @@ public:
 
        }
 
-       virtual void    getWorldTransform(btTransform& worldTrans ) const
+       void    getWorldTransform(btTransform& worldTrans ) const
        {
-               float pos[3];
-               float quatOrn[4];
+               btVector3 pos;
+               float ori[12];
 
-               m_blenderMotionState->getWorldPosition(pos[0],pos[1],pos[2]);
-               m_blenderMotionState->getWorldOrientation(quatOrn[0],quatOrn[1],quatOrn[2],quatOrn[3]);
-               worldTrans.setOrigin(btVector3(pos[0],pos[1],pos[2]));
-               worldTrans.setBasis(btMatrix3x3(btQuaternion(quatOrn[0],quatOrn[1],quatOrn[2],quatOrn[3])));
+               m_blenderMotionState->getWorldPosition(pos.m_floats[0],pos.m_floats[1],pos.m_floats[2]);
+               m_blenderMotionState->getWorldOrientation(ori);
+               worldTrans.setOrigin(pos);
+               worldTrans.getBasis().setFromOpenGLSubMatrix(ori);
        }
 
-       virtual void    setWorldTransform(const btTransform& worldTrans)
+       void    setWorldTransform(const btTransform& worldTrans)
        {
                m_blenderMotionState->setWorldPosition(worldTrans.getOrigin().getX(),worldTrans.getOrigin().getY(),worldTrans.getOrigin().getZ());
                btQuaternion rotQuat = worldTrans.getRotation();
@@ -493,10 +496,12 @@ void CcdPhysicsController::CreateRigidbody()
        //convert collision flags!
        //special case: a near/radar sensor controller should not be defined static or it will
        //generate loads of static-static collision messages on the console
-       if ((m_cci.m_collisionFilterGroup & CcdConstructionInfo::SensorFilter) != 0)
+       if (m_cci.m_bSensor)
        {
                // reset the flags that have been set so far
                GetCollisionObject()->setCollisionFlags(0);
+               // sensor must never go to sleep: they need to detect continously
+               GetCollisionObject()->setActivationState(DISABLE_DEACTIVATION);
        }
        GetCollisionObject()->setCollisionFlags(m_object->getCollisionFlags() | m_cci.m_collisionFlags);
        btRigidBody* body = GetRigidBody();
@@ -613,12 +618,13 @@ bool              CcdPhysicsController::SynchronizeMotionStates(float time)
                                body->setLinearVelocity(linvel * (m_cci.m_clamp_vel_min / len));
                }
                
-               const btVector3& worldPos = body->getCenterOfMassPosition();
+               const btTransform& xform = body->getCenterOfMassTransform();
+               const btMatrix3x3& worldOri = xform.getBasis();
+               const btVector3& worldPos = xform.getOrigin();
+               float ori[12];
+               worldOri.getOpenGLSubMatrix(ori);
+               m_MotionState->setWorldOrientation(ori);
                m_MotionState->setWorldPosition(worldPos[0],worldPos[1],worldPos[2]);
-               
-               const btQuaternion& worldquat = body->getOrientation();
-               m_MotionState->setWorldOrientation(worldquat[0],worldquat[1],worldquat[2],worldquat[3]);
-
                m_MotionState->calculateWorldTransformations();
 
                float scale[3];
@@ -655,8 +661,10 @@ bool               CcdPhysicsController::SynchronizeMotionStates(float time)
                
 void           CcdPhysicsController::WriteMotionStateToDynamics(bool nondynaonly)
 {
-
+       btTransform& xform = CcdPhysicsController::GetTransformFromMotionState(m_MotionState);
+       SetCenterOfMassTransform(xform);
 }
+
 void           CcdPhysicsController::WriteDynamicsToMotionState()
 {
 }
@@ -673,12 +681,12 @@ void              CcdPhysicsController::PostProcessReplica(class PHY_IMotionState* motionsta
        if (m_shapeInfo)
        {
                m_shapeInfo->AddRef();
-               m_collisionShape = m_shapeInfo->CreateBulletShape();
+               m_collisionShape = m_shapeInfo->CreateBulletShape(m_cci.m_margin);
 
                if (m_collisionShape)
                {
                        // new shape has no scaling, apply initial scaling
-                       m_collisionShape->setMargin(m_cci.m_margin);
+                       //m_collisionShape->setMargin(m_cci.m_margin);
                        m_collisionShape->setLocalScaling(m_cci.m_scaling);
                        
                        if (m_cci.m_mass)
@@ -697,8 +705,10 @@ void               CcdPhysicsController::PostProcessReplica(class PHY_IMotionState* motionsta
                {
                        body->setMassProps(m_cci.m_mass, m_cci.m_localInertiaTensor * m_cci.m_inertiaFactor);
                }
-       }                       
-       m_cci.m_physicsEnv->addCcdPhysicsController(this);
+       }       
+       // sensor object are added when needed
+       if (!m_cci.m_bSensor)
+               m_cci.m_physicsEnv->addCcdPhysicsController(this);
 
 
 /*     SM_Object* dynaparent=0;
@@ -773,7 +783,7 @@ void                CcdPhysicsController::RelativeTranslate(float dlocX,float dlocY,float dloc
        if (m_object)
        {
                m_object->activate(true);
-               if (m_object->isStaticObject())
+               if (m_object->isStaticObject() && !m_cci.m_bSensor)
                {
                        m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
                }
@@ -799,7 +809,7 @@ void                CcdPhysicsController::RelativeRotate(const float rotval[9],bool local)
        if (m_object)
        {
                m_object->activate(true);
-               if (m_object->isStaticObject())
+               if (m_object->isStaticObject() && !m_cci.m_bSensor)
                {
                        m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
                }
@@ -843,7 +853,7 @@ void                CcdPhysicsController::setOrientation(float quatImag0,float quatImag1,float
        if (m_object)
        {
                m_object->activate(true);
-               if (m_object->isStaticObject())
+               if (m_object->isStaticObject() && !m_cci.m_bSensor)
                {
                        m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
                }
@@ -866,7 +876,7 @@ void CcdPhysicsController::setWorldOrientation(const btMatrix3x3& orn)
        if (m_object)
        {
                m_object->activate(true);
-               if (m_object->isStaticObject())
+               if (m_object->isStaticObject() && !m_cci.m_bSensor)
                {
                        m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
                }
@@ -895,7 +905,7 @@ void                CcdPhysicsController::setPosition(float posX,float posY,float posZ)
        if (m_object)
        {
                m_object->activate(true);
-               if (m_object->isStaticObject())
+               if (m_object->isStaticObject() && !m_cci.m_bSensor)
                {
                        m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
                }
@@ -909,9 +919,19 @@ void               CcdPhysicsController::setPosition(float posX,float posY,float posZ)
                // not required
                //m_bulletMotionState->setWorldTransform(xform);
        }
+}
 
-
+void CcdPhysicsController::forceWorldTransform(const btMatrix3x3& mat, const btVector3& pos)
+{
+       if (m_object)
+       {
+               btTransform& xform = m_object->getWorldTransform();
+               xform.setBasis(mat);
+               xform.setOrigin(pos);
+       }
 }
+
+
 void           CcdPhysicsController::resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ)
 {
 }
@@ -961,7 +981,9 @@ void                CcdPhysicsController::ApplyTorque(float torqueX,float torqueY,float torque
                m_object->activate();
                if (m_object->isStaticObject())
                {
-                       m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
+                       if (!m_cci.m_bSensor)
+                               m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
+                       return;
                }
                if (local)
                {
@@ -989,27 +1011,26 @@ void             CcdPhysicsController::ApplyForce(float forceX,float forceY,float forceZ,bo
                m_object->activate();
                if (m_object->isStaticObject())
                {
-                       m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
+                       if (!m_cci.m_bSensor)
+                               m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
+                       return;
                }
-
+               btTransform xform = m_object->getWorldTransform();
+               
+               if (local)
+               {       
+                       force   = xform.getBasis()*force;
+               }
+               btRigidBody* body = GetRigidBody();
+               if (body)
+                       body->applyCentralForce(force);
+               btSoftBody* soft = GetSoftBody();
+               if (soft)
                {
-                       btTransform xform = m_object->getWorldTransform();
-                       
-                       if (local)
-                       {       
-                               force   = xform.getBasis()*force;
-                       }
-                       btRigidBody* body = GetRigidBody();
-                       if (body)
-                               body->applyCentralForce(force);
-                       btSoftBody* soft = GetSoftBody();
-                       if (soft)
-                       {
-                               // the force is applied on each node, must reduce it in the same extend
-                               if (soft->m_nodes.size() > 0)
-                                       force /= soft->m_nodes.size();
-                               soft->addForce(force);
-                       }
+                       // the force is applied on each node, must reduce it in the same extend
+                       if (soft->m_nodes.size() > 0)
+                               force /= soft->m_nodes.size();
+                       soft->addForce(force);
                }
        }
 }
@@ -1021,19 +1042,18 @@ void            CcdPhysicsController::SetAngularVelocity(float ang_velX,float ang_velY,flo
                m_object->activate(true);
                if (m_object->isStaticObject())
                {
-                       m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
-               } else
+                       if (!m_cci.m_bSensor)
+                               m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
+                       return;
+               }
+               btTransform xform = m_object->getWorldTransform();
+               if (local)
                {
-                       btTransform xform = m_object->getWorldTransform();
-                       if (local)
-                       {
-                               angvel  = xform.getBasis()*angvel;
-                       }
-                       btRigidBody* body = GetRigidBody();
-                       if (body)
-                               body->setAngularVelocity(angvel);
-
+                       angvel  = xform.getBasis()*angvel;
                }
+               btRigidBody* body = GetRigidBody();
+               if (body)
+                       body->setAngularVelocity(angvel);
        }
 
 }
@@ -1046,7 +1066,8 @@ void              CcdPhysicsController::SetLinearVelocity(float lin_velX,float lin_velY,floa
                m_object->activate(true);
                if (m_object->isStaticObject())
                {
-                       m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
+                       if (!m_cci.m_bSensor)
+                               m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
                        return;
                }
                
@@ -1080,7 +1101,9 @@ void              CcdPhysicsController::applyImpulse(float attachX,float attachY,float attac
                m_object->activate();
                if (m_object->isStaticObject())
                {
-                       m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
+                       if (!m_cci.m_bSensor)
+                               m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
+                       return;
                }
                
                btVector3 pos(attachX,attachY,attachZ);
@@ -1207,7 +1230,7 @@ PHY_IPhysicsController*   CcdPhysicsController::GetReplica()
        if (m_shapeInfo)
        {
                // This situation does not normally happen
-               cinfo.m_collisionShape = m_shapeInfo->CreateBulletShape();
+               cinfo.m_collisionShape = m_shapeInfo->CreateBulletShape(0.01);
        } 
        else if (m_collisionShape)
        {
@@ -1274,28 +1297,22 @@ void    DefaultMotionState::getWorldScaling(float& scaleX,float& scaleY,float& scal
 
 void   DefaultMotionState::getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal)
 {
-       quatIma0 = m_worldTransform.getRotation().x();
-       quatIma1 = m_worldTransform.getRotation().y();
-       quatIma2 = m_worldTransform.getRotation().z();
-       quatReal = m_worldTransform.getRotation()[3];
+       btQuaternion quat = m_worldTransform.getRotation();
+       quatIma0 = quat.x();
+       quatIma1 = quat.y();
+       quatIma2 = quat.z();
+       quatReal = quat[3];
 }
                
 void   DefaultMotionState::getWorldOrientation(float* ori)
 {
-       *ori++ = m_worldTransform.getBasis()[0].x();
-       *ori++ = m_worldTransform.getBasis()[1].x();
-       *ori++ = m_worldTransform.getBasis()[1].x();
-       *ori++ = 0.f;
-       *ori++ = m_worldTransform.getBasis()[0].y();
-       *ori++ = m_worldTransform.getBasis()[1].y();
-       *ori++ = m_worldTransform.getBasis()[1].y();
-       *ori++ = 0.f;
-       *ori++ = m_worldTransform.getBasis()[0].z();
-       *ori++ = m_worldTransform.getBasis()[1].z();
-       *ori++ = m_worldTransform.getBasis()[1].z();
-       *ori++ = 0.f;
+       m_worldTransform.getBasis().getOpenGLSubMatrix(ori);
 }
 
+void   DefaultMotionState::setWorldOrientation(const float* ori)
+{
+       m_worldTransform.getBasis().setFromOpenGLSubMatrix(ori);
+}
 void   DefaultMotionState::setWorldPosition(float posX,float posY,float posZ)
 {
        btVector3 pos(posX,posY,posZ);
@@ -1583,7 +1600,7 @@ bool CcdShapeConstructionInfo::SetProxy(CcdShapeConstructionInfo* shapeInfo)
        return true;
 }
 
-btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape()
+btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape(btScalar margin)
 {
        btCollisionShape* collisionShape = 0;
        btTriangleMeshShape* concaveShape = 0;
@@ -1591,7 +1608,7 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape()
        CcdShapeConstructionInfo* nextShapeInfo;
 
        if (m_shapeType == PHY_SHAPE_PROXY && m_shapeProxy != NULL)
-               return m_shapeProxy->CreateBulletShape();
+               return m_shapeProxy->CreateBulletShape(margin);
 
        switch (m_shapeType) 
        {
@@ -1600,22 +1617,27 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape()
 
        case PHY_SHAPE_BOX:
                collisionShape = new btBoxShape(m_halfExtend);
+               collisionShape->setMargin(margin);
                break;
 
        case PHY_SHAPE_SPHERE:
                collisionShape = new btSphereShape(m_radius);
+               collisionShape->setMargin(margin);
                break;
 
        case PHY_SHAPE_CYLINDER:
                collisionShape = new btCylinderShapeZ(m_halfExtend);
+               collisionShape->setMargin(margin);
                break;
 
        case PHY_SHAPE_CONE:
                collisionShape = new btConeShapeZ(m_radius, m_height);
+               collisionShape->setMargin(margin);
                break;
 
        case PHY_SHAPE_POLYTOPE:
                collisionShape = new btConvexHullShape(&m_vertexArray[0], m_vertexArray.size()/3, 3*sizeof(btScalar));
+               collisionShape->setMargin(margin);
                break;
 
        case PHY_SHAPE_MESH:
@@ -1638,7 +1660,7 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape()
                                );
                                
                                btGImpactMeshShape* gimpactShape =  new btGImpactMeshShape(indexVertexArrays);
-
+                               gimpactShape->setMargin(margin);
                                collisionShape = gimpactShape;
                                gimpactShape->updateBound();
 
@@ -1683,6 +1705,7 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape()
                                m_unscaledShape->recalcLocalAabb();
                        }
                        collisionShape = new btScaledBvhTriangleMeshShape(m_unscaledShape, btVector3(1.0f,1.0f,1.0f));
+                       collisionShape->setMargin(margin);
                }
                break;
 
@@ -1694,7 +1717,7 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape()
                                 sit != m_shapeArray.end();
                                 sit++)
                        {
-                               collisionShape = (*sit)->CreateBulletShape();
+                               collisionShape = (*sit)->CreateBulletShape(margin);
                                if (collisionShape)
                                {
                                        collisionShape->setLocalScaling((*sit)->m_childScale);
index 315e2bd..fc8de0e 100644 (file)
@@ -152,7 +152,7 @@ public:
                return m_shapeProxy;
        }
 
-       btCollisionShape* CreateBulletShape();
+       btCollisionShape* CreateBulletShape(btScalar margin);
 
        // member variables
        PHY_ShapeType                   m_shapeType;
@@ -222,6 +222,7 @@ struct CcdConstructionInfo
                m_collisionFlags(0),
                m_bRigid(false),
                m_bSoft(false),
+               m_bSensor(false),
                m_collisionFilterGroup(DefaultFilter),
                m_collisionFilterMask(AllFilter),
                m_collisionShape(0),
@@ -288,6 +289,7 @@ struct CcdConstructionInfo
        int                     m_collisionFlags;
        bool            m_bRigid;
        bool            m_bSoft;
+       bool            m_bSensor;
 
        ///optional use of collision group/mask:
        ///only collision with object goups that match the collision mask.
@@ -326,7 +328,7 @@ class btSoftBody;
 ///CcdPhysicsController is a physics object that supports continuous collision detection and time of impact based physics resolution.
 class CcdPhysicsController : public PHY_IPhysicsController     
 {
-
+protected:
        btCollisionObject* m_object;
        
 
@@ -361,8 +363,8 @@ class CcdPhysicsController : public PHY_IPhysicsController
                return (--m_registerCount == 0) ? true : false;
        }
 
-       protected:
-               void setWorldOrientation(const btMatrix3x3& mat);
+       void setWorldOrientation(const btMatrix3x3& mat);
+       void forceWorldTransform(const btMatrix3x3& mat, const btVector3& pos);
 
        public:
        
@@ -407,6 +409,7 @@ class CcdPhysicsController : public PHY_IPhysicsController
                
                virtual void            WriteMotionStateToDynamics(bool nondynaonly);
                virtual void            WriteDynamicsToMotionState();
+
                // controller replication
                virtual void            PostProcessReplica(class PHY_IMotionState* motionstate,class PHY_IPhysicsController* parentctrl);
 
@@ -505,7 +508,7 @@ class CcdPhysicsController : public PHY_IPhysicsController
 
                void    SetCenterOfMassTransform(btTransform& xform);
 
-               static btTransform      GetTransformFromMotionState(PHY_IMotionState* motionState);
+               static btTransform&     GetTransformFromMotionState(PHY_IMotionState* motionState);
 
                void    setAabb(const btVector3& aabbMin,const btVector3& aabbMax);
 
@@ -563,6 +566,7 @@ class       DefaultMotionState : public PHY_IMotionState
                virtual void    setWorldPosition(float posX,float posY,float posZ);
                virtual void    setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal);
                virtual void    getWorldOrientation(float* ori);
+               virtual void    setWorldOrientation(const float* ori);
                
                virtual void    calculateWorldTransformations();
                
index 03c9d13..ed517e6 100644 (file)
@@ -415,61 +415,7 @@ void       CcdPhysicsEnvironment::addCcdPhysicsController(CcdPhysicsController* ctrl)
                obj->setActivationState(ISLAND_SLEEPING);
        }
 
-
-       //CollisionObject(body,ctrl->GetCollisionFilterGroup(),ctrl->GetCollisionFilterMask());
-
        assert(obj->getBroadphaseHandle());
-
-       btBroadphaseInterface* scene =  getBroadphase();
-
-
-       btCollisionShape* shapeinterface = ctrl->GetCollisionShape();
-
-       assert(shapeinterface);
-
-       const btTransform& t = ctrl->GetCollisionObject()->getWorldTransform();
-       
-
-       btVector3 minAabb,maxAabb;
-
-       shapeinterface->getAabb(t,minAabb,maxAabb);
-
-       float timeStep = 0.02f;
-
-
-       //extent it with the motion
-
-       if (body)
-       {
-               btVector3 linMotion = body->getLinearVelocity()*timeStep;
-
-               float maxAabbx = maxAabb.getX();
-               float maxAabby = maxAabb.getY();
-               float maxAabbz = maxAabb.getZ();
-               float minAabbx = minAabb.getX();
-               float minAabby = minAabb.getY();
-               float minAabbz = minAabb.getZ();
-
-               if (linMotion.x() > 0.f)
-                       maxAabbx += linMotion.x(); 
-               else
-                       minAabbx += linMotion.x();
-               if (linMotion.y() > 0.f)
-                       maxAabby += linMotion.y(); 
-               else
-                       minAabby += linMotion.y();
-               if (linMotion.z() > 0.f)
-                       maxAabbz += linMotion.z(); 
-               else
-                       minAabbz += linMotion.z();
-
-
-               minAabb = btVector3(minAabbx,minAabby,minAabbz);
-               maxAabb = btVector3(maxAabbx,maxAabby,maxAabbz);
-       }
-
-
-
 }
 
                
@@ -1884,29 +1830,20 @@ void CcdPhysicsEnvironment::addSensor(PHY_IPhysicsController* ctrl)
        //      addCcdPhysicsController(ctrl1);
        //}
        enableCcdPhysicsController(ctrl1);
-
-       //Collision filter/mask is now set at the time of the creation of the controller 
-       //force collision detection with everything, including static objects (might hurt performance!)
-       //ctrl1->GetRigidBody()->getBroadphaseHandle()->m_collisionFilterMask = btBroadphaseProxy::AllFilter ^ btBroadphaseProxy::SensorTrigger;
-       //ctrl1->GetRigidBody()->getBroadphaseHandle()->m_collisionFilterGroup = btBroadphaseProxy::SensorTrigger;
-       //todo: make this 'sensor'!
-
-       requestCollisionCallback(ctrl);
-       //printf("addSensor\n");
 }
 
-void CcdPhysicsEnvironment::removeCollisionCallback(PHY_IPhysicsController* ctrl)
+bool CcdPhysicsEnvironment::removeCollisionCallback(PHY_IPhysicsController* ctrl)
 {
        CcdPhysicsController* ccdCtrl = (CcdPhysicsController*)ctrl;
-       if (ccdCtrl->Unregister())
-               m_triggerControllers.erase(ccdCtrl);
+       if (!ccdCtrl->Unregister())
+               return false;
+       m_triggerControllers.erase(ccdCtrl);
+       return true;
 }
 
 
 void CcdPhysicsEnvironment::removeSensor(PHY_IPhysicsController* ctrl)
 {
-       removeCollisionCallback(ctrl);
-
        disableCcdPhysicsController((CcdPhysicsController*)ctrl);
 }
 
@@ -1942,12 +1879,14 @@ void CcdPhysicsEnvironment::addTouchCallback(int response_class, PHY_ResponseCal
        m_triggerCallbacksUserPtrs[response_class] = user;
 
 }
-void CcdPhysicsEnvironment::requestCollisionCallback(PHY_IPhysicsController* ctrl)
+bool CcdPhysicsEnvironment::requestCollisionCallback(PHY_IPhysicsController* ctrl)
 {
        CcdPhysicsController* ccdCtrl = static_cast<CcdPhysicsController*>(ctrl);
 
-       if (ccdCtrl->Register())
-               m_triggerControllers.insert(ccdCtrl);
+       if (!ccdCtrl->Register())
+               return false;
+       m_triggerControllers.insert(ccdCtrl);
+       return true;
 }
 
 void   CcdPhysicsEnvironment::CallbackTriggers()
@@ -2096,12 +2035,13 @@ PHY_IPhysicsController* CcdPhysicsEnvironment::CreateSphereController(float radi
        // declare this object as Dyamic rather then static!!
        // The reason as it is designed to detect all type of object, including static object
        // It would cause static-static message to be printed on the console otherwise
-       cinfo.m_collisionFlags |= btCollisionObject::CF_NO_CONTACT_RESPONSE/* | btCollisionObject::CF_KINEMATIC_OBJECT*/;
+       cinfo.m_collisionFlags |= btCollisionObject::CF_NO_CONTACT_RESPONSE | btCollisionObject::CF_STATIC_OBJECT;
        DefaultMotionState* motionState = new DefaultMotionState();
        cinfo.m_MotionState = motionState;
        // we will add later the possibility to select the filter from option
        cinfo.m_collisionFilterMask = CcdConstructionInfo::AllFilter ^ CcdConstructionInfo::SensorFilter;
        cinfo.m_collisionFilterGroup = CcdConstructionInfo::SensorFilter;
+       cinfo.m_bSensor = true;
        motionState->m_worldTransform.setIdentity();
        motionState->m_worldTransform.setOrigin(btVector3(position[0],position[1],position[2]));
 
@@ -2555,13 +2495,14 @@ PHY_IPhysicsController* CcdPhysicsEnvironment::CreateConeController(float conera
        cinfo.m_collisionShape = new btConeShape(coneradius,coneheight);
        cinfo.m_MotionState = 0;
        cinfo.m_physicsEnv = this;
-       cinfo.m_collisionFlags |= btCollisionObject::CF_NO_CONTACT_RESPONSE;
+       cinfo.m_collisionFlags |= btCollisionObject::CF_NO_CONTACT_RESPONSE | btCollisionObject::CF_STATIC_OBJECT;
        DefaultMotionState* motionState = new DefaultMotionState();
        cinfo.m_MotionState = motionState;
        
        // we will add later the possibility to select the filter from option
        cinfo.m_collisionFilterMask = CcdConstructionInfo::AllFilter ^ CcdConstructionInfo::SensorFilter;
        cinfo.m_collisionFilterGroup = CcdConstructionInfo::SensorFilter;
+       cinfo.m_bSensor = true;
        motionState->m_worldTransform.setIdentity();
 //     motionState->m_worldTransform.setOrigin(btVector3(position[0],position[1],position[2]));
 
index 5f9fb95..4e39d53 100644 (file)
@@ -179,8 +179,8 @@ protected:
                virtual void addSensor(PHY_IPhysicsController* ctrl);
                virtual void removeSensor(PHY_IPhysicsController* ctrl);
                virtual void addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user);
-               virtual void requestCollisionCallback(PHY_IPhysicsController* ctrl);
-               virtual void removeCollisionCallback(PHY_IPhysicsController* ctrl);
+               virtual bool requestCollisionCallback(PHY_IPhysicsController* ctrl);
+               virtual bool removeCollisionCallback(PHY_IPhysicsController* ctrl);
                //These two methods are used *solely* to create controllers for Near/Radar sensor! Don't use for anything else
                virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position);
                virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight);
index 397a1ba..73e7e94 100644 (file)
@@ -79,8 +79,8 @@ public:
                virtual void addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user)
                {
                }
-               virtual void requestCollisionCallback(PHY_IPhysicsController* ctrl) {}
-               virtual void removeCollisionCallback(PHY_IPhysicsController* ctrl) {}
+               virtual bool requestCollisionCallback(PHY_IPhysicsController* ctrl) { return false; }
+               virtual bool removeCollisionCallback(PHY_IPhysicsController* ctrl) { return false;}
                virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) {return 0;}
                virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight) { return 0;}
 
index 3451e6c..56caa92 100644 (file)
@@ -390,6 +390,11 @@ void               SumoPhysicsController::PostProcessReplica(class PHY_IMotionState* motionst
        m_sumoScene->add(* (m_sumoObj));
 }
 
+PHY_IMotionState* SumoPhysicsController::GetMotionState()
+{
+       return m_MotionState;
+}
+
 void                   SumoPhysicsController::SetSimulatedTime(float)
 {
 }
index 415bc1e..adf2964 100644 (file)
@@ -110,6 +110,7 @@ public:
        
        virtual void            WriteDynamicsToMotionState() {};
        virtual void    WriteMotionStateToDynamics(bool nondynaonly);
+       virtual class PHY_IMotionState* GetMotionState();
 
        /** 
         *      call from Scene Graph Node to 'update'.
index cc6d565..b4daf0a 100644 (file)
@@ -213,7 +213,7 @@ void SumoPhysicsEnvironment::addTouchCallback(int response_class, PHY_ResponseCa
 
        m_sumoScene->addTouchCallback(sumoRespClass,SumoPHYCallbackBridge::StaticSolidToPHYCallback,bridge);
 }
-void SumoPhysicsEnvironment::requestCollisionCallback(PHY_IPhysicsController* ctrl)
+bool SumoPhysicsEnvironment::requestCollisionCallback(PHY_IPhysicsController* ctrl)
 {
        SumoPhysicsController* smctrl = dynamic_cast<SumoPhysicsController*>(ctrl);
        MT_assert(smctrl);
@@ -225,12 +225,15 @@ void SumoPhysicsEnvironment::requestCollisionCallback(PHY_IPhysicsController* ct
                smObject->setPhysicsClientObject(ctrl);
        
                m_sumoScene->requestCollisionCallback(*smObject);
+               return true;
        }
+       return false;
 }
 
-void SumoPhysicsEnvironment::removeCollisionCallback(PHY_IPhysicsController* ctrl)
+bool SumoPhysicsEnvironment::removeCollisionCallback(PHY_IPhysicsController* ctrl)
 {
        // intentionally empty
+       return false;
 }
 
 PHY_IPhysicsController*        SumoPhysicsEnvironment::CreateSphereController(float radius,const PHY__Vector3& position)
index c2b443a..4c9d59e 100644 (file)
@@ -83,8 +83,8 @@ public:
        virtual void addSensor(PHY_IPhysicsController* ctrl);
        virtual void removeSensor(PHY_IPhysicsController* ctrl);
        virtual void addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user);
-       virtual void requestCollisionCallback(PHY_IPhysicsController* ctrl);
-       virtual void removeCollisionCallback(PHY_IPhysicsController* ctrl);
+       virtual bool requestCollisionCallback(PHY_IPhysicsController* ctrl);
+       virtual bool removeCollisionCallback(PHY_IPhysicsController* ctrl);
        virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position);
        virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight);
 
index 64bb810..f7bcbd4 100644 (file)
@@ -45,10 +45,12 @@ class       PHY_IMotionState
                virtual void    getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal)=0;
                // ori = array 12 floats, [0..3] = first column + 0, [4..7] = second colum, [8..11] = third column
                virtual void    getWorldOrientation(float* ori)=0;
+               virtual void    setWorldOrientation(const float* ori)=0;
                
                virtual void    setWorldPosition(float posX,float posY,float posZ)=0;
                virtual void    setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal)=0;
 
+
                virtual void    calculateWorldTransformations()=0;
 };
 
index 770426b..d7b8cb0 100644 (file)
@@ -31,7 +31,7 @@
 
 #include "PHY_IController.h"
 
-
+class PHY_IMotionState;
 
 /**
        PHY_IPhysicsController is the abstract simplified Interface to a physical object.
@@ -53,6 +53,7 @@ class PHY_IPhysicsController : public PHY_IController
                
                virtual void            WriteMotionStateToDynamics(bool nondynaonly)=0;
                virtual void            WriteDynamicsToMotionState()=0;
+               virtual class PHY_IMotionState* GetMotionState() = 0;
                // controller replication
                virtual void            PostProcessReplica(class PHY_IMotionState* motionstate,class PHY_IPhysicsController* parentctrl)=0;
 
index a360566..1939083 100644 (file)
@@ -152,8 +152,8 @@ class PHY_IPhysicsEnvironment
                virtual void addSensor(PHY_IPhysicsController* ctrl)=0;
                virtual void removeSensor(PHY_IPhysicsController* ctrl)=0;
                virtual void addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user)=0;
-               virtual void requestCollisionCallback(PHY_IPhysicsController* ctrl)=0;
-               virtual void removeCollisionCallback(PHY_IPhysicsController* ctrl)=0;
+               virtual bool requestCollisionCallback(PHY_IPhysicsController* ctrl)=0;
+               virtual bool removeCollisionCallback(PHY_IPhysicsController* ctrl)=0;
                //These two methods are *solely* used to create controllers for sensor! Don't use for anything else
                virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) =0;
                virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight)=0;
index b4dd9a9..8f448a0 100644 (file)
@@ -203,6 +203,13 @@ public:
                return m_SGcontrollers; 
        }
 
+       /**
+        * 
+        */
+       SG_Callbacks& GetCallBackFunctions()
+       {
+               return m_callbacks;
+       }
        
        /**
         * Get the client object associated with this
index d1fc95c..6e27448 100644 (file)
@@ -148,6 +148,13 @@ public:
                SetModified();
        }
 
+       // rot is arrange like openGL matrix
+       void SetLocalOrientation(const float* rot)
+       {
+               m_localRotation.setValue(rot);
+               SetModified();
+       }
+
        void SetWorldOrientation(const MT_Matrix3x3& rot) 
        {
                m_worldRotation = rot;