Big patches:
authorKester Maddock <Christopher.Maddock.1@uni.massey.ac.nz>
Fri, 25 Mar 2005 10:33:39 +0000 (10:33 +0000)
committerKester Maddock <Christopher.Maddock.1@uni.massey.ac.nz>
Fri, 25 Mar 2005 10:33:39 +0000 (10:33 +0000)
Erwin Coumans: Abstract the physics engine
Charlie C: Joystick fixes
Me: Moved the ray cast (shadows, mouse sensor & ray sensor)

78 files changed:
source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp
source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h
source/gameengine/Converter/BL_ActionActuator.h
source/gameengine/Converter/KX_BlenderSceneConverter.cpp
source/gameengine/Converter/KX_ConvertSensors.cpp
source/gameengine/Expressions/InputParser.cpp
source/gameengine/Expressions/Makefile
source/gameengine/Expressions/PyObjectPlus.cpp
source/gameengine/Expressions/PyObjectPlus.h
source/gameengine/Expressions/SConscript
source/gameengine/Expressions/Value.cpp
source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp
source/gameengine/GameLogic/Makefile
source/gameengine/GameLogic/SCA_JoystickManager.cpp
source/gameengine/GameLogic/SCA_JoystickManager.h
source/gameengine/GameLogic/SCA_JoystickSensor.cpp
source/gameengine/GamePlayer/common/GPC_RenderTools.cpp
source/gameengine/GamePlayer/common/GPC_RenderTools.h
source/gameengine/GamePlayer/ghost/GPG_Application.cpp
source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
source/gameengine/Ketsji/KX_GameObject.cpp
source/gameengine/Ketsji/KX_GameObject.h
source/gameengine/Ketsji/KX_IPO_SGController.cpp
source/gameengine/Ketsji/KX_IPO_SGController.h
source/gameengine/Ketsji/KX_IPhysicsController.cpp
source/gameengine/Ketsji/KX_IPhysicsController.h
source/gameengine/Ketsji/KX_KetsjiEngine.cpp
source/gameengine/Ketsji/KX_KetsjiEngine.h
source/gameengine/Ketsji/KX_MouseFocusSensor.cpp
source/gameengine/Ketsji/KX_MouseFocusSensor.h
source/gameengine/Ketsji/KX_NearSensor.cpp
source/gameengine/Ketsji/KX_NearSensor.h
source/gameengine/Ketsji/KX_OdePhysicsController.cpp
source/gameengine/Ketsji/KX_OdePhysicsController.h
source/gameengine/Ketsji/KX_PolygonMaterial.cpp
source/gameengine/Ketsji/KX_PyConstraintBinding.cpp
source/gameengine/Ketsji/KX_PyConstraintBinding.h
source/gameengine/Ketsji/KX_PythonInit.cpp
source/gameengine/Ketsji/KX_RadarSensor.cpp
source/gameengine/Ketsji/KX_RadarSensor.h
source/gameengine/Ketsji/KX_RayCast.cpp [new file with mode: 0644]
source/gameengine/Ketsji/KX_RayCast.h [new file with mode: 0644]
source/gameengine/Ketsji/KX_RaySensor.cpp
source/gameengine/Ketsji/KX_RaySensor.h
source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp
source/gameengine/Ketsji/KX_Scene.cpp
source/gameengine/Ketsji/KX_Scene.h
source/gameengine/Ketsji/KX_SoundActuator.cpp
source/gameengine/Ketsji/KX_SumoPhysicsController.cpp
source/gameengine/Ketsji/KX_SumoPhysicsController.h
source/gameengine/Ketsji/KX_TouchEventManager.cpp
source/gameengine/Ketsji/KX_TouchEventManager.h
source/gameengine/Ketsji/KX_TouchSensor.cpp
source/gameengine/Ketsji/KX_TouchSensor.h
source/gameengine/Ketsji/SConscript
source/gameengine/Network/LoopBackNetwork/NG_LoopBackNetworkDeviceInterface.cpp
source/gameengine/Network/Makefile
source/gameengine/Network/NG_NetworkScene.cpp
source/gameengine/Network/SConscript
source/gameengine/Physics/BlOde/OdePhysicsController.cpp
source/gameengine/Physics/BlOde/OdePhysicsController.h
source/gameengine/Physics/BlOde/OdePhysicsEnvironment.cpp
source/gameengine/Physics/BlOde/OdePhysicsEnvironment.h
source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.cpp
source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h
source/gameengine/Physics/Sumo/Fuzzics/include/SM_Object.h
source/gameengine/Physics/Sumo/Fuzzics/src/SM_Object.cpp
source/gameengine/Physics/Sumo/Fuzzics/src/SM_Scene.cpp
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_DynamicTypes.h
source/gameengine/Physics/common/PHY_IPhysicsController.h
source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h
source/gameengine/PyDoc/KX_PolygonMaterial.py

index f0eb36107e8159e0e5b072f831534c540639a38f..ca908f86344b2b8236855c8e6ae667b1d9904297 100644 (file)
@@ -346,7 +346,6 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
                
                // clean up some stuff
                audiodevice->StopCD();
-               SND_DeviceManager::Unsubscribe();
                
                if (ketsjiengine)
                {
@@ -388,6 +387,9 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
                        delete canvas;
                        canvas = NULL;
                }
+               
+               SND_DeviceManager::Unsubscribe();
+       
        } while (exitrequested == KX_EXIT_REQUEST_RESTART_GAME || exitrequested == KX_EXIT_REQUEST_START_OTHER_GAME);
 
        if (bfd) BLO_blendfiledata_free(bfd);
index d8a89461031b38e18666f5ac6fcf8c5b246a3e7b..e35ec6f41ef66f18c965cef2d6b34e4e82c83a2a 100644 (file)
@@ -47,7 +47,6 @@
 #include "RAS_ICanvas.h"
 #include "RAS_GLExtensionManager.h"
 
-
 // next two includes/dependencies come from the shadow feature
 // it needs the gameobject and the sumo physics scene for a raycast
 #include "KX_GameObject.h"
@@ -60,9 +59,9 @@
 #include "STR_String.h"
 #include "RAS_BucketManager.h" // for polymaterial (needed for textprinting)
 
-#include "SM_Scene.h"
-#include "SumoPhysicsEnvironment.h"
-#include "KX_SumoPhysicsController.h"
+#include "KX_RayCast.h"
+#include "KX_IPhysicsController.h"
+#include "PHY_IPhysicsEnvironment.h"
 #include "KX_Scene.h"
 
 KX_BlenderRenderTools::KX_BlenderRenderTools()
@@ -125,7 +124,27 @@ void KX_BlenderRenderTools::BeginFrame(RAS_IRasterizer* rasty)
 
 
 }
+
+bool KX_BlenderRenderTools::RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data)
+{
+       double* const oglmatrix = (double* const) data;
+       MT_Point3 resultpoint(hit_point);
+       MT_Vector3 resultnormal(hit_normal);
+       MT_Vector3 left(oglmatrix[0],oglmatrix[1],oglmatrix[2]);
+       MT_Vector3 dir = -(left.cross(resultnormal)).safe_normalized();
+       left = (dir.cross(resultnormal)).safe_normalized();
+       // for the up vector, we take the 'resultnormal' returned by the physics
        
+       double maat[16]={
+                       left[0],        left[1],        left[2], 0,
+                               dir[0],         dir[1],         dir[2], 0,
+               resultnormal[0],resultnormal[1],resultnormal[2], 0,
+                               0,              0,              0, 1};
+       glTranslated(resultpoint[0],resultpoint[1],resultpoint[2]);
+       //glMultMatrixd(oglmatrix);
+       glMultMatrixd(maat);
+       return true;
+}
 
 void KX_BlenderRenderTools::applyTransform(RAS_IRasterizer* rasty,double* oglmatrix,int objectdrawmode )
 {
@@ -196,44 +215,26 @@ void KX_BlenderRenderTools::applyTransform(RAS_IRasterizer* rasty,double* oglmat
                        KX_GameObject *gameobj = (KX_GameObject*) this->m_clientobject;
                        MT_Vector3 direction = MT_Vector3(0,0,-1);
 
-                       
                        direction.normalize();
                        direction *= 100000;
 
                        MT_Point3 topoint = frompoint + direction;
-                       MT_Point3 resultpoint;
-                       MT_Vector3 resultnormal;
 
-                       //todo:
-                       //use physics abstraction
                        KX_Scene* kxscene = (KX_Scene*) m_auxilaryClientInfo;
-                       SumoPhysicsEnvironment *spe = dynamic_cast<SumoPhysicsEnvironment *>( kxscene->GetPhysicsEnvironment());
-                       SM_Scene *scene = spe->GetSumoScene();
-                       KX_SumoPhysicsController *spc = dynamic_cast<KX_SumoPhysicsController *>( gameobj->GetPhysicsController());
+                       PHY_IPhysicsEnvironment* physics_environment = kxscene->GetPhysicsEnvironment();
+                       KX_IPhysicsController* physics_controller = gameobj->GetPhysicsController();
+                       
                        KX_GameObject *parent = gameobj->GetParent();
-                       if (!spc && parent)
-                               spc = dynamic_cast<KX_SumoPhysicsController *>(parent->GetPhysicsController());
+                       if (!physics_controller && parent)
+                               physics_controller = parent->GetPhysicsController();
                        if (parent)
                                parent->Release();
-                       SM_Object *thisObj = spc?spc->GetSumoObject():NULL;
-                       
-                       if (scene->rayTest(thisObj, frompoint, topoint, resultpoint, resultnormal))
-                       {
-                               MT_Vector3 left(oglmatrix[0],oglmatrix[1],oglmatrix[2]);
-                               MT_Vector3 dir = -(left.cross(resultnormal)).safe_normalized();
-                               left = (dir.cross(resultnormal)).safe_normalized();
-                               // for the up vector, we take the 'resultnormal' returned by the physics
                                
-                               double maat[16]={
-                                               left[0],        left[1],        left[2], 0,
-                                                dir[0],         dir[1],         dir[2], 0,
-                                       resultnormal[0],resultnormal[1],resultnormal[2], 0,
-                                                     0,              0,              0, 1};
-                               glTranslated(resultpoint[0],resultpoint[1],resultpoint[2]);
-                               //glMultMatrixd(oglmatrix);
-                               glMultMatrixd(maat);
-                       } else
+                       MT_Point3 resultpoint;
+                       MT_Vector3 resultnormal;
+                       if (!KX_RayCast::RayTest(physics_controller, physics_environment, frompoint, topoint, resultpoint, resultnormal, KX_RayCast::Callback<KX_BlenderRenderTools>(this, oglmatrix)))
                        {
+                               // couldn't find something to cast the shadow on...
                                glMultMatrixd(oglmatrix);
                        }
                } else
index 48b1ca423573c5dac7a9373bc42bfefe837f6c1e..dc638d1a43a44fb15c536597f7cf42f8dfb830cd 100644 (file)
@@ -39,6 +39,8 @@
 
 #include "RAS_IRenderTools.h"
 
+struct KX_ClientObjectInfo;
+
 /**
 BlenderRenderTools are a set of tools to apply 2D/3D graphics effects, which are not
 part of the (polygon) Rasterizer. 
@@ -96,6 +98,8 @@ public:
                                                                        bool bIsTriangle,
                                                                        void* clientobject,
                                                                        void* tface);
+       
+       bool RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data);
 };
 
 #endif //__KX_BLENDERRENDERTOOLS
index 5587cbd9c5efa385c48509be06cb46415f7b56ad..f96855408b772b82a65a4a0783414a604d01fa0d 100644 (file)
@@ -58,9 +58,11 @@ public:
                m_flag(0),
                m_startframe (starttime),
                m_endframe(endtime) ,
+               m_starttime(0),
                m_localtime(starttime),
                m_lastUpdate(-1),
                m_blendin(blendin),
+               m_blendstart(0),
                m_stridelength(stride),
                m_playtype(playtype),
                m_priority(priority),
@@ -73,8 +75,8 @@ public:
        };
        virtual ~BL_ActionActuator();
        virtual bool Update(double curtime, bool frame);
-       CValue* GetReplica();
-       void ProcessReplica();
+       virtual CValue* GetReplica();
+       virtual void ProcessReplica();
        
        void SetBlendTime (float newtime);
 
index 6b3cbbea2e5d1e7b752fa420977ac7b609c4c1ab..53b775b89208503234aae41607a66d85959e05df 100644 (file)
@@ -152,7 +152,6 @@ bool KX_BlenderSceneConverter::TryAndLoadNewFile()
         * Find the specified scene by name, or the first
         * scene if nothing matches (shouldn't happen).
         */
-#if 0
 static struct Scene *GetSceneForName2(struct Main *maggie, const STR_String& scenename) {
        Scene *sce;
 
@@ -162,7 +161,7 @@ static struct Scene *GetSceneForName2(struct Main *maggie, const STR_String& sce
 
        return (Scene*) maggie->scene.first;
 }
-#endif
+
 
 void KX_BlenderSceneConverter::ConvertScene(const STR_String& scenename,
                                                                                        class KX_Scene* destinationscene,
@@ -172,12 +171,10 @@ void KX_BlenderSceneConverter::ConvertScene(const STR_String& scenename,
                                                                                        class RAS_ICanvas* canvas)
 {
        //find out which physics engine
-       // Scene *blenderscene = GetSceneForName2(m_maggie, scenename); /*unused*/
+       Scene *blenderscene = GetSceneForName2(m_maggie, scenename);
 
        e_PhysicsEngine physics_engine = UseSumo;
 
-       /* FIXME: Force physics engine = sumo.
-       This isn't really a problem - no other physics engines are available. 
        if (blenderscene)
        {
                int i=0;
@@ -210,7 +207,7 @@ void KX_BlenderSceneConverter::ConvertScene(const STR_String& scenename,
                  
                }
        }
-       */
+
        switch (physics_engine)
        {
        
@@ -220,6 +217,7 @@ void KX_BlenderSceneConverter::ConvertScene(const STR_String& scenename,
                        break;
 #endif
 #ifdef USE_ODE
+
                case UseODE:
                        destinationscene ->SetPhysicsEnvironment(new ODEPhysicsEnvironment());
                        break;
index 396d633043c97d257d41abae52a0735403cfe695..450f4c0b523fb250551b80bf9dfba5d1208c2bf1 100644 (file)
@@ -79,6 +79,7 @@ probably misplaced */
 #include "KX_BlenderKeyboardDevice.h"
 #include "KX_BlenderGL.h"
 #include "RAS_ICanvas.h"
+#include "PHY_IPhysicsEnvironment.h"
 
 #include "KX_KetsjiEngine.h"
 #include "KX_BlenderSceneConverter.h"
@@ -374,11 +375,23 @@ void BL_ConvertSensors(struct Object* blenderobject,
                                        
                                        // this sumoObject is not deleted by a gameobj, so delete it ourself
                                        // later (memleaks)!
-                                       //SM_Object* sumoObj            =       new SM_Object(shape,NULL,NULL,NULL);
-                                       //sumoObj->setMargin(blendernearsensor->dist);
-                                       //sumoObj->setPosition(gameobj->NodeGetWorldPosition());
+                                       float radius = blendernearsensor->dist;
+                                       PHY__Vector3 pos;
+                                       const MT_Vector3& wpos = gameobj->NodeGetWorldPosition();
+                                       pos[0] = wpos[0];
+                                       pos[1] = wpos[1];
+                                       pos[2] = wpos[2];
+                                       pos[3] = 0.f;
                                        bool bFindMaterial = false;
-                                       gamesensor = new KX_NearSensor(eventmgr,gameobj,blendernearsensor->dist,blendernearsensor->resetdist,bFindMaterial,nearpropertyname,kxscene);
+                                       PHY_IPhysicsController* physCtrl = kxscene->GetPhysicsEnvironment()->CreateSphereController(radius,pos);
+
+                                       gamesensor = new KX_NearSensor(eventmgr,gameobj,
+                                               blendernearsensor->dist,
+                                               blendernearsensor->resetdist,
+                                               bFindMaterial,
+                                               nearpropertyname,kxscene,
+                                               physCtrl
+                                               );
                                        
                                }
                                break;
@@ -551,9 +564,12 @@ void BL_ConvertSensors(struct Object* blenderobject,
                                        MT_Scalar largemargin = 0.0;
                                        
                                        bool bFindMaterial = false;
+                                       PHY_IPhysicsController* ctrl = kxscene->GetPhysicsEnvironment()->CreateConeController(coneradius,coneheight);
+
                                        gamesensor = new KX_RadarSensor(
                                                eventmgr,
                                                gameobj,
+                                               ctrl,
                                                coneradius,
                                                coneheight,
                                                radaraxis,
index 090c95e3c07f7514a6c9883da349dec39bfc89cb..24033dd21a2d0bff4c45f6de9cbaf17fe61956b7 100644 (file)
@@ -14,6 +14,8 @@
 
 #include <stdlib.h>
 
+#include "MT_assert.h"
+
 #include "Value.h"
 #include "InputParser.h"
 #include "ErrorValue.h"
@@ -371,7 +373,7 @@ int CParser::Priority(int optorkind) {
     case OPtimes:
     case OPdivide: return 5;
        }
-       assert(false);
+       MT_assert(false);
        return 0;      // should not happen
 }
 
@@ -400,7 +402,7 @@ CExpression *CParser::Ex(int i) {
                        case OPless: e1 = new COperator2Expr(VALUE_LES_OPERATOR,e1, e2); break;
                        case OPgreaterequal: e1 = new COperator2Expr(VALUE_GEQ_OPERATOR,e1, e2); break;
                        case OPlessequal: e1 = new COperator2Expr(VALUE_LEQ_OPERATOR,e1, e2); break;
-                       default: assert(false); break; // should not happen
+                       default: MT_assert(false);      break; // should not happen
                        }
                }
        } else if (i == NUM_PRIORITY) {
@@ -445,7 +447,7 @@ CExpression *CParser::Ex(int i) {
                                        e1 = new CConstExpr(new CStringValue(const_as_string,""));
                                        break;
                                default :
-                                       assert(false);
+                                       MT_assert(false);
                                        break;
                                }
                                NextSym();
@@ -483,7 +485,7 @@ CExpression *CParser::Ex(int i) {
                                }
                        case errorsym:
                                {
-                                       assert(!e1);
+                                       MT_assert(!e1);
                                        STR_String errtext="[no info]";
                                        if (errmsg)
                                        {
@@ -498,7 +500,7 @@ CExpression *CParser::Ex(int i) {
                                                        errmsg=NULL;
                                                } else {
                                                        // does this happen ?
-                                                       assert ("does this happen");
+                                                       MT_assert ("does this happen");
                                                }
                                        }
                                        e1 = Error(errtext);
@@ -508,7 +510,7 @@ CExpression *CParser::Ex(int i) {
                        default:
                                NextSym();
                                //return Error("Expression expected");
-                               assert(!e1);
+                               MT_assert(!e1);
                                e1 = Error("Expression expected");
                        }
                }
index 88746c18eae328297bbf099c61af126876523d5c..18dca9a1c68eb8996d28a895e8bc8332f1a0c5db 100644 (file)
@@ -40,6 +40,7 @@ CCFLAGS += $(LEVEL_1_CPP_WARNINGS)
 
 CPPFLAGS += -I$(NAN_PYTHON)/include/python$(NAN_PYTHON_VERSION)
 
-CPPFLAGS += -I$(NAN_STRING)/include    
+CPPFLAGS += -I$(NAN_STRING)/include
+CPPFLAGS += -I$(NAN_MOTO)/include
 CPPFLAGS += -I../../kernel/gen_system
 
index 2b331d7f728e6d3fda3771d9f213306f62e4f95f..b75da2c12a2e5fe5c14a5837aa62d8dd62cace7f 100644 (file)
@@ -49,7 +49,7 @@
  * http://www.python.org/doc/PyCPP.html
  *
 ------------------------------*/
-#include <assert.h>
+#include <MT_assert.h>
 #include "stdlib.h"
 #include "PyObjectPlus.h"
 #include "STR_String.h"
@@ -79,7 +79,7 @@ PyTypeObject PyObjectPlus::Type = {
 
 PyObjectPlus::PyObjectPlus(PyTypeObject *T)                            // constructor
 {
-       assert(T != NULL);
+       MT_assert(T != NULL);
        this->ob_type = T; 
        _Py_NewReference(this);
 };
index 7e6b3f29bab48837804d5271bec669b1bd975cc9..8784d28d502d409ae7b6fda09530787f136fb76e 100644 (file)
@@ -48,7 +48,7 @@
 
                                                                // some basic python macros
 #define Py_NEWARGS 1                   
-#define Py_Return Py_INCREF(Py_None); return Py_None;  
+#define Py_Return { Py_INCREF(Py_None); return Py_None;}
 
 #define Py_Error(E, M)   {PyErr_SetString(E, M); return NULL;}
 #define Py_Try(F) {if (!(F)) return NULL;}
index 93a197e085b1408602119ac6b1d93a77ce35c071..212381cc0341a3143ca8f4fc3516e810e8e7e6ca 100755 (executable)
@@ -26,7 +26,8 @@ source_files = ['BoolValue.cpp',
 
 expressions_env.Append (CPPPATH = ['.',
                                    '#source/kernel/gen_system',
-                                   '#intern/string'])
+                                   '#intern/string',
+                                  '#intern/moto/include'])
 
 expressions_env.Append (CPPPATH = user_options_dict['PYTHON_INCLUDE'])
 
index fbb1e9a8c9956a41041a8232121690a6117d4866..1a09123c107a3742dead9ba3e020e1d5ae825b5e 100644 (file)
@@ -532,7 +532,7 @@ int CValue::Release()
        else
        {
                // Reference count reached 0, delete ourselves and return 0
-//             assert(m_refcount==0, "Reference count reached sub-zero, object released too much");
+//             MT_assert(m_refcount==0, "Reference count reached sub-zero, object released too much");
                delete this;
                return 0;
        }
index 7d1d4b2873013f51e101b3da91e549b2055e6948..02775c58168804ec8114105c7dae47610acb1a7c 100644 (file)
@@ -28,7 +28,7 @@
  * ***** END GPL/BL DUAL LICENSE BLOCK *****
  */
 #include <SDL.h>
+
 #include "SCA_Joystick.h"
 #include "SCA_JoystickPrivate.h"
 
@@ -47,11 +47,14 @@ SCA_Joystick::SCA_Joystick()
        m_private = new PrivateData();
 }
 
+
 SCA_Joystick::~SCA_Joystick()
+
 {
        delete m_private;
 }
 
+
 bool SCA_Joystick::CreateJoystickDevice()
 {
        bool init = false;
@@ -66,6 +69,7 @@ void SCA_Joystick::DestroyJoystickDevice()
                pDestroyJoystickDevice();
 }
 
+
 void SCA_Joystick::HandleEvents()
 {
        if(m_isinit)
@@ -91,6 +95,7 @@ void SCA_Joystick::cSetPrecision(int val)
        m_prec = val;
 }
 
+
 bool SCA_Joystick::aRightAxisIsPositive(int axis)
 {
        bool result;
@@ -164,7 +169,6 @@ int SCA_Joystick::pGetButtonPress(int button)
        if(button == m_buttonnum)
                return m_buttonnum;
        return -2;
-
 }
 
 
@@ -279,6 +283,7 @@ int SCA_Joystick::GetNumberOfButtons()
        return -1;
 }
 
+
 int SCA_Joystick::GetNumberOfHats()
 {
        int number;
@@ -291,7 +296,6 @@ int SCA_Joystick::GetNumberOfHats()
        return -1;
 }
 
-
 bool SCA_Joystick::pCreateJoystickDevice()
 {
        if(m_isinit == false){
@@ -328,6 +332,7 @@ void SCA_Joystick::pDestroyJoystickDevice()
        SDL_QuitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_VIDEO );
 }
 
+
 void SCA_Joystick::pFillAxes()
 {
        if(GetNumberOfAxes() == 1){
@@ -344,6 +349,7 @@ void SCA_Joystick::pFillAxes()
        }
 }
 
+
 int SCA_Joystick::pGetAxis(int axisnum, int udlr)
 {
        if(axisnum == 1 && udlr == 1)return m_axis10; //u/d
index 90bb728936b545466aac4a0208b5d431d5eb08a5..5fd8510d566fb971337fcc131ce3c4134bade71b 100644 (file)
  * ***** END GPL/BL DUAL LICENSE BLOCK *****
  */
 #include <SDL.h>
 #include "SCA_Joystick.h"
 #include "SCA_JoystickPrivate.h"
 
+
+
 void SCA_Joystick::OnAxisMotion(void)
 {
        pFillAxes();
@@ -70,4 +71,3 @@ void SCA_Joystick::OnNothing(void)
 {
        m_istrig = 0;
 }
-
index dcf2163a68b939750a7adebdd3042a989c9f5226..9e6f4515badacd99c483c15e5893ebc4c077f22c 100644 (file)
@@ -35,8 +35,8 @@ LIBNAME = logic
 DIR = $(OCGDIR)/gameengine/$(LIBNAME)
 DIRS = Joystick
 
-include nan_compile.mk
 include nan_subdirs.mk
+include nan_compile.mk
 
 CCFLAGS += $(LEVEL_1_CPP_WARNINGS)
 
index 3637883047dd92d8778e3ff2959538fb23f85b5f..cf182a0503eaa280e23e81bc25488fadad0eff0b 100644 (file)
  *
  * ***** END GPL/BL DUAL LICENSE BLOCK *****
  */
-
 #include "SCA_JoystickSensor.h"
 #include "SCA_JoystickManager.h"
 #include "SCA_LogicManager.h"
-#include <vector>
+//#include <vector>
 #include "SCA_ISensor.h"
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
+//using namespace std;
 
-using namespace std;
 
 SCA_JoystickManager::SCA_JoystickManager(class SCA_LogicManager* logicmgr)
        : SCA_EventManager(JOY_EVENTMGR),
        m_logicmgr(logicmgr)
 {
-       Joystick.CreateJoystickDevice();
+       m_joystick = new SCA_Joystick();
+       m_joystick->CreateJoystickDevice();
 }
+
+
 SCA_JoystickManager::~SCA_JoystickManager()
 {
-       Joystick.DestroyJoystickDevice();
+       m_joystick->DestroyJoystickDevice();
+       delete m_joystick;
 }
 
 
@@ -59,23 +62,23 @@ void SCA_JoystickManager::NextFrame(double curtime,double deltatime)
                SCA_JoystickSensor* joysensor = (SCA_JoystickSensor*) m_sensors[i];
                if(!joysensor->IsSuspended())
                {
-                       Joystick.HandleEvents();
+                       m_joystick->HandleEvents();
                        joysensor->Activate(m_logicmgr, NULL);
                }
        }
 }
 
 
-
 void SCA_JoystickManager::RegisterSensor(SCA_ISensor* sensor)
 {
        m_sensors.push_back(sensor);
 }
 
-SCA_Joystick SCA_JoystickManager::GetJoystickDevice()
+
+SCA_Joystick *SCA_JoystickManager::GetJoystickDevice()
 {
        /* 
         *Return the instance of SCA_Joystick for use 
         */
-       return Joystick;
+       return m_joystick;
 }
index c6ca0a4990cf4ee4e86733be7d5df077d6e55810..5c892d71f6c3dc21165e8d959e9eb77159626bb9 100644 (file)
@@ -43,14 +43,15 @@ class SCA_JoystickManager : public SCA_EventManager
        /**
         * SDL Joystick Class Instance
         */
-       SCA_Joystick Joystick;
+       SCA_Joystick *m_joystick;
 public:
        SCA_JoystickManager(class SCA_LogicManager* logicmgr);
        virtual ~SCA_JoystickManager();
        virtual void NextFrame(double curtime,double deltatime);
        virtual void    RegisterSensor(SCA_ISensor* sensor);
-       SCA_Joystick GetJoystickDevice(void);
+       SCA_Joystick* GetJoystickDevice(void);
 
 };
 
 #endif
+
index d1a35469c3a22394237613fa754c5f4862d4a0fe..40942dd296ff51da4ec5eb2834762a6a68912856 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -39,6 +39,7 @@
 #include <config.h>
 #endif
 
+
 SCA_JoystickSensor::SCA_JoystickSensor(class SCA_JoystickManager* eventmgr,
                                                                           SCA_IObject* gameobj,
                                                                           short int joymode,
@@ -70,13 +71,11 @@ std::cout << " hat flag "   << m_hatf               << std::endl;
 }
 
 
-
 SCA_JoystickSensor::~SCA_JoystickSensor()
 {
 }
 
 
-
 CValue* SCA_JoystickSensor::GetReplica()
 {
        CValue* replica = new SCA_JoystickSensor(*this);
@@ -86,7 +85,6 @@ CValue* SCA_JoystickSensor::GetReplica()
 }
 
 
-
 bool SCA_JoystickSensor::IsPositiveTrigger()
 { 
        bool result =   m_istrig;
@@ -94,10 +92,11 @@ bool SCA_JoystickSensor::IsPositiveTrigger()
                result = !result;
        return result;
 }
+
+
 bool SCA_JoystickSensor::Evaluate(CValue* event)
 {
-       SCA_Joystick js = m_pJoystickMgr->GetJoystickDevice();
-
+       SCA_Joystick *js = m_pJoystickMgr->GetJoystickDevice();
        bool result = false;
        
        switch(m_joymode)
@@ -111,9 +110,9 @@ bool SCA_JoystickSensor::Evaluate(CValue* event)
                        m_axisf == 3 == down
                        numberof== m_axis  -- max 2
                        */
-                       js.cSetPrecision(m_precision);
+                       js->cSetPrecision(m_precision);
                        if(m_axisf == 1){
-                               if(js.aUpAxisIsPositive(m_axis)){
+                               if(js->aUpAxisIsPositive(m_axis)){
                                        m_istrig =1;
                                        result = true;
                                }else{
@@ -124,7 +123,7 @@ bool SCA_JoystickSensor::Evaluate(CValue* event)
                                }
                        }
                        if(m_axisf == 3){
-                               if(js.aDownAxisIsPositive(m_axis)){
+                               if(js->aDownAxisIsPositive(m_axis)){
                                        m_istrig = 1;
                                        result = true;
                                }else{
@@ -135,7 +134,7 @@ bool SCA_JoystickSensor::Evaluate(CValue* event)
                                }
                        }
                        if(m_axisf == 2){
-                               if(js.aLeftAxisIsPositive(m_axis)){
+                               if(js->aLeftAxisIsPositive(m_axis)){
                                        m_istrig = 1;
                                        result = true;
                                }else{
@@ -146,7 +145,7 @@ bool SCA_JoystickSensor::Evaluate(CValue* event)
                                }
                        }
                        if(m_axisf == 0){
-                               if(js.aRightAxisIsPositive(m_axis)){
+                               if(js->aRightAxisIsPositive(m_axis)){
                                        m_istrig = 1;
                                        result = true;
                                }else{
@@ -166,7 +165,7 @@ bool SCA_JoystickSensor::Evaluate(CValue* event)
                        m_button = the actual button in question
                        */
                        if(m_buttonf == 0){
-                               if(js.aButtonPressIsPositive(m_button)){
+                               if(js->aButtonPressIsPositive(m_button)){
                                        m_istrig = 1;
                                        result = true;
                                }else {
@@ -177,7 +176,7 @@ bool SCA_JoystickSensor::Evaluate(CValue* event)
                                }
                        }
                        if(m_buttonf == 1){
-                               if(js.aButtonReleaseIsPositive(m_button)){
+                               if(js->aButtonReleaseIsPositive(m_button)){
                                        m_istrig = 1;
                                        result = true;
                                }else {
@@ -196,7 +195,7 @@ bool SCA_JoystickSensor::Evaluate(CValue* event)
                        direction= m_hatf -- max 12
                        */
                        if(m_hat == 1){
-                               if(js.aHatIsPositive(m_hatf)){
+                               if(js->aHatIsPositive(m_hatf)){
                                        m_istrig = 1;
                                        result = true;
                                }else{
@@ -204,10 +203,10 @@ bool SCA_JoystickSensor::Evaluate(CValue* event)
                                                m_istrig = 0;
                                                result = true;
                                        }
-                               }                       
+                               }
                        }
                        if(m_hat == 2){
-                               if(js.aHatIsPositive(m_hatf)){
+                               if(js->aHatIsPositive(m_hatf)){
                                        m_istrig = 1;
                                        result = true;
                                }else{
@@ -219,7 +218,7 @@ bool SCA_JoystickSensor::Evaluate(CValue* event)
                        }
                        /*
                        if(m_hat == 3){
-                               if(js.aHatIsPositive(m_hatf)){
+                               if(js->aHatIsPositive(m_hatf)){
                                        m_istrig = 1;
                                        result = true;
                                }else{
@@ -237,7 +236,7 @@ bool SCA_JoystickSensor::Evaluate(CValue* event)
                printf("Error invalid switch statement\n");
                break;
        }
-       if(!js.IsTrig()){
+       if(!js->IsTrig()){
                m_istrig = 0;
        }
        return result;
@@ -247,12 +246,11 @@ bool SCA_JoystickSensor::Evaluate(CValue* event)
 bool SCA_JoystickSensor::isValid(SCA_JoystickSensor::KX_JOYSENSORMODE m)
 {
        bool res = false;
-       
        res = ((m > KX_JOYSENSORMODE_NODEF) && (m < KX_JOYSENSORMODE_MAX));
-       
        return res;
 }
 
+
 /* ------------------------------------------------------------------------- */
 /* Python functions                                                                                                             */
 /* ------------------------------------------------------------------------- */
@@ -277,6 +275,7 @@ PyTypeObject SCA_JoystickSensor::Type = {
                0
 };
 
+
 PyParentObject SCA_JoystickSensor::Parents[] = {
                &SCA_JoystickSensor::Type,
                &SCA_ISensor::Type,
@@ -285,6 +284,7 @@ PyParentObject SCA_JoystickSensor::Parents[] = {
                NULL
 };
 
+
 PyMethodDef SCA_JoystickSensor::Methods[] = {
        {"getAxis",      (PyCFunction) SCA_JoystickSensor::sPyGetAxis,          METH_NOARGS,    GetAxis_doc},
        {"setAxis",      (PyCFunction) SCA_JoystickSensor::sPySetAxis,          METH_VARARGS,   SetAxis_doc},
@@ -301,10 +301,12 @@ PyMethodDef SCA_JoystickSensor::Methods[] = {
        {NULL,NULL} //Sentinel
 };
 
+
 PyObject* SCA_JoystickSensor::_getattr(const STR_String& attr) {
        _getattr_up(SCA_ISensor);
 }
 
+
 /* get axis  ---------------------------------------------------------- */
 char SCA_JoystickSensor::GetAxis_doc[] = 
 "getAxis\n"
@@ -314,6 +316,8 @@ PyObject* SCA_JoystickSensor::PyGetAxis( PyObject* self,
                                                                                PyObject* kwds) {
        return Py_BuildValue("[ii]",m_axis, m_axisf);
 }
+
+
 /* set axis  ---------------------------------------------------------- */
 char SCA_JoystickSensor::SetAxis_doc[] = 
 "setAxis\n"
@@ -330,6 +334,8 @@ PyObject* SCA_JoystickSensor::PySetAxis( PyObject* self,
        m_axisf = axisflag;
        Py_Return;
 }
+
+
 /* get axis value ----------------------------------------------------- */
 char SCA_JoystickSensor::GetRealAxis_doc[] = 
 "getAxisValue\n"
@@ -338,13 +344,15 @@ PyObject* SCA_JoystickSensor::PyGetRealAxis( PyObject* self,
                                                                                        PyObject* args, 
                                                                                        PyObject* kwds) {
        int a,b,c,d;
-       SCA_Joystick joy = m_pJoystickMgr->GetJoystickDevice();
-       a = joy.GetAxis10();
-       b = joy.GetAxis11();
-       c = joy.GetAxis20();
-       d = joy.GetAxis21();
+       SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice();
+       a = joy->GetAxis10();
+       b = joy->GetAxis11();
+       c = joy->GetAxis20();
+       d = joy->GetAxis21();
        return Py_BuildValue("[iiii]",a,b,c,d);
 }
+
+
 /* get threshold  ----------------------------------------------------- */
 char SCA_JoystickSensor::GetThreshold_doc[] = 
 "getThreshold\n"
@@ -354,6 +362,8 @@ PyObject* SCA_JoystickSensor::PyGetThreshold( PyObject* self,
                                                                                         PyObject* kwds) {
        return Py_BuildValue("i", m_precision);
 }
+
+
 /* set threshold  ----------------------------------------------------- */
 char SCA_JoystickSensor::SetThreshold_doc[] = 
 "setThreshold\n"
@@ -368,6 +378,8 @@ PyObject* SCA_JoystickSensor::PySetThreshold( PyObject* self,
        m_precision = thresh;
        Py_Return;
 }
+
+
 /* get button  -------------------------------------------------------- */
 char SCA_JoystickSensor::GetButton_doc[] = 
 "getButton\n"
@@ -377,6 +389,8 @@ PyObject* SCA_JoystickSensor::PyGetButton( PyObject* self,
                                                                                  PyObject* kwds) {
        return Py_BuildValue("[ii]",m_button, m_buttonf);
 }
+
+
 /* set button  -------------------------------------------------------- */
 char SCA_JoystickSensor::SetButton_doc[] = 
 "setButton\n"
@@ -392,6 +406,8 @@ PyObject* SCA_JoystickSensor::PySetButton( PyObject* self,
        m_buttonf = buttonflag;
        Py_Return;      
 }
+
+
 /* get hat     ----------------------------------------------------------- */
 char SCA_JoystickSensor::GetHat_doc[] = 
 "getHat\n"
@@ -401,6 +417,8 @@ PyObject* SCA_JoystickSensor::PyGetHat( PyObject* self,
                                                                           PyObject* kwds) {
        return Py_BuildValue("[ii]",m_hat, m_hatf);
 }
+
+
 /* set hat     ----------------------------------------------------------- */
 char SCA_JoystickSensor::SetHat_doc[] = 
 "setHat\n"
@@ -416,6 +434,8 @@ PyObject* SCA_JoystickSensor::PySetHat( PyObject* self,
        m_hatf = hatflag;
        Py_Return;
 }
+
+
 /* get # of ----------------------------------------------------- */
 char SCA_JoystickSensor::NumberOfAxes_doc[] = 
 "getNumAxes\n"
@@ -424,10 +444,12 @@ PyObject* SCA_JoystickSensor::PyNumberOfAxes( PyObject* self,
                                                                                        PyObject* args, 
                                                                                        PyObject* kwds) {
        int num;
-       SCA_Joystick joy = m_pJoystickMgr->GetJoystickDevice();
-       num = joy.GetNumberOfAxes();
+       SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice();
+       num = joy->GetNumberOfAxes();
        return Py_BuildValue("i",num);
 }
+
+
 char SCA_JoystickSensor::NumberOfButtons_doc[] = 
 "getNumButtons\n"
 "\tReturns the number of buttons .\n";
@@ -435,10 +457,12 @@ PyObject* SCA_JoystickSensor::PyNumberOfButtons( PyObject* self,
                                                                                        PyObject* args, 
                                                                                        PyObject* kwds) {
        int num;
-       SCA_Joystick joy = m_pJoystickMgr->GetJoystickDevice();
-       num = joy.GetNumberOfButtons();
+       SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice();
+       num = joy->GetNumberOfButtons();
        return Py_BuildValue("i",num);
 }
+
+
 char SCA_JoystickSensor::NumberOfHats_doc[] = 
 "getNumHats\n"
 "\tReturns the number of hats .\n";
@@ -446,7 +470,7 @@ PyObject* SCA_JoystickSensor::PyNumberOfHats( PyObject* self,
                                                                                        PyObject* args, 
                                                                                        PyObject* kwds) {
        int num;
-       SCA_Joystick joy = m_pJoystickMgr->GetJoystickDevice();
-       num = joy.GetNumberOfHats();
+       SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice();
+       num = joy->GetNumberOfHats();
        return Py_BuildValue("i",num);
 }
index 96c3c21ee90380bf7a98fb58287aa9a4298e2c6d..8c3a17f58f3dfafa1b90d004c3a74e90bce3fc05 100644 (file)
 #include "IMB_imbuf_types.h"
 // End of Blender includes
 
-#include "SM_Scene.h"
-#include "SumoPhysicsEnvironment.h"
-#include "KX_SumoPhysicsController.h"
 #include "KX_Scene.h"
+#include "KX_RayCast.h"
+#include "KX_IPhysicsController.h"
+#include "PHY_IPhysicsEnvironment.h"
 
 
 GPC_RenderTools::GPC_RenderTools()
@@ -436,6 +436,26 @@ int GPC_RenderTools::applyLights(int objectlayer)
 
 }
 
+bool GPC_RenderTools::RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data)
+{
+       double* const oglmatrix = (double* const) data;
+       MT_Point3 resultpoint(hit_point);
+       MT_Vector3 resultnormal(hit_normal);
+       MT_Vector3 left(oglmatrix[0],oglmatrix[1],oglmatrix[2]);
+       MT_Vector3 dir = -(left.cross(resultnormal)).safe_normalized();
+       left = (dir.cross(resultnormal)).safe_normalized();
+       // for the up vector, we take the 'resultnormal' returned by the physics
+       
+       double maat[16]={
+                       left[0],        left[1],        left[2], 0,
+                               dir[0],         dir[1],         dir[2], 0,
+               resultnormal[0],resultnormal[1],resultnormal[2], 0,
+                               0,              0,              0, 1};
+       glTranslated(resultpoint[0],resultpoint[1],resultpoint[2]);
+       //glMultMatrixd(oglmatrix);
+       glMultMatrixd(maat);
+       return true;
+}
 
 void GPC_RenderTools::applyTransform(RAS_IRasterizer* rasty,double* oglmatrix,int objectdrawmode )
 {
@@ -494,44 +514,26 @@ void GPC_RenderTools::applyTransform(RAS_IRasterizer* rasty,double* oglmatrix,in
                        KX_GameObject *gameobj = (KX_GameObject*) this->m_clientobject;
                        MT_Vector3 direction = MT_Vector3(0,0,-1);
 
-                       
                        direction.normalize();
                        direction *= 100000;
 
                        MT_Point3 topoint = frompoint + direction;
-                       MT_Point3 resultpoint;
-                       MT_Vector3 resultnormal;
 
-                       //todo:
-                       //use physics abstraction
                        KX_Scene* kxscene = (KX_Scene*) m_auxilaryClientInfo;
-                       SumoPhysicsEnvironment *spe = dynamic_cast<SumoPhysicsEnvironment *>( kxscene->GetPhysicsEnvironment());
-                       SM_Scene *scene = spe->GetSumoScene();
-                       KX_SumoPhysicsController *spc = dynamic_cast<KX_SumoPhysicsController *>( gameobj->GetPhysicsController());
+                       PHY_IPhysicsEnvironment* physics_environment = kxscene->GetPhysicsEnvironment();
+                       KX_IPhysicsController* physics_controller = gameobj->GetPhysicsController();
+                       
                        KX_GameObject *parent = gameobj->GetParent();
-                       if (!spc && parent)
-                               spc = dynamic_cast<KX_SumoPhysicsController *>(parent->GetPhysicsController());
+                       if (!physics_controller && parent)
+                               physics_controller = parent->GetPhysicsController();
                        if (parent)
                                parent->Release();
-                       SM_Object *thisObj = spc?spc->GetSumoObject():NULL;
-                       
-                       if (scene->rayTest(thisObj, frompoint, topoint, resultpoint, resultnormal))
-                       {
-                               MT_Vector3 left(oglmatrix[0],oglmatrix[1],oglmatrix[2]);
-                               MT_Vector3 dir = -(left.cross(resultnormal)).normalized();
-                               left = (dir.cross(resultnormal)).normalized();
-                               // for the up vector, we take the 'resultnormal' returned by the physics
                                
-                               double maat[16]={
-                                               left[0],        left[1],        left[2], 0,
-                                                dir[0],         dir[1],         dir[2], 0,
-                                       resultnormal[0],resultnormal[1],resultnormal[2], 0,
-                                                     0,              0,              0, 1};
-                               glTranslated(resultpoint[0],resultpoint[1],resultpoint[2]);
-                               //glMultMatrixd(oglmatrix);
-                               glMultMatrixd(maat);
-                       } else
+                       MT_Point3 resultpoint;
+                       MT_Vector3 resultnormal;
+                       if (!KX_RayCast::RayTest(physics_controller, physics_environment, frompoint, topoint, resultpoint, resultnormal, KX_RayCast::Callback<GPC_RenderTools>(this, oglmatrix)))
                        {
+                               // couldn't find something to cast the shadow on...
                                glMultMatrixd(oglmatrix);
                        }
                } else
index 62b69c07c5c0cab06f2d7bf2cdd78ce569a9798f..3ff9479f9dad00d7ff3b5ecadf9ad438f188bbc0 100644 (file)
@@ -50,6 +50,8 @@
 
 #include "BMF_Api.h"
 
+struct KX_ClientObjectInfo;
+
 
 class GPC_RenderTools : public RAS_IRenderTools
 {
@@ -146,6 +148,7 @@ public:
 
        int applyLights(int objectlayer);
 
+       bool RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data);
 protected:
        /** 
         * Copied from KX_BlenderGL.cpp in KX_blenderhook
index a956ede0d57c2b51b3b4e898f622f0fbe8b932d8..52bee8e81dd7ae50e5ca11a1c0e9123bb6f8981e 100644 (file)
@@ -51,7 +51,7 @@
 #include "GPG_Application.h"
 
 #include <iostream>
-#include <assert.h>
+#include <MT_assert.h>
 
 /**********************************
  * Begin Blender include block
@@ -725,7 +725,7 @@ void GPG_Application::exitEngine()
 bool GPG_Application::handleWheel(GHOST_IEvent* event)
 {
        bool handled = false;
-       assert(event);
+       MT_assert(event);
        if (m_mouse) 
        {
                GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData();
@@ -744,7 +744,7 @@ bool GPG_Application::handleWheel(GHOST_IEvent* event)
 bool GPG_Application::handleButton(GHOST_IEvent* event, bool isDown)
 {
        bool handled = false;
-       assert(event);
+       MT_assert(event);
        if (m_mouse) 
        {
                GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData();
@@ -773,7 +773,7 @@ bool GPG_Application::handleButton(GHOST_IEvent* event, bool isDown)
 bool GPG_Application::handleCursorMove(GHOST_IEvent* event)
 {
        bool handled = false;
-       assert(event);
+       MT_assert(event);
        if (m_mouse && m_mainWindow)
        {
                GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData();
@@ -790,7 +790,7 @@ bool GPG_Application::handleCursorMove(GHOST_IEvent* event)
 bool GPG_Application::handleKey(GHOST_IEvent* event, bool isDown)
 {
        bool handled = false;
-       assert(event);
+       MT_assert(event);
        if (m_keyboard)
        {
                GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData();
index 9c60bc0f32ff7785b8d5b9d6ec209bf10b88fc8c..c877b699860efdbbbd6e29ef55aa7e7433a0378d 100644 (file)
@@ -33,6 +33,8 @@
 #pragma warning (disable : 4786)
 #endif
 
+#include "MT_assert.h"
+
 // defines USE_ODE to choose physics engine
 #include "KX_ConvertPhysicsObject.h"
 #include "KX_GameObject.h"
@@ -258,7 +260,7 @@ void        KX_ConvertSumoObject(   KX_GameObject* gameobj,
                                                        dynamicParent = sumoctrl->GetSumoObject();
                                                }
 
-                                               assert(dynamicParent);
+                                               MT_assert(dynamicParent);
                                        }
                                
                                        
@@ -303,11 +305,12 @@ static void       BL_RegisterSumoObject(
                // need easy access, not via 'node' etc.
                KX_SumoPhysicsController* physicscontroller = new KX_SumoPhysicsController(sumoScene,sumoObj,motionstate,isDynamic);
                gameobj->SetPhysicsController(physicscontroller);
-               physicscontroller->setClientInfo(gameobj);
+
                
                if (!gameobj->getClientInfo())
                        std::cout << "BL_RegisterSumoObject: WARNING: Object " << gameobj->GetName() << " has no client info" << std::endl;
-               sumoObj->setClientObject(gameobj->getClientInfo());
+               physicscontroller->setNewClientInfo(gameobj->getClientInfo());
+               
 
                gameobj->GetSGNode()->AddSGController(physicscontroller);
 
@@ -586,6 +589,7 @@ void        KX_ConvertODEEngineObject(KX_GameObject* gameobj,
                                                        struct  PHY_MaterialProps*      smmaterial,
                                                        struct  KX_ObjectProperties*    objprop)
 {
+       
        // not yet, future extension :)
        bool dyna=objprop->m_dyna;
        bool fullRigidBody= ( objprop->m_dyna && objprop->m_angular_rigidbody) != 0;
@@ -598,48 +602,51 @@ void      KX_ConvertODEEngineObject(KX_GameObject* gameobj,
        dxSpace* space = odeEnv->GetOdeSpace();
        dxWorld* world = odeEnv->GetOdeWorld();
 
-       if (!objprop->m_implicitsphere &&
-               MT_fuzzyZero(objprop->m_boundingbox.m_extends[0]) ||
-               MT_fuzzyZero(objprop->m_boundingbox.m_extends[1]) ||
-               MT_fuzzyZero(objprop->m_boundingbox.m_extends[2])
-               )
-       {
+       bool isSphere = false;
 
-       } else
+       switch (objprop->m_boundclass)
        {
+       case KX_BOUNDBOX:
+               {
 
-               KX_OdePhysicsController* physicscontroller = 
-                       new KX_OdePhysicsController(
-                       dyna,
-                       fullRigidBody,
-                       phantom,
-                       motionstate,
-                       space,
-                       world,
-                       shapeprops->m_mass,
-                       smmaterial->m_friction,
-                       smmaterial->m_restitution,
-                       objprop->m_implicitsphere,
-                       objprop->m_boundingbox.m_center,
-                       objprop->m_boundingbox.m_extends,
-                       objprop->m_radius
-                       );
-
-               gameobj->SetPhysicsController(physicscontroller);
-               physicscontroller->setClientInfo(gameobj);                                              
-               gameobj->GetSGNode()->AddSGController(physicscontroller);
-
-               bool isActor = objprop->m_isactor;
-               STR_String materialname;
-               if (meshobj)
-                       materialname = meshobj->GetMaterialName(0);
-
-               const char* matname = materialname.ReadPtr();
+                               KX_OdePhysicsController* physicscontroller = 
+                                       new KX_OdePhysicsController(
+                                       dyna,
+                                       fullRigidBody,
+                                       phantom,
+                                       motionstate,
+                                       space,
+                                       world,
+                                       shapeprops->m_mass,
+                                       smmaterial->m_friction,
+                                       smmaterial->m_restitution,
+                                       isSphere,
+                                       objprop->m_boundobject.box.m_center,
+                                       objprop->m_boundobject.box.m_extends,
+                                       objprop->m_boundobject.c.m_radius
+                                       );
+
+                               gameobj->SetPhysicsController(physicscontroller);
+                               physicscontroller->setNewClientInfo(gameobj->getClientInfo());                                          
+                               gameobj->GetSGNode()->AddSGController(physicscontroller);
+
+                               bool isActor = objprop->m_isactor;
+                               STR_String materialname;
+                               if (meshobj)
+                                       materialname = meshobj->GetMaterialName(0);
+
+                               const char* matname = materialname.ReadPtr();
+
+
+                               physicscontroller->SetObject(gameobj->GetSGNode());
 
+                               break;
+                       }
+       default:
+               {
+               }
+       };
 
-               physicscontroller->SetObject(gameobj->GetSGNode());
-                               
-       }
 }
 
 
index d255fd1d18fb80421caa91f6694b70fb3b24cfa8..c89bf33b21c3ab2cb0ff777b10ca5cadb97cbe59 100644 (file)
@@ -360,31 +360,6 @@ void KX_GameObject::UpdateIPO(float curframetime,
        UpdateTransform();
 }
 
-
-/*
-void KX_GameObject::RegisterSumoObject(class SM_Scene* sumoScene,
-                                                                          DT_SceneHandle solidscene,
-                                                                          class SM_Object* sumoObj,
-                                                                          const char* matname,
-                                                                          bool isDynamic,
-                                                                          bool isActor)
-{
-       m_bDyna = isDynamic;
-
-       // need easy access, not via 'node' etc.
-       m_pPhysicsController = new KX_PhysicsController(sumoScene,solidscene,sumoObj,isDynamic);
-                               
-       GetSGNode()->AddSGController(m_pPhysicsController);
-       
-       m_pClient_info->m_type = (isActor ? 1 : 0);
-       m_pClient_info->m_clientobject = this;
-
-       // store materialname in auxinfo, needed for touchsensors
-       m_pClient_info->m_auxilary_info = (matname? (void*)(matname+2) : NULL);
-       m_pPhysicsController->SetObject(this->GetSGNode());
-}
-*/
-
 bool
 KX_GameObject::GetVisible(
        void
@@ -468,10 +443,11 @@ void KX_GameObject::ResolveCombinedVelocities(
 ){
        if (m_pPhysicsController1)
        {
+
+               MT_Vector3 lv = lin_vel_local ? NodeGetWorldOrientation() * lin_vel : lin_vel;
+               MT_Vector3 av = ang_vel_local ? NodeGetWorldOrientation() * ang_vel : ang_vel;
                m_pPhysicsController1->resolveCombinedVelocities(
-                       lin_vel_local ? NodeGetWorldOrientation() * lin_vel : lin_vel,
-                       ang_vel_local ? NodeGetWorldOrientation() * ang_vel : ang_vel                   
-               );              
+                       lv.x(),lv.y(),lv.z(),av.x(),av.y(),av.z());
        }
 }
 
index 27451f637db48450f4787f771ee0829b7f141ef1..c84d905da8bd9cd5dc850aa9e0278d12085ea622 100644 (file)
@@ -57,7 +57,7 @@
 struct KX_ClientObjectInfo;
 class RAS_MeshObject;
 class KX_IPhysicsController;
-class SM_Object;
+
 
 /**
  * KX_GameObject is the main class for dynamic objects.
index 2152fa35cd1170716fa606fa9a435589dbb35b59..e54fb11dc1436bb4e6a3a326b09b17a44df92893 100644 (file)
@@ -57,7 +57,6 @@ KX_IpoSGController::KX_IpoSGController()
   m_modified(true),
   m_ipotime(1.0)
 {
-       m_sumo_object = NULL;
        m_game_object = NULL;
 
 }
@@ -86,7 +85,7 @@ KX_IpoSGController::UpdateSumoReference(
        )
 {
        if (m_game_object) {
-               m_sumo_object = 0;//m_game_object->GetSumoObject();
+
        }
 }
 
@@ -113,15 +112,7 @@ bool KX_IpoSGController::Update(double currentTime)
                
                if (m_modify_position) {
                        if (m_ipo_as_force) {
-                               /*
-                               UpdateSumoReference();
-                               if (m_sumo_object && ob) {
-                                       m_sumo_object->applyCenterForce(m_force_ipo_acts_local ?
-                                               ob->GetWorldOrientation() * m_ipo_xform.GetPosition() :
-                                               m_ipo_xform.GetPosition());
-                                       m_sumo_object->calcXform();
-                               }
-                               */
+                               
                                if (m_game_object && ob) {
                                        m_game_object->GetPhysicsController()->ApplyForce(m_force_ipo_acts_local ?
                                                ob->GetWorldOrientation() * m_ipo_xform.GetPosition() :
@@ -134,15 +125,7 @@ bool KX_IpoSGController::Update(double currentTime)
                }
                if (m_modify_orientation) {
                        if (m_ipo_as_force) {
-                               /*
-                               UpdateSumoReference();
-                               if (m_sumo_object && ob) {
-                                       m_sumo_object->applyTorque(m_force_ipo_acts_local ?
-                                               ob->GetWorldOrientation() * m_ipo_xform.GetEulerAngles() :
-                                               m_ipo_xform.GetEulerAngles());
-                                       m_sumo_object->calcXform();
-                               }
-                               */
+                               
                                if (m_game_object && ob) {
                                        m_game_object->ApplyTorque(m_force_ipo_acts_local ?
                                                ob->GetWorldOrientation() * m_ipo_xform.GetEulerAngles() :
index 107d5026370176cfd0d5ad29edfd70999fc3c417..3b20f47f5fcf1db77ab423edb1cad0f1ce3009a9 100644 (file)
@@ -59,12 +59,6 @@ class KX_IpoSGController : public SG_Controller
        /** Local time of this ipo.*/
        double                  m_ipotime;
 
-       /** A reference to the sm scene an eventually associated physics object is in. */
-//     class SM_Scene*     m_sumo_scene;
-
-       /** A reference an eventually associated physics object is in. */
-       class SM_Object*     m_sumo_object;
-
        /** A reference to the original game object. */
        class KX_GameObject* m_game_object;
 
index 9cc7764227bd5b141c7ee4bbfd61b48889813b9a..c2328e454357400a575e0b5a2e6845434239ee86 100644 (file)
 #include <config.h>
 #endif
 
+#include "PHY_DynamicTypes.h"
+
 KX_IPhysicsController::KX_IPhysicsController(bool dyna,void* userdata)
 
 :      m_bDyna(dyna),
        m_suspendDynamics(false),
        m_userdata(userdata)
 {
-};
+}
 
 KX_IPhysicsController::~KX_IPhysicsController()
 {
 }
+
+
index d2f1f59bac8f1a403ad9edaa6bb0b7cbadadd7ca..ca64888fd55ff6876e464a61e0fd179447acdae8 100644 (file)
@@ -37,6 +37,8 @@
 #include "MT_Point3.h"
 #include "MT_Matrix3x3.h"
 
+struct KX_ClientObjectInfo;
+
 /**
        Physics Controller, a special kind of Scene Graph Transformation Controller.
        It get's callbacks from Physics in case a transformation change took place.
@@ -47,7 +49,6 @@
 class KX_IPhysicsController : public SG_Controller
                                                         
 {
-
 protected:
        bool            m_bDyna;
        bool            m_suspendDynamics;
@@ -68,7 +69,7 @@ public:
        virtual MT_Vector3 GetVelocity(const MT_Point3& pos)=0;
        virtual void    SetAngularVelocity(const MT_Vector3& ang_vel,bool local)=0;
        virtual void    SetLinearVelocity(const MT_Vector3& lin_vel,bool local)=0;
-       virtual void    resolveCombinedVelocities(const MT_Vector3 & lin_vel, const MT_Vector3 & ang_vel) = 0;
+       virtual void    resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ) = 0;
 
        virtual void    getOrientation(MT_Quaternion& orn)=0;
        virtual void setOrientation(const MT_Quaternion& orn)=0;
@@ -95,8 +96,6 @@ public:
        // call from scene graph to update
        virtual bool Update(double time)=0;
        void*   GetUserData() { return m_userdata;}
-       
-
 };
 
 #endif //__KX_IPHYSICSCONTROLLER_H
index af75e3493c18f6fe3911b1d167469ab6784156f3..2e76103ac13990d568792e3534494c28da3453eb 100644 (file)
@@ -177,7 +177,7 @@ KX_KetsjiEngine::~KX_KetsjiEngine()
 
 void KX_KetsjiEngine::SetKeyboardDevice(SCA_IInputDevice* keyboarddevice)
 {
-       assert(keyboarddevice);
+       MT_assert(keyboarddevice);
        m_keyboarddevice = keyboarddevice;
 }
 
@@ -185,7 +185,7 @@ void KX_KetsjiEngine::SetKeyboardDevice(SCA_IInputDevice* keyboarddevice)
 
 void KX_KetsjiEngine::SetMouseDevice(SCA_IInputDevice* mousedevice)
 {
-       assert(mousedevice);
+       MT_assert(mousedevice);
        m_mousedevice = mousedevice;
 }
 
@@ -193,7 +193,7 @@ void KX_KetsjiEngine::SetMouseDevice(SCA_IInputDevice* mousedevice)
 
 void KX_KetsjiEngine::SetNetworkDevice(NG_NetworkDeviceInterface* networkdevice)
 {
-       assert(networkdevice);
+       MT_assert(networkdevice);
        m_networkdevice = networkdevice;
 }
 
@@ -201,7 +201,7 @@ void KX_KetsjiEngine::SetNetworkDevice(NG_NetworkDeviceInterface* networkdevice)
 
 void KX_KetsjiEngine::SetAudioDevice(SND_IAudioDevice* audiodevice)
 {
-       assert(audiodevice);
+       MT_assert(audiodevice);
        m_audiodevice = audiodevice;
 }
 
@@ -209,7 +209,7 @@ void KX_KetsjiEngine::SetAudioDevice(SND_IAudioDevice* audiodevice)
 
 void KX_KetsjiEngine::SetCanvas(RAS_ICanvas* canvas)
 {
-       assert(canvas);
+       MT_assert(canvas);
        m_canvas = canvas;
 }
 
@@ -217,7 +217,7 @@ void KX_KetsjiEngine::SetCanvas(RAS_ICanvas* canvas)
 
 void KX_KetsjiEngine::SetRenderTools(RAS_IRenderTools* rendertools)
 {
-       assert(rendertools);
+       MT_assert(rendertools);
        m_rendertools = rendertools;
 }
 
@@ -225,7 +225,7 @@ void KX_KetsjiEngine::SetRenderTools(RAS_IRenderTools* rendertools)
 
 void KX_KetsjiEngine::SetRasterizer(RAS_IRasterizer* rasterizer)
 {
-       assert(rasterizer);
+       MT_assert(rasterizer);
        m_rasterizer = rasterizer;
 }
 
@@ -233,7 +233,7 @@ void KX_KetsjiEngine::SetRasterizer(RAS_IRasterizer* rasterizer)
 
 void KX_KetsjiEngine::SetPythonDictionary(PyObject* pythondictionary)
 {
-       assert(pythondictionary);
+       MT_assert(pythondictionary);
        m_pythondictionary = pythondictionary;
 }
 
@@ -241,7 +241,7 @@ void KX_KetsjiEngine::SetPythonDictionary(PyObject* pythondictionary)
 
 void KX_KetsjiEngine::SetSceneConverter(KX_ISceneConverter* sceneconverter)
 {
-       assert(sceneconverter);
+       MT_assert(sceneconverter);
        m_sceneconverter = sceneconverter;
 }
 
@@ -258,7 +258,6 @@ void KX_KetsjiEngine::StartEngine()
        m_firstframe = true;
        m_bInitialized = true;
        m_ticrate = DEFAULT_LOGIC_TIC_RATE;
-       SumoPhysicsEnvironment::setTicRate(DEFAULT_PHYSICS_TIC_RATE);
 }
 
 bool KX_KetsjiEngine::BeginFrame()
@@ -320,6 +319,8 @@ void KX_KetsjiEngine::NextFrame()
        else
                curtime = m_kxsystem->GetTimeInSeconds();
        m_deltatime += curtime - m_previoustime;
+       float   realDeltaTime = curtime - m_previoustime;
+
        m_previoustime = curtime;
        double localtime = curtime - m_deltatime;
 
@@ -386,7 +387,7 @@ void KX_KetsjiEngine::NextFrame()
                                // Perform physics calculations on the scene. This can involve 
                                // many iterations of the physics solver.
                                m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true);
-                               scene->GetPhysicsEnvironment()->proceed(localtime);
+                               scene->GetPhysicsEnvironment()->proceedDeltaTime(localtime,realDeltaTime);
                        } // suspended
        
                        DoSound(scene);
@@ -430,7 +431,7 @@ void KX_KetsjiEngine::NextFrame()
                        // Perform physics calculations on the scene. This can involve 
                        // many iterations of the physics solver.
                        m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true);
-                       scene->GetPhysicsEnvironment()->proceed(curtime);
+                       scene->GetPhysicsEnvironment()->proceedDeltaTime(curtime,0.f);
                        // Update scenegraph after physics step. This maps physics calculations
                        // into node positions.         
                        m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
index 9a6f18a5c5f5142fd8d15bd23ea622d275f15b6f..8ea611298e794f8220345afc57ab5e7ba420a8c7 100644 (file)
@@ -296,7 +296,7 @@ public:
         * @param b Blue component of the override color.
         */
        void GetOverrideFrameColor(float& r, float& g, float& b) const;
-
+       
 protected:
        /**
         * Processes all scheduled scene activity.
index 1ffde7e31f8a19bb42ac0433b68129510683f269..7c61edd45e7ad0c3163af593df276afa110f9ea9 100644 (file)
 #include "KX_Camera.h"
 #include "KX_MouseFocusSensor.h"
 
-#include "SM_Object.h"
-#include "SM_Scene.h"
-#include "SumoPhysicsEnvironment.h"
-#include "KX_SumoPhysicsController.h"
+#include "KX_RayCast.h"
+#include "KX_IPhysicsController.h"
+#include "PHY_IPhysicsController.h"
+#include "PHY_IPhysicsEnvironment.h"
+
+
 #include "KX_ClientObjectInfo.h"
 
 /* ------------------------------------------------------------------------- */
@@ -117,10 +119,40 @@ bool KX_MouseFocusSensor::Evaluate(CValue* event)
        return result;
 }
 
+bool KX_MouseFocusSensor::RayHit(KX_ClientObjectInfo* client_info, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data)
+{
+       KX_GameObject* hitKXObj = client_info->m_gameobject;
+       
+       if (client_info->m_type > KX_ClientObjectInfo::ACTOR)
+       {
+               // false hit
+               return false;
+       }
+       
+       /* Is this me? In the ray test, there are a lot of extra checks
+       * for aliasing artefacts from self-hits. That doesn't happen
+       * here, so a simple test suffices. Or does the camera also get
+       * self-hits? (No, and the raysensor shouldn't do it either, since
+       * self-hits are excluded by setting the correct ignore-object.)
+       * Hitspots now become valid. */
+       KX_GameObject* thisObj = (KX_GameObject*) GetParent();
+       if (hitKXObj == thisObj)
+       {
+               m_hitPosition = hit_point;
+               m_hitNormal = hit_normal;
+               return true;
+       }
+       
+       return true;     // object must be visible to trigger
+       //return false;  // occluded objects can trigger
+}
+
+
+
 bool KX_MouseFocusSensor::ParentObjectHasFocus(void)
 {
        
-       // bool res = false; /*unused*/
+       bool res = false;
        m_hitPosition = MT_Vector3(0,0,0);
        m_hitNormal =   MT_Vector3(1,0,0);
        MT_Point3 resultpoint;
@@ -236,88 +268,99 @@ bool KX_MouseFocusSensor::ParentObjectHasFocus(void)
        m_prevTargetPoint = topoint3;
        m_prevSourcePoint = frompoint3;
        
-       /* 2. Get the object from SuMO*/
+       /* 2. Get the object from PhysicsEnvironment */
        /* Shoot! Beware that the first argument here is an
         * ignore-object. We don't ignore anything... */
-       KX_GameObject* thisObj = (KX_GameObject*) GetParent();
        
-       SumoPhysicsEnvironment *spe = dynamic_cast<SumoPhysicsEnvironment* > (m_kxscene->GetPhysicsEnvironment());
-       SM_Scene *sumoScene = spe->GetSumoScene();
-       KX_SumoPhysicsController *spc = dynamic_cast<KX_SumoPhysicsController*> (cam->GetPhysicsController());
-       SM_Object *sumoCam = spc?spc->GetSumoObject():NULL;
-       MT_Vector3 todir = topoint3 - frompoint3;
-       if (todir.dot(todir) < MT_EPSILON)
-               return false;
-       todir.normalize();
-
-       while (true)
-       {       
-               SM_Object* hitSMObj = sumoScene->rayTest(sumoCam, 
-                                                       frompoint3,
-                                                       topoint3,
-                                                       resultpoint, 
-                                                       resultnormal);
-               
-               if (!hitSMObj)
-                       return false;
-                       
-               /* all this casting makes me nervous... */
-               KX_ClientObjectInfo* client_info 
-                       = ( hitSMObj ?
-                               static_cast<KX_ClientObjectInfo*>( hitSMObj->getClientObject() ):
-                               NULL);
-               
-               if (!client_info)
-               {
-                       std::cout<< "WARNING:  MouseOver sensor " << GetName() << " cannot sense SM_Object " << hitSMObj << " - no client info.\n" << std::endl;
-                       return false;
-               } 
+       KX_IPhysicsController* physics_controller = (cam->GetPhysicsController());
+       PHY_IPhysicsEnvironment* physics_environment = m_kxscene->GetPhysicsEnvironment();
+
+//     MT_Vector3 todir = topoint3 - frompoint3;
+//     if (todir.dot(todir) < MT_EPSILON)
+//             return false;
+//     todir.normalize();
        
-               KX_GameObject* hitKXObj = client_info->m_gameobject;
-               
-               if (client_info->m_type > KX_ClientObjectInfo::ACTOR)
-               {
-                       // false hit
-                       KX_SumoPhysicsController *hitspc = dynamic_cast<KX_SumoPhysicsController *> (static_cast<KX_GameObject*> (hitKXObj) ->GetPhysicsController());
-                       if (hitspc)
-                       {
-                               /* We add 0.01 of fudge, so that if the margin && radius == 0., we don't endless loop. */
-                               MT_Scalar marg = 0.01 + hitspc->GetSumoObject()->getMargin();
-                               if (hitspc->GetSumoObject()->getShapeProps())
-                               {
-                                       marg += 2*hitspc->GetSumoObject()->getShapeProps()->m_radius;
-                               }
-                               
-                               /* Calculate the other side of this object */
-                               MT_Point3 hitObjPos;
-                               hitspc->GetWorldPosition(hitObjPos);
-                               MT_Vector3 hitvector = hitObjPos - resultpoint;
-                               if (hitvector.dot(hitvector) > MT_EPSILON)
-                               {
-                                       hitvector.normalize();
-                                       marg *= 2.*todir.dot(hitvector);
-                               }
-                               frompoint3 = resultpoint + marg * todir;
-                       } else {
-                               return false;
-                       }
-                       continue;
-               }
-               /* Is this me? In the ray test, there are a lot of extra checks
-               * for aliasing artefacts from self-hits. That doesn't happen
-               * here, so a simple test suffices. Or does the camera also get
-               * self-hits? (No, and the raysensor shouldn't do it either, since
-               * self-hits are excluded by setting the correct ignore-object.)
-               * Hitspots now become valid. */
-               if (hitKXObj == thisObj)
-               {
-                       m_hitPosition = resultpoint;
-                       m_hitNormal = resultnormal;
-                       return true;
-               }
-               
-               return false;
-       }
+       KX_RayCast::RayTest(physics_controller, physics_environment, frompoint3, topoint3, resultpoint, resultnormal, KX_RayCast::Callback<KX_MouseFocusSensor>(this));
+       
+
+//     while (true)
+//     {       
+//             PHY__Vector3 resultpt;
+//             PHY__Vector3 resultnr;
+// 
+//             PHY_IPhysicsController* hitCtrl= physEnv->rayTest(camCtrl, 
+//                                                     frompoint3.x(),frompoint3.y(),frompoint3.z(),
+//                                                     topoint3.x(),topoint3.y(),topoint3.z(),
+//                                                     resultpt[0], resultpt[1],resultpt[2],
+//                                                     resultnr[0],resultnr[1],resultnr[2]);
+//             
+//             if (!hitCtrl)
+//                     return false;
+//                     
+//             resultpoint = MT_Vector3(resultpt);
+//             resultnormal = MT_Vector3(resultnr);
+// 
+//             /* all this casting makes me nervous... */
+//             KX_ClientObjectInfo* client_info 
+//                     =       static_cast<KX_ClientObjectInfo*>( hitCtrl->getNewClientInfo());
+//             
+//             if (!client_info)
+//             {
+//                     std::cout<< "WARNING:  MouseOver sensor " << GetName() << " cannot sense - no client info.\n" << std::endl;
+// 
+//                     return false;
+//             } 
+//     
+//             KX_GameObject* hitKXObj = client_info->m_gameobject;
+//             
+//             if (client_info->m_type > KX_ClientObjectInfo::ACTOR)
+//             {
+//                     // false hit
+//                     // FIXME: add raytest interface to KX_IPhysicsController, remove casting
+//                     PHY_IPhysicsController* hitspc = (PHY_IPhysicsController*) (static_cast<KX_GameObject*> (hitKXObj)->GetPhysicsController());
+//                     if (hitspc)
+//                     {
+//                             /* We add 0.01 of fudge, so that if the margin && radius == 0., we don't endless loop. */
+//                             MT_Scalar marg = 0.01 + hitspc->GetMargin();
+//                             marg += hitspc->GetRadius(); //this is changed, check !
+// 
+//                             //if (hitspc->GetSumoObject()->getShapeProps())
+//                             //{
+//                             //      marg += 2*hitspc->GetSumoObject()->getShapeProps()->m_radius;
+//                             //}
+//                             
+//                             /* Calculate the other side of this object */
+//                             MT_Point3 hitObjPos;
+//                             PHY__Vector3 hitpos;
+//                             hitspc->getPosition(hitpos);
+//                             hitObjPos = MT_Vector3(hitpos);
+//                             MT_Vector3 hitvector = hitObjPos - resultpoint;
+//                             if (hitvector.dot(hitvector) > MT_EPSILON)
+//                             {
+//                                     hitvector.normalize();
+//                                     marg *= 2.*todir.dot(hitvector);
+//                             }
+//                             frompoint3 = resultpoint + marg * todir;
+//                     } else {
+//                             return false;
+//                     }
+//                     continue;
+//             }
+//             /* Is this me? In the ray test, there are a lot of extra checks
+//             * for aliasing artefacts from self-hits. That doesn't happen
+//             * here, so a simple test suffices. Or does the camera also get
+//             * self-hits? (No, and the raysensor shouldn't do it either, since
+//             * self-hits are excluded by setting the correct ignore-object.)
+//             * Hitspots now become valid. */
+//             if (hitKXObj == thisObj)
+//             {
+//                     m_hitPosition = resultpoint;
+//                     m_hitNormal = resultnormal;
+//                     return true;
+//             }
+//             
+//             return false;
+//     }
 
        return false;
 }
index 61571e190ec2fbc414a2c74129b4677e34bf5e50..d92cebfb4e16b01fb4259ee607292a5af5f90deb 100644 (file)
@@ -78,6 +78,8 @@ class KX_MouseFocusSensor : public SCA_MouseSensor
                return result;
        };
 
+       bool RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data);
+
        
        /* --------------------------------------------------------------------- */
        /* Python interface ---------------------------------------------------- */
index 4766d837069d63e6d5fee2301fac21efff09011c..9f9188ab9a12a4f020e58638081f92b5a0371b03 100644 (file)
 #include "KX_GameObject.h"
 #include "KX_TouchEventManager.h"
 #include "KX_Scene.h" // needed to create a replica
+#include "PHY_IPhysicsEnvironment.h"
+#include "PHY_IPhysicsController.h"
 
-#include "SM_Object.h"
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 KX_NearSensor::KX_NearSensor(SCA_EventManager* eventmgr,
                                                         KX_GameObject* gameobj,
-                                                        void *vshape,
                                                         double margin,
                                                         double resetmargin,
                                                         bool bFindMaterial,
                                                         const STR_String& touchedpropname,
                                                         class KX_Scene* scene,
+                                                        PHY_IPhysicsController*        ctrl,
                                                         PyTypeObject* T)
                         :KX_TouchSensor(eventmgr,
                                                         gameobj,
@@ -66,46 +67,17 @@ KX_NearSensor::KX_NearSensor(SCA_EventManager* eventmgr,
        m_client_info = new KX_ClientObjectInfo(gameobj, KX_ClientObjectInfo::NEAR);
        m_client_info->m_sensors.push_back(this);
        
-       DT_ShapeHandle shape = (DT_ShapeHandle) vshape;
-       m_sumoObj = new SM_Object(shape,NULL,NULL,NULL);
-       m_sumoObj->setMargin(m_Margin);
-       m_sumoObj->setClientObject(m_client_info);
-       
-       SynchronizeTransform();
-}
-
-KX_NearSensor::KX_NearSensor(SCA_EventManager* eventmgr,
-                                                        KX_GameObject* gameobj,
-                                                        double margin,
-                                                        double resetmargin,
-                                                        bool bFindMaterial,
-                                                        const STR_String& touchedpropname,
-                                                        class KX_Scene* scene,
-                                                        PyTypeObject* T)
-                        :KX_TouchSensor(eventmgr,
-                                                        gameobj,
-                                                        bFindMaterial,
-                                                        touchedpropname,
-                                                        /* scene, */
-                                                        T),
-                        m_Margin(margin),
-                        m_ResetMargin(resetmargin)
-
-{
-       gameobj->getClientInfo()->m_sensors.remove(this);
-       m_client_info = new KX_ClientObjectInfo(gameobj, KX_ClientObjectInfo::NEAR);
-       m_client_info->m_sensors.push_back(this);
-       
-       m_sumoObj = new SM_Object(DT_NewSphere(0.0),NULL,NULL,NULL);
-       m_sumoObj->setMargin(m_Margin);
-       m_sumoObj->setClientObject(m_client_info);
+       //DT_ShapeHandle shape = (DT_ShapeHandle) vshape;
+       m_physCtrl = ctrl;
+       m_physCtrl->SetMargin(m_Margin);
+       m_physCtrl->setNewClientInfo(m_client_info);
        
        SynchronizeTransform();
 }
 
 void KX_NearSensor::RegisterSumo(KX_TouchEventManager *touchman)
 {
-       touchman->GetSumoScene()->addSensor(*m_sumoObj);
+       touchman->GetPhysicsEnvironment()->addSensor(m_physCtrl);
 }
 
 CValue* KX_NearSensor::GetReplica()
@@ -121,9 +93,11 @@ CValue* KX_NearSensor::GetReplica()
        
        replica->m_client_info = new KX_ClientObjectInfo(m_client_info->m_gameobject, KX_ClientObjectInfo::NEAR);
        
-       replica->m_sumoObj = new SM_Object(DT_NewSphere(0.0),NULL,NULL,NULL);
-       replica->m_sumoObj->setMargin(m_Margin);
-       replica->m_sumoObj->setClientObject(replica->m_client_info);
+       replica->m_physCtrl = replica->m_physCtrl->GetReplica();
+       //todo: make sure replication works fine
+       //>m_sumoObj = new SM_Object(DT_NewSphere(0.0),NULL,NULL,NULL);
+       //replica->m_sumoObj->setMargin(m_Margin);
+       //replica->m_sumoObj->setClientObject(replica->m_client_info);
        
        replica->SynchronizeTransform();
        
@@ -148,11 +122,11 @@ KX_NearSensor::~KX_NearSensor()
 {
        // for nearsensor, the sensor is the 'owner' of sumoobj
        // for touchsensor, it's the parent
-       if (m_sumoObj)
+       if (m_physCtrl)
        {
-               static_cast<KX_TouchEventManager*>(m_eventmgr)->GetSumoScene()->remove(*m_sumoObj);
-               delete m_sumoObj;
-               m_sumoObj = NULL;
+               static_cast<KX_TouchEventManager*>(m_eventmgr)->GetPhysicsEnvironment()->removeSensor(m_physCtrl);
+               delete m_physCtrl;
+               m_physCtrl = NULL;
        }
                
        if (m_client_info)
@@ -163,22 +137,22 @@ KX_NearSensor::~KX_NearSensor()
 bool KX_NearSensor::Evaluate(CValue* event)
 {
        bool result = false;
-       // KX_GameObject* parent = static_cast<KX_GameObject*>(GetParent()); /*unused*/
+       KX_GameObject* parent = static_cast<KX_GameObject*>(GetParent());
 
        if (m_bTriggered != m_bLastTriggered)
        {
                m_bLastTriggered = m_bTriggered;
                if (m_bTriggered)
                {
-                       if (m_sumoObj)
+                       if (m_physCtrl)
                        {
-                               m_sumoObj->setMargin(m_ResetMargin);
+                               m_physCtrl->SetMargin(m_ResetMargin);
                        }
                } else
                {
-                       if (m_sumoObj)
+                       if (m_physCtrl)
                        {
-                               m_sumoObj->setMargin(m_Margin);
+                               m_physCtrl->SetMargin(m_Margin);
                        }
 
                }
@@ -190,16 +164,16 @@ bool KX_NearSensor::Evaluate(CValue* event)
 
 
 
-DT_Bool KX_NearSensor::HandleCollision(void* obj1,void* obj2,const DT_CollData * coll_data)
+bool   KX_NearSensor::NewHandleCollision(void* obj1,void* obj2,const PHY_CollData * coll_data)
 {
-       // KX_TouchEventManager* toucheventmgr = static_cast<KX_TouchEventManager*>(m_eventmgr); /*unused*/
+       KX_TouchEventManager* toucheventmgr = static_cast<KX_TouchEventManager*>(m_eventmgr);
        KX_GameObject* parent = static_cast<KX_GameObject*>(GetParent());
        
-       // need the mapping from SM_Objects to gameobjects now
+       // need the mapping from PHY_IPhysicsController to gameobjects now
        
-       KX_ClientObjectInfo* client_info =static_cast<KX_ClientObjectInfo*> (obj1 == m_sumoObj
-                                       ((SM_Object*)obj2)->getClientObject() : 
-                                       ((SM_Object*)obj1)->getClientObject());
+       KX_ClientObjectInfo* client_info =static_cast<KX_ClientObjectInfo*> (obj1 == m_physCtrl
+                                       ((PHY_IPhysicsController*)obj2)->getNewClientInfo() : 
+                                       ((PHY_IPhysicsController*)obj1)->getNewClientInfo());
 
        KX_GameObject* gameobj = ( client_info ? 
                        client_info->m_gameobject :
index 080df58639ee2dc8b7143540c86f8e3a5fe7d287..d1b8984b91b61350a45dddc4a0524d838811fd9f 100644 (file)
 #include "KX_ClientObjectInfo.h"
 
 class KX_Scene;
+struct PHY_CollData;
 
 class KX_NearSensor : public KX_TouchSensor
 {
        Py_Header;
+protected:
        double  m_Margin;
        double  m_ResetMargin;
        KX_Scene*       m_scene;
        KX_ClientObjectInfo*    m_client_info;
-protected:
+public:
        KX_NearSensor(class SCA_EventManager* eventmgr,
                        class KX_GameObject* gameobj,
-                       void *shape,
                        double margin,
                        double resetmargin,
                        bool bFindMaterial,
                        const STR_String& touchedpropname,
                        class KX_Scene* scene,
+                        PHY_IPhysicsController*        ctrl,
                        PyTypeObject* T=&Type);
-
+/*
 public:
        KX_NearSensor(class SCA_EventManager* eventmgr,
                        class KX_GameObject* gameobj,
@@ -67,13 +69,14 @@ public:
                        const STR_String& touchedpropname,
                        class KX_Scene* scene,
                        PyTypeObject* T=&Type);
+*/
        virtual ~KX_NearSensor(); 
        virtual CValue* GetReplica();
        virtual bool Evaluate(CValue* event);
 
        virtual void ReParent(SCA_IObject* parent);
-       virtual DT_Bool HandleCollision(void* obj1,void* obj2,
-                                                const DT_CollData * coll_data); 
+       virtual bool    NewHandleCollision(void* obj1,void* obj2,
+                                                const PHY_CollData * coll_data); 
        virtual void RegisterSumo(KX_TouchEventManager *touchman);
        
        virtual PyObject* _getattr(const STR_String& attr);
index 14461145cb7658f9109eb000e33160c01060a993..cce2ceb70c2ff5f09ee6eb7958e12a6a986ed594 100644 (file)
 #include "KX_GameObject.h"
 #include "KX_MotionState.h"
 
+#include "MT_assert.h"
+
+#include "PHY_IPhysicsEnvironment.h"
+
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
@@ -225,7 +229,7 @@ SG_Controller*      KX_OdePhysicsController::GetReplica(class SG_Node* destnode)
        
 }
 
-void   KX_OdePhysicsController::resolveCombinedVelocities(const MT_Vector3 & lin_vel, const MT_Vector3 & ang_vel )
+void           KX_OdePhysicsController::resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ)
 {
 }
 
index 69c06a2b6208d8a0e80e8ea96bdd4b4763b37433..f5bc7dee1656d3cd5a05fc2ae16c69818749c7a3 100644 (file)
@@ -65,7 +65,7 @@ public:
        virtual MT_Vector3 GetVelocity(const MT_Point3& pos);
        virtual void    SetAngularVelocity(const MT_Vector3& ang_vel,bool local);
        virtual void    SetLinearVelocity(const MT_Vector3& lin_vel,bool local);
-       virtual void    resolveCombinedVelocities(const MT_Vector3 & lin_vel, const MT_Vector3 & ang_vel );
+       virtual void            resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ);
        virtual void            getOrientation(MT_Quaternion& orn);
        virtual void setOrientation(const MT_Quaternion& orn);
        virtual void setPosition(const MT_Point3& pos);
@@ -95,7 +95,7 @@ public:
        ){
                // intentionally empty
        };
-
+       
 };
 
 #endif //__KX_ODEPHYSICSCONTROLLER_H
index 0c7be571c8def9f7271c4ab80228942da519f8c8..89c84d639135d3bc984c406f42144d8dcd75f90d 100644 (file)
@@ -71,7 +71,7 @@ KX_PolygonMaterial::KX_PolygonMaterial(const STR_String &texname,
                                                                                           PyTypeObject *T)
                : PyObjectPlus(T),
                  RAS_IPolyMaterial(texname,
-                                                       material?STR_String(material->id.name):STR_String(""),
+                                                       STR_String(material?material->id.name:""),
                                                        tile,
                                                        tilexrep,
                                                        tileyrep,
index 1f810e655acee936b69d72e509dc8edea056122e..0111fd36cb212cb7f899f54c033b30e61b304a7b 100644 (file)
@@ -41,7 +41,7 @@
 
 // nasty glob variable to connect scripting language
 // if there is a better way (without global), please do so!
-static PHY_IPhysicsEnvironment* g_physics_env = NULL;
+static PHY_IPhysicsEnvironment* g_CurrentActivePhysicsEnvironment = NULL;
 
 static char PhysicsConstraints_module_documentation[] =
 "This is the Python API for the Physics Constraints";
@@ -59,8 +59,8 @@ static PyObject* gPySetGravity(PyObject* self,
        int len = PyTuple_Size(args);
        if ((len == 3) && PyArg_ParseTuple(args,"fff",&x,&y,&z))
        {
-               if (g_physics_env)
-                       g_physics_env->setGravity(x,y,z);
+               if (PHY_GetActiveEnvironment())
+                       PHY_GetActiveEnvironment()->setGravity(x,y,z);
        }
        Py_INCREF(Py_None); return Py_None;
 }
@@ -99,16 +99,16 @@ static PyObject* gPyCreateConstraint(PyObject* self,
        
        if (success)
        {
-               if (g_physics_env)
+               if (PHY_GetActiveEnvironment())
                {
                        
                        PHY_IPhysicsController* physctrl = (PHY_IPhysicsController*) physicsid;
                        PHY_IPhysicsController* physctrl2 = (PHY_IPhysicsController*) physicsid2;
                        if (physctrl) //TODO:check for existance of this pointer!
                        {
-                               int constraintid = g_physics_env->createConstraint(physctrl,physctrl2,(enum PHY_ConstraintType)constrainttype,pivotX,pivotY,pivotZ,axisX,axisY,axisZ);
+                               int constraintid = PHY_GetActiveEnvironment()->createConstraint(physctrl,physctrl2,(enum PHY_ConstraintType)constrainttype,pivotX,pivotY,pivotZ,axisX,axisY,axisZ);
                                
-                               KX_ConstraintWrapper* wrap = new KX_ConstraintWrapper((enum PHY_ConstraintType)constrainttype,constraintid,g_physics_env);
+                               KX_ConstraintWrapper* wrap = new KX_ConstraintWrapper((enum PHY_ConstraintType)constrainttype,constraintid,PHY_GetActiveEnvironment());
                                
 
                                return wrap;
@@ -130,9 +130,9 @@ static PyObject* gPyRemoveConstraint(PyObject* self,
        
        if (PyArg_ParseTuple(args,"i",&constraintid))
        {
-               if (g_physics_env)
+               if (PHY_GetActiveEnvironment())
                {
-                       g_physics_env->removeConstraint(constraintid);
+                       PHY_GetActiveEnvironment()->removeConstraint(constraintid);
                }
        }
        Py_INCREF(Py_None); return Py_None;
@@ -188,5 +188,11 @@ void       KX_RemovePythonConstraintBinding()
 
 void   PHY_SetActiveEnvironment(class  PHY_IPhysicsEnvironment* env)
 {
-       g_physics_env = env;
+       g_CurrentActivePhysicsEnvironment = env;
 }
+
+PHY_IPhysicsEnvironment*       PHY_GetActiveEnvironment()
+{
+       return g_CurrentActivePhysicsEnvironment;
+}
+
index f1ba459a19f0ef169848ad60edb7788adc07ef5d..a8651a175c25ecbc18772eb9c015e8ff0ee48437 100644 (file)
@@ -37,6 +37,8 @@
 PyObject*                              initPythonConstraintBinding();
 void   PHY_RemovePythonConstraintBinding();
 void   PHY_SetActiveEnvironment(class  PHY_IPhysicsEnvironment* env);
+PHY_IPhysicsEnvironment*       PHY_GetActiveEnvironment();
+
 
 #endif //PHY_PYTHON_CONSTRAINTBINDING
 
index 42b26185b4c85df20356b55666231d962ab954a1..6f2fced3bd1bcddf7408b9ae5dd2378df948cf24 100644 (file)
@@ -40,6 +40,8 @@
 #endif //WIN32
 
 #include "KX_PythonInit.h"
+//python physics binding
+#include "KX_PyConstraintBinding.h"
 
 #include "KX_KetsjiEngine.h"
 
@@ -211,7 +213,8 @@ static PyObject* gPySetPhysicsTicRate(PyObject*,
        float ticrate;
        if (PyArg_ParseTuple(args, "f", &ticrate))
        {
-               SumoPhysicsEnvironment::setTicRate(ticrate);
+
+               PHY_GetActiveEnvironment()->setFixedTimeStep(true,ticrate);
                Py_Return;
        }
        
@@ -220,7 +223,7 @@ static PyObject* gPySetPhysicsTicRate(PyObject*,
 
 static PyObject* gPyGetPhysicsTicRate(PyObject*, PyObject*, PyObject*)
 {
-       return PyFloat_FromDouble(SumoPhysicsEnvironment::getTicRate());
+       return PyFloat_FromDouble(PHY_GetActiveEnvironment()->getFixedTimeStep());
 }
 
 static STR_String gPyGetCurrentScene_doc =  
index 1ad3750422460e9fc76e8ba1b6075549cabfea39..ea656877e9277aea8cfca69cf0cbfaf7624d64bf 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "KX_RadarSensor.h"
 #include "KX_GameObject.h"
+#include "PHY_IPhysicsController.h"
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -41,6 +42,7 @@
  */
 KX_RadarSensor::KX_RadarSensor(SCA_EventManager* eventmgr,
                KX_GameObject* gameobj,
+               PHY_IPhysicsController* physCtrl,
                        double coneradius,
                        double coneheight,
                        int     axis,
@@ -54,12 +56,13 @@ KX_RadarSensor::KX_RadarSensor(SCA_EventManager* eventmgr,
                        : KX_NearSensor(
                                eventmgr,
                                gameobj,
-                               DT_NewCone(coneradius,coneheight),
+                               //DT_NewCone(coneradius,coneheight),
                                margin,
                                resetmargin,
                                bFindMaterial,
                                touchedpropname,
                                kxscene,
+                               physCtrl,
                                T),
                                m_coneradius(coneradius),
                                m_coneheight(coneheight),
@@ -90,9 +93,11 @@ CValue* KX_RadarSensor::GetReplica()
        
        replica->m_client_info = new KX_ClientObjectInfo(m_client_info->m_gameobject, KX_ClientObjectInfo::RADAR);
        
-       replica->m_sumoObj = new SM_Object(DT_NewCone(m_coneradius, m_coneheight),NULL,NULL,NULL);
-       replica->m_sumoObj->setMargin(m_Margin);
-       replica->m_sumoObj->setClientObject(replica->m_client_info);
+       replica->m_physCtrl = replica->m_physCtrl->GetReplica();
+       //todo: make sure replication works fine!
+       //>m_sumoObj = new SM_Object(DT_NewCone(m_coneradius, m_coneheight),NULL,NULL,NULL);
+       //replica->m_sumoObj->setMargin(m_Margin);
+       //replica->m_sumoObj->setClientObject(replica->m_client_info);
        
        replica->SynchronizeTransform();
        
@@ -145,9 +150,11 @@ void KX_RadarSensor::SynchronizeTransform()
        m_cone_origin = trans.getOrigin();
        m_cone_target = trans(MT_Point3(0, -m_coneheight/2.0 ,0));
 
-       m_sumoObj->setPosition(trans.getOrigin());
-       m_sumoObj->setOrientation(trans.getRotation());
-       m_sumoObj->calcXform();
+
+       m_physCtrl->setPosition(trans.getOrigin().x(),trans.getOrigin().y(),trans.getOrigin().z());
+       m_physCtrl->setOrientation(trans.getRotation().x(),trans.getRotation().y(),trans.getRotation().z(),trans.getRotation().w());
+       m_physCtrl->calcXform();
+
 }
 
 /* ------------------------------------------------------------------------- */
index 0e055357f1805e71f515f008429c3faf871fffcc..4f5ff994b40bb0f31814fc8f563d551cac9a157d 100644 (file)
@@ -65,6 +65,7 @@ public:
 
        KX_RadarSensor(SCA_EventManager* eventmgr,
                KX_GameObject* gameobj,
+                       PHY_IPhysicsController* physCtrl,
                        double coneradius,
                        double coneheight,
                        int     axis,
diff --git a/source/gameengine/Ketsji/KX_RayCast.cpp b/source/gameengine/Ketsji/KX_RayCast.cpp
new file mode 100644 (file)
index 0000000..98ebde9
--- /dev/null
@@ -0,0 +1,97 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. The Blender
+ * Foundation also sells licenses for use in proprietary software under
+ * the Blender License.  See http://www.blender.org/BL/ for information
+ * about this.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ * KX_MouseFocusSensor determines mouse in/out/over events.
+ */
+
+#include "KX_RayCast.h"
+
+#include "MT_Point3.h"
+#include "MT_Vector3.h"
+
+#include "KX_IPhysicsController.h"
+#include "PHY_IPhysicsEnvironment.h"
+#include "PHY_IPhysicsController.h"
+
+bool KX_RayCast::RayTest(KX_IPhysicsController* ignore_controller, PHY_IPhysicsEnvironment* physics_environment, const MT_Point3& _frompoint, const MT_Point3& topoint, MT_Point3& result_point, MT_Vector3& result_normal, const KX_RayCast& callback)
+{
+       // Loops over all physics objects between frompoint and topoint,
+       // calling callback.RayHit for each one.
+       //
+       // callback.RayHit should return true to stop looking, or false to continue.
+       //
+       // returns true if an object was found, false if not.
+       MT_Point3 frompoint(_frompoint);
+       const MT_Vector3 todir( (topoint - frompoint).normalized() );
+       
+       PHY_IPhysicsController* hit_controller;
+       PHY__Vector3 phy_pos;
+       PHY__Vector3 phy_normal;
+
+       while((hit_controller = physics_environment->rayTest(dynamic_cast<PHY_IPhysicsController*>(ignore_controller),
+                       frompoint.x(),frompoint.y(),frompoint.z(),
+                       topoint.x(),topoint.y(),topoint.z(),
+                       phy_pos[0],phy_pos[1],phy_pos[2],
+                       phy_normal[0],phy_normal[1],phy_normal[2]))) 
+       {
+               result_point = MT_Point3(phy_pos);
+               result_normal = MT_Vector3(phy_normal);
+               KX_ClientObjectInfo* info = static_cast<KX_ClientObjectInfo*>(hit_controller->getNewClientInfo());
+               
+               if (!info)
+               {
+                       MT_assert(info && "Physics controller with no client object info");
+                       return false;
+               }
+               
+               if (callback.RayHit(info, result_point, result_normal))
+                       return true;
+               
+               // skip past the object and keep tracing
+               /* We add 0.01 of fudge, so that if the margin && radius == 0., we don't endless loop. */
+               MT_Scalar marg = 0.01 + hit_controller->GetMargin();
+               marg += 2.f * hit_controller->GetMargin();
+               /* Calculate the other side of this object */
+               PHY__Vector3 hitpos;
+               hit_controller->getPosition(hitpos);
+               MT_Point3 hitObjPos(hitpos);
+               
+               MT_Vector3 hitvector = hitObjPos - result_point;
+               if (hitvector.dot(hitvector) > MT_EPSILON)
+               {
+                       hitvector.normalize();
+                       marg *= 2.*todir.dot(hitvector);
+               }
+               frompoint = result_point + marg * todir;
+       }
+       
+       return hit_controller;
+}
+
diff --git a/source/gameengine/Ketsji/KX_RayCast.h b/source/gameengine/Ketsji/KX_RayCast.h
new file mode 100644 (file)
index 0000000..8bb21e2
--- /dev/null
@@ -0,0 +1,107 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. The Blender
+ * Foundation also sells licenses for use in proprietary software under
+ * the Blender License.  See http://www.blender.org/BL/ for information
+ * about this.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ */
+
+#ifndef __KX_RAYCAST_H__
+#define __KX_RAYCAST_H__
+
+class MT_Point3;
+class MT_Vector3;
+class KX_IPhysicsController;
+class PHY_IPhysicsEnvironment;
+
+struct KX_ClientObjectInfo;
+
+/**
+ *  Defines a function for doing a ray cast.
+ *
+ *  eg KX_RayCast::RayTest(ignore_physics_controller, physics_environment, frompoint, topoint, result_point, result_normal, KX_RayCast::Callback<KX_MyClass>(this, data)
+ *
+ *  Calls myclass->RayHit(client, hit_point, hit_normal, data) for all client
+ *  between frompoint and topoint
+ *
+ *  myclass->RayHit should return true to end the raycast, false to ignore the current client.
+ *
+ *  Returns true if a client was accepted, false if nothing found.
+ */
+class KX_RayCast
+{
+protected:
+       KX_RayCast() {};
+public:
+       virtual ~KX_RayCast() {}
+
+       /** ray test callback.
+        *  either override this in your class, or use a callback wrapper.
+        */
+       virtual bool RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal) const = 0;
+
+       /** 
+        *  Callback wrapper.
+        *
+        *  Construct with KX_RayCast::Callback<MyClass>(this, data)
+        *  and pass to KX_RayCast::RayTest
+        */
+       template<class T> class Callback;
+       
+       /// Public interface.
+       /// Implement bool RayHit in your class to receive ray callbacks.
+       static bool RayTest(KX_IPhysicsController* physics_controller, 
+               PHY_IPhysicsEnvironment* physics_environment, 
+               const MT_Point3& _frompoint, 
+               const MT_Point3& topoint, 
+               MT_Point3& result_point, 
+               MT_Vector3& result_normal, 
+               const KX_RayCast& callback);
+       
+};
+
+template<class T> class KX_RayCast::Callback : public KX_RayCast
+{
+       T *self;
+       void *data;
+public:
+       Callback(T *_self, void *_data = NULL)
+               : self(_self),
+               data(_data)
+       {
+       }
+       
+       ~Callback() {}
+       
+       virtual bool RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal) const
+       {
+               return self->RayHit(client, hit_point, hit_normal, data);
+       }
+};
+       
+
+#endif
index c60b2171cab3650543dc847a41452b7b1196107e..fa5f5215aa427d058c21238a096aaa72ae92dffa 100644 (file)
 #include "KX_GameObject.h"
 #include "KX_Scene.h"
 
-#include "SumoPhysicsEnvironment.h"
-#include "KX_SumoPhysicsController.h"
+#include "KX_RayCast.h"
+#include "PHY_IPhysicsEnvironment.h"
+#include "PHY_IPhysicsController.h"
+#include "KX_IPhysicsController.h"
+
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -101,7 +104,47 @@ bool KX_RaySensor::IsPositiveTrigger()
        return result;
 }
 
+bool KX_RaySensor::RayHit(KX_ClientObjectInfo* info, MT_Point3& hit_point, MT_Vector3& hit_normal, void* const data)
+{
+       KX_GameObject* obj = (KX_GameObject*)GetParent();
+       SCA_IObject *hitgameobj = info->m_gameobject;
+       if (hitgameobj == obj || info->m_type > KX_ClientObjectInfo::ACTOR)
+       {
+               // false hit
+               return false;
+       }
+       
+       bool bFound = false;
+       if (m_propertyname.Length() == 0)
+       {
+               bFound = true;
+       }
+       else
+       {
+               if (m_bFindMaterial)
+               {
+                       if (info->m_auxilary_info)
+                       {
+                               bFound = (m_propertyname== ((char*)info->m_auxilary_info));
+                       }
+               }
+               else
+               {
+                       bFound = hitgameobj->GetProperty(m_propertyname) != NULL;
+               }
+       }
 
+       if (bFound)
+       {
+               m_rayHit = true;
+               m_hitObject = hitgameobj;
+               m_hitPosition = hit_point;
+               m_hitNormal = hit_normal;
+                       
+       }
+       
+       return true;
+}
 
 bool KX_RaySensor::Evaluate(CValue* event)
 {
@@ -168,115 +211,64 @@ bool KX_RaySensor::Evaluate(CValue* event)
        MT_Point3 topoint = frompoint + (m_distance) * todir;
        MT_Point3 resultpoint;
        MT_Vector3 resultnormal;
-       bool ready = false;
-       SumoPhysicsEnvironment *spe = dynamic_cast<SumoPhysicsEnvironment *>(m_scene->GetPhysicsEnvironment());
-       if (!spe)
+       PHY_IPhysicsEnvironment* physics_environment = m_scene->GetPhysicsEnvironment();
+       if (!physics_environment)
        {
                std::cout << "WARNING: Ray sensor " << GetName() << ":  There is no physics environment!" << std::endl;
                std::cout << "         Check universe for malfunction." << std::endl;
                return false;
        } 
-       SM_Scene *scene = spe->GetSumoScene();
-       KX_SumoPhysicsController *spc = dynamic_cast<KX_SumoPhysicsController *>(obj->GetPhysicsController());
+       KX_IPhysicsController* physics_controller = obj->GetPhysicsController();
+
+       // Use the parent's physics controller if obj has no physics controller.
        KX_GameObject *parent = obj->GetParent();
-       if (!spc && parent)
-               spc = dynamic_cast<KX_SumoPhysicsController *>(parent->GetPhysicsController());
+       if (!physics_controller && parent)
+               physics_controller = parent->GetPhysicsController();
+
        if (parent)
                parent->Release();
-       SM_Object *thisObj = spc?spc->GetSumoObject():NULL;
-       
-       do {
-               SM_Object* hitObj = scene->rayTest(thisObj,
-                       frompoint,
-                       topoint,
-                       resultpoint,
-                       resultnormal);
-                       
-               if (hitObj)
-               {
-       
-                       KX_ClientObjectInfo* info = static_cast<KX_ClientObjectInfo*>(hitObj->getClientObject());
-                       bool bFound = false;
-                       
-                       if (!info)
-                       {
-                               std::cout<< "WARNING:  Ray sensor " << GetName() << " cannot sense SM_Object " << hitObj << " - no client info.\n" << std::endl;
-                               ready = true;
-                               break;
-                       } 
-                       
-                       SCA_IObject *hitgameobj = info->m_gameobject;
-                       
-                       if (hitgameobj == obj || info->m_type > KX_ClientObjectInfo::ACTOR)
-                       {
-                               // false hit
-                               KX_SumoPhysicsController *hitspc = dynamic_cast<KX_SumoPhysicsController *> (static_cast<KX_GameObject*> (hitgameobj) ->GetPhysicsController());
-                               if (hitspc)
-                               {
-                                       /* We add 0.01 of fudge, so that if the margin && radius == 0., we don't endless loop. */
-                                       MT_Scalar marg = 0.01 + hitspc->GetSumoObject()->getMargin();
-                                       if (hitspc->GetSumoObject()->getShapeProps())
-                                       {
-                                               marg += 2*hitspc->GetSumoObject()->getShapeProps()->m_radius;
-                                       }
-                                       
-                                       /* Calculate the other side of this object */
-                                       MT_Point3 hitObjPos;
-                                       hitspc->GetWorldPosition(hitObjPos);
-                                       MT_Vector3 hitvector = hitObjPos - resultpoint;
-                                       if (hitvector.dot(hitvector) > MT_EPSILON)
-                                       {
-                                               hitvector.normalize();
-                                               marg *= 2.*todir.dot(hitvector);
-                                       }
-                                       frompoint = resultpoint + marg * todir;
-                               } else {
-                                       ready = true;
-                               }
-                       }
-                       else
-                       {
-                               ready = true;
-                               if (m_propertyname.Length() == 0)
-                               {
-                                       bFound = true;
-                               }
-                               else
-                               {
-                                       if (m_bFindMaterial)
-                                       {
-                                               if (info->m_auxilary_info)
-                                               {
-                                                       bFound = (m_propertyname== ((char*)info->m_auxilary_info));
-                                               }
-                                       }
-                                       else
-                                       {
-                                               bFound = hitgameobj->GetProperty(m_propertyname) != NULL;
-                                       }
-                               }
-
-                               if (bFound)
-                               {
-                                       m_rayHit = true;
-                                       m_hitObject = hitgameobj;
-                                       m_hitPosition = resultpoint;
-                                       m_hitNormal = resultnormal;
-                                               
-                               }
-                       }
-               }
-               else
-               {
-                       ready = true;
-               }
-       }
-       while (!ready);
-       
+               
+       KX_RayCast::RayTest(physics_controller, physics_environment, frompoint, topoint, resultpoint, resultnormal, KX_RayCast::Callback<KX_RaySensor>(this));
+
+//     do {
+//             PHY__Vector3 respos;
+//             PHY__Vector3 resnormal;
+// 
+//             PHY_IPhysicsController* hitCtrl = spe->rayTest(physCtrl,
+//                     frompoint.x(),frompoint.y(),frompoint.z(),
+//                     topoint.x(),topoint.y(),topoint.z(),
+//                     respos[0],respos[1],respos[2],
+//                     resnormal[0],resnormal[1],resnormal[2]);
+//                     
+//             if (hitCtrl)
+//             {
+// 
+//                     resultpoint = MT_Vector3(respos);
+//                     resultnormal = MT_Vector3(resnormal);
+//                     KX_ClientObjectInfo* info = static_cast<KX_ClientObjectInfo*>(hitCtrl->getNewClientInfo());
+//                     bool bFound = false;
+//                     
+//                     if (!info)
+//                     {
+//                             std::cout<< "WARNING:  Ray sensor " << GetName() << " cannot sense PHY_IPhysicsController  - no client info.\n" << std::endl;
+//                             ready = true;
+//                             break;
+//                     } 
+//                     
+//                     
+// 
+//             }
+//             else
+//             {
+//                     ready = true;
+//             }
+//     }
+//     while (!ready);
+//     
        
        
        /* now pass this result to some controller */
-    if (m_rayHit) 
+       if (m_rayHit) 
        {
                if (!m_bTriggered)
                {
@@ -284,10 +276,6 @@ bool KX_RaySensor::Evaluate(CValue* event)
                        result = true;
                        m_bTriggered = true;
                }
-               else
-               {
-                       
-               }
        }
        else
        {
index 8d361f53d3e22e4a4a2aa65736c662f5a09437fb..0e05c6021c0a01b529ea9ba3a787afb9ed699c9c 100644 (file)
@@ -38,6 +38,8 @@
 #include "SCA_ISensor.h"
 #include "MT_Point3.h"
 
+struct KX_ClientObjectInfo;
+
 class KX_RaySensor : public SCA_ISensor
 {
        Py_Header;
@@ -68,6 +70,8 @@ public:
        virtual bool Evaluate(CValue* event);
        virtual bool IsPositiveTrigger();
 
+       bool RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data);
+       
        KX_PYMETHOD_DOC(KX_RaySensor,GetHitObject);
        KX_PYMETHOD_DOC(KX_RaySensor,GetHitPosition);
        KX_PYMETHOD_DOC(KX_RaySensor,GetHitNormal);
index 8af01c561f25a9ca29c8ecc2473d9b2aa615cfe5..540e14d06eaed7fd1fcf54a53e226f3eeec1427e 100644 (file)
@@ -56,7 +56,7 @@ UpdateChildCoordinates(
        SG_Spatial * child,
        const SG_Spatial * parent
 ){
-       assert(child != NULL);
+       MT_assert(child != NULL);
 
        // This way of accessing child coordinates is a bit cumbersome
        // be nice to have non constant reference access to these values.
@@ -140,7 +140,7 @@ UpdateChildCoordinates(
        const SG_Spatial * parent
 ){
 
-       assert(child != NULL);
+       MT_assert(child != NULL);
 
        const MT_Vector3 & child_scale = child->GetLocalScale();
        const MT_Point3 & child_pos = child->GetLocalPosition();
@@ -225,7 +225,7 @@ UpdateChildCoordinates(
        SG_Spatial * child,
        const SG_Spatial * parent
 ){
-       assert(child != NULL);
+       MT_assert(child != NULL);
 
        const MT_Vector3 & child_scale = child->GetLocalScale();
        const MT_Point3 & child_pos = child->GetLocalPosition();
index 2046c52355c074b3a93ddf51a899aa2cab399da2..eb3f8821b62311eb030b91fa2727c1faf069d306 100644 (file)
@@ -73,8 +73,6 @@
 #include "PHY_IPhysicsEnvironment.h"
 #include "KX_IPhysicsController.h"
 
-#include "SM_Scene.h"
-#include "SumoPhysicsEnvironment.h"
 
 void* KX_SceneReplicationFunc(SG_IObject* node,void* gameobj,void* scene)
 {
@@ -398,7 +396,7 @@ KX_GameObject* KX_Scene::AddNodeReplicaObject(class SG_IObject* node, class CVal
        }
        
        SG_IObject* replicanode = newobj->GetSGNode();
-       // SG_Node* rootnode = (replicanode == m_rootnode ? NULL : m_rootnode); /*unused*/
+       SG_Node* rootnode = (replicanode == m_rootnode ? NULL : m_rootnode);
 
        replicanode->SetSGClientObject(newobj);
 
@@ -660,11 +658,10 @@ void KX_Scene::DelayedRemoveObject(class CValue* gameobj)
 void KX_Scene::NewRemoveObject(class CValue* gameobj)
 {
        KX_GameObject* newobj = (KX_GameObject*) gameobj;
-       //SM_Object* sumoObj = newobj->GetSumoObject();
-       //if (sumoObj)
-       //{
-       //      this->GetSumoScene()->remove(*sumoObj);
-       //}
+
+       //todo: look at this
+       //GetPhysicsEnvironment()->RemovePhysicsController(gameobj->getPhysicsController());
+
        // remove all sensors/controllers/actuators from logicsystem...
        
        SCA_SensorList& sensors = newobj->GetSensors();
@@ -1104,14 +1101,11 @@ void KX_Scene::SetNodeTree(SG_Tree* root)
 
 void KX_Scene::SetPhysicsEnvironment(class PHY_IPhysicsEnvironment* physEnv)
 {
-       SumoPhysicsEnvironment *sme = dynamic_cast<SumoPhysicsEnvironment *>(physEnv);
        m_physicsEnvironment = physEnv;
-       if (sme)
-       {
-               KX_TouchEventManager* touchmgr = new KX_TouchEventManager(m_logicmgr, sme->GetSumoScene());
-               m_logicmgr->RegisterEventManager(touchmgr);
-               return;
-       }
+
+       KX_TouchEventManager* touchmgr = new KX_TouchEventManager(m_logicmgr, physEnv);
+       m_logicmgr->RegisterEventManager(touchmgr);
+       return;
 }
 
 //----------------------------------------------------------------------------
index 27f234f52a693851f9ee8218b2ee0dff11ff3345..0c0ee4e287a3d94056102e461045848b60579c56 100644 (file)
@@ -128,7 +128,7 @@ protected:
        * physics engine abstraction
        */
 
-       e_PhysicsEngine m_physicsEngine;
+       //e_PhysicsEngine m_physicsEngine; //who needs this ?
        class PHY_IPhysicsEnvironment*          m_physicsEnvironment;
 
        /**
index 793c3b84206cf02b68738e99d33ae447ac397947..f7a2001fcdfa7e74829563b2df768f5fd09ebac4 100644 (file)
@@ -64,6 +64,8 @@ KX_SoundActuator::KX_SoundActuator(SCA_IObject* gameobj,
        m_startFrame = start;
        m_endFrame = end;
        m_pino = false;
+       
+
 }
 
 
index 8f284809a1719c9bd69da4e82ffcada1047605b2..609f0fc0e0b608979c8c143d0445baf493611777 100644 (file)
@@ -10,6 +10,8 @@
 #include "KX_MotionState.h"
 #include "KX_ClientObjectInfo.h"
 
+#include "PHY_IPhysicsEnvironment.h"
+
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
@@ -64,12 +66,9 @@ MT_Vector3 KX_SumoPhysicsController::GetLinearVelocity()
        
 }
 
-void KX_SumoPhysicsController::resolveCombinedVelocities(
-               const MT_Vector3 & lin_vel,
-               const MT_Vector3 & ang_vel
-       )
+void           KX_SumoPhysicsController::resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ)
 {
-       SumoPhysicsController::resolveCombinedVelocities(lin_vel, ang_vel);
+       SumoPhysicsController::resolveCombinedVelocities(linvelX,linvelY,linvelZ,angVelX,angVelY,angVelZ);
 }
 
 void   KX_SumoPhysicsController::ApplyTorque(const MT_Vector3& torque,bool local)
@@ -215,3 +214,5 @@ KX_SumoPhysicsController::~KX_SumoPhysicsController()
 
        
 }
+
+
index b160315ce537977d8f9dd2234e0f84474086d46f..b4b0f8a4cd0468dcced2e9a28f0a6192b0ce58ae 100644 (file)
@@ -33,7 +33,6 @@
 #define __KX_SUMOPHYSICSCONTROLLER_H
 
 #include "PHY_IPhysicsController.h"
-#include "SM_Object.h" // for SM_Callback
 
 /**
        Physics Controller, a special kind of Scene Graph Transformation Controller.
@@ -54,7 +53,6 @@ class KX_SumoPhysicsController : public KX_IPhysicsController,
 public:
        KX_SumoPhysicsController(
                class SM_Scene* sumoScene,
-/*             DT_SceneHandle solidscene, */
                class SM_Object* sumoObj,       
                class PHY_IMotionState* motionstate
                ,bool dyna) 
@@ -76,7 +74,7 @@ public:
        MT_Vector3 GetVelocity(const MT_Point3& pos);
        void    SetAngularVelocity(const MT_Vector3& ang_vel,bool local);
        void    SetLinearVelocity(const MT_Vector3& lin_vel,bool local);
-       void    resolveCombinedVelocities(const MT_Vector3 & lin_vel, const MT_Vector3 & ang_vel);
+       void    resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ);
 
 
        void    SuspendDynamics();
@@ -108,8 +106,6 @@ public:
        ){
                // intentionally empty
        };
-
-
 };
 
 #endif //__KX_SUMOPHYSICSCONTROLLER_H
index a95e6a135486968a11d97302556ddddc1e6594b7..575ade6dc3b6cb85eb338cd42a250a5cfe061a30 100644 (file)
 #include "SCA_ISensor.h"
 #include "KX_TouchSensor.h"
 #include "KX_GameObject.h"
+#include "PHY_IPhysicsEnvironment.h"
+#include "PHY_IPhysicsController.h"
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 
-#include "SM_Object.h"
 
 KX_TouchEventManager::KX_TouchEventManager(class SCA_LogicManager* logicmgr,
-       SM_Scene *scene)
+       PHY_IPhysicsEnvironment* physEnv)
        : SCA_EventManager(TOUCH_EVENTMGR),
          m_logicmgr(logicmgr),
-         m_scene(scene)
+         m_physEnv(physEnv)
 {
-       //m_scene->addTouchCallback(STATIC_RESPONSE, KX_TouchEventManager::collisionResponse, this);
-       m_scene->addTouchCallback(OBJECT_RESPONSE, KX_TouchEventManager::collisionResponse, this);
-       m_scene->addTouchCallback(SENSOR_RESPONSE, KX_TouchEventManager::collisionResponse, this);
-}
+       //notm_scene->addTouchCallback(STATIC_RESPONSE, KX_TouchEventManager::collisionResponse, this);
+
+       //m_scene->addTouchCallback(OBJECT_RESPONSE, KX_TouchEventManager::collisionResponse, this);
+       //m_scene->addTouchCallback(SENSOR_RESPONSE, KX_TouchEventManager::collisionResponse, this);
+
+       m_physEnv->addTouchCallback(PHY_OBJECT_RESPONSE, KX_TouchEventManager::newCollisionResponse, this);
+       m_physEnv->addTouchCallback(PHY_SENSOR_RESPONSE, KX_TouchEventManager::newCollisionResponse, this);
 
-DT_Bool KX_TouchEventManager::HandleCollision(void* object1, void* object2, const DT_CollData *coll_data)
-{
-       SM_Object * obj1 = static_cast<SM_Object*>(object1);
-       SM_Object * obj2 = static_cast<SM_Object*>(object2);
-       
-       m_collisions.insert(std::pair<SM_Object*, SM_Object*>(obj1, obj2));
-               
-       return DT_CONTINUE;
 }
 
-/*
-DT_Bool KX_TouchEventManager::HandleCollision(void* object1,void* object2,
-                                                const DT_CollData * coll_data)
+bool   KX_TouchEventManager::NewHandleCollision(void* object1, void* object2, const PHY_CollData *coll_data)
 {
-       SM_Object * obj1 = (SM_Object *) object1;
-       SM_Object * obj2 = (SM_Object *) object2;
 
-       for ( vector<SCA_ISensor*>::iterator it = m_sensors.begin(); !(it==m_sensors.end()); it++)
-       {
-               KX_GameObject* gameobj = ((KX_GameObject*)((KX_TouchSensor*)*it)->GetParent());
-               KX_ClientObjectInfo *client_info = (KX_ClientObjectInfo *) obj1->getClientObject();
-// Enable these printfs to create excesive debug info
-//             printf("KX_TEM::HC: Sensor %s\tGO: %p o1: %s (%p)", (const char *) (*it)->GetName(), gameobj, (const char *) ((KX_GameObject *) client_info->m_clientobject)->GetName(), client_info->m_clientobject);
-               if (client_info && client_info->m_clientobject == gameobj)
-                       ((KX_TouchSensor*)*it)->HandleCollision(object1,object2,coll_data);
-
-               client_info = (KX_ClientObjectInfo *) obj2->getClientObject();
-//             printf(" o2: %s (%p)\n", (const char *) ((KX_GameObject *) client_info->m_clientobject)->GetName(), client_info->m_clientobject);
-               if (client_info && client_info->m_clientobject == gameobj)
-                        ((KX_TouchSensor*)*it)->HandleCollision(object1,object2,coll_data);
-
-       }
+       PHY_IPhysicsController* obj1 = static_cast<PHY_IPhysicsController*>(object1);
+       PHY_IPhysicsController* obj2 = static_cast<PHY_IPhysicsController*>(object2);
        
-       return DT_CONTINUE;
+       m_newCollisions.insert(std::pair<PHY_IPhysicsController*, PHY_IPhysicsController*>(obj1, obj2));
+               
+       return false;
 }
 
-*/
 
-DT_Bool KX_TouchEventManager::collisionResponse(void *client_data, 
+bool    KX_TouchEventManager::newCollisionResponse(void *client_data, 
                                                        void *object1,
                                                        void *object2,
-                                                       const DT_CollData *coll_data)
+                                                       const PHY_CollData *coll_data)
 {
        KX_TouchEventManager *touchmgr = (KX_TouchEventManager *) client_data;
-       touchmgr->HandleCollision(object1, object2, coll_data);
-       return DT_CONTINUE;
+       touchmgr->NewHandleCollision(object1, object2, coll_data);
+       return false;
 }
 
 void KX_TouchEventManager::RegisterSensor(SCA_ISensor* sensor)
@@ -131,20 +111,25 @@ void KX_TouchEventManager::NextFrame()
                for (it = m_sensors.begin();!(it==m_sensors.end());++it)
                        static_cast<KX_TouchSensor*>(*it)->SynchronizeTransform();
                
-               for (std::set<Collision>::iterator cit = m_collisions.begin(); cit != m_collisions.end(); ++cit)
+               for (std::set<NewCollision>::iterator cit = m_newCollisions.begin(); cit != m_newCollisions.end(); ++cit)
                {
-                       KX_ClientObjectInfo *client_info = static_cast<KX_ClientObjectInfo *>((*cit).first->getClientObject());
+                       PHY_IPhysicsController* ctrl1 = (*cit).first;
+                       PHY_IPhysicsController* ctrl2 = (*cit).second;
+//                     KX_GameObject* gameOb1 = ctrl1->getClientInfo();
+//                     KX_GameObject* gameOb1 = ctrl1->getClientInfo();
+
+                       KX_ClientObjectInfo *client_info = static_cast<KX_ClientObjectInfo *>(ctrl1->getNewClientInfo());
        
                        list<SCA_ISensor*>::iterator sit;
                        for ( sit = client_info->m_sensors.begin(); sit != client_info->m_sensors.end(); ++sit)
-                               static_cast<KX_TouchSensor*>(*sit)->HandleCollision((*cit).first, (*cit).second, NULL);
+                               static_cast<KX_TouchSensor*>(*sit)->NewHandleCollision((*cit).first, (*cit).second, NULL);
                
-                       client_info = static_cast<KX_ClientObjectInfo *>((*cit).second->getClientObject());
+                       client_info = static_cast<KX_ClientObjectInfo *>((*cit).second->getNewClientInfo());
                        for ( sit = client_info->m_sensors.begin(); sit != client_info->m_sensors.end(); ++sit)
-                               static_cast<KX_TouchSensor*>(*sit)->HandleCollision((*cit).second, (*cit).first, NULL);
+                               static_cast<KX_TouchSensor*>(*sit)->NewHandleCollision((*cit).second, (*cit).first, NULL);
                }
                        
-               m_collisions.clear();
+               m_newCollisions.clear();
                        
                for (it = m_sensors.begin();!(it==m_sensors.end());++it)
                        (*it)->Activate(m_logicmgr,NULL);
index 128758f0be6c3573898bf708054b233976df27d1..21faceef799cb32b6be4f392624a713032ea446c 100644 (file)
@@ -32,6 +32,7 @@
 #ifndef __KX_TOUCHEVENTMANAGER
 #define __KX_TOUCHEVENTMANAGER
 
+
 #include "SCA_EventManager.h"
 #include "KX_TouchSensor.h"
 #include "KX_GameObject.h"
 #include <set>
 
 class SCA_ISensor;
-class SM_Object;
+class PHY_IPhysicsEnvironment;
 
 class KX_TouchEventManager : public SCA_EventManager
 {
-       typedef std::pair<SM_Object*, SM_Object*> Collision;
+       typedef std::pair<PHY_IPhysicsController*, PHY_IPhysicsController*> NewCollision;
        class SCA_LogicManager* m_logicmgr;
-       SM_Scene *m_scene;
+       PHY_IPhysicsEnvironment*        m_physEnv;
        
-       std::set<Collision> m_collisions;
+       std::set<NewCollision> m_newCollisions;
        
-
-       static DT_Bool collisionResponse(void *client_data, 
-                                                       void *object1,
-                                                       void *object2,
-                                                       const DT_CollData *coll_data);
        
-       virtual DT_Bool HandleCollision(void* obj1,void* obj2,
-                                                const DT_CollData * coll_data); 
+       static bool newCollisionResponse(void *client_data, 
+                                               void *object1,
+                                               void *object2,
+                                               const PHY_CollData *coll_data);
        
+       virtual bool    NewHandleCollision(void* obj1,void* obj2,
+                                               const PHY_CollData * coll_data); 
+
+
+
+
 
 public:
        KX_TouchEventManager(class SCA_LogicManager* logicmgr,  
-               SM_Scene *scene);
+               PHY_IPhysicsEnvironment* physEnv);
        virtual void NextFrame();
        virtual void    EndFrame();
        virtual void    RemoveSensor(class SCA_ISensor* sensor);
        virtual void RegisterSensor(SCA_ISensor* sensor);
        SCA_LogicManager* GetLogicManager() { return m_logicmgr;}
-       SM_Scene *GetSumoScene() { return m_scene; }
+       PHY_IPhysicsEnvironment *GetPhysicsEnvironment() { return m_physEnv; }
+
 };
 
 #endif //__KX_TOUCHEVENTMANAGER
index 64dc175f451588fec850e09bfe6b27d9c2796ce0..e89b1e41434b3bfd8f04364479729223274f3858 100644 (file)
@@ -37,9 +37,9 @@
 #include "SCA_LogicManager.h"
 #include "KX_GameObject.h"
 #include "KX_TouchEventManager.h"
-#include "SM_Object.h"
 #include "KX_SumoPhysicsController.h"
 #include <iostream>
+#include "PHY_IPhysicsEnvironment.h"
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 void KX_TouchSensor::SynchronizeTransform()
 {
 
-       if (m_sumoObj)
+       if (m_physCtrl)
        {
-               m_sumoObj->setPosition(((KX_GameObject*)GetParent())->NodeGetWorldPosition());
-               m_sumoObj->setOrientation(
-                       ((KX_GameObject*)GetParent())->NodeGetWorldOrientation().getRotation()
-                       );
-               m_sumoObj->calcXform();
+               MT_Vector3 pos = ((KX_GameObject*)GetParent())->NodeGetWorldPosition();
+               MT_Quaternion orn = ((KX_GameObject*)GetParent())->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();
        }
        
 }
@@ -84,7 +84,7 @@ bool KX_TouchSensor::Evaluate(CValue* event)
        return result;
 }
 
-KX_TouchSensor::KX_TouchSensor(SCA_EventManager* eventmgr,KX_GameObject* gameobj,/*SM_Object* sumoObj,*/bool bFindMaterial,const STR_String& touchedpropname,PyTypeObject* T)
+KX_TouchSensor::KX_TouchSensor(SCA_EventManager* eventmgr,KX_GameObject* gameobj,bool bFindMaterial,const STR_String& touchedpropname,PyTypeObject* T)
 :SCA_ISensor(gameobj,eventmgr,T),
 m_touchedpropname(touchedpropname),
 m_bFindMaterial(bFindMaterial),
@@ -94,7 +94,7 @@ m_bCollision(false),
 m_bTriggered(false),
 m_bLastTriggered(false)
 {
-       // KX_TouchEventManager* touchmgr = (KX_TouchEventManager*) eventmgr; /*unused*/
+       KX_TouchEventManager* touchmgr = (KX_TouchEventManager*) eventmgr;
 //     m_resptable = touchmgr->GetResponseTable();
        
 //     m_solidHandle = m_sumoObj->getObjectHandle();
@@ -107,10 +107,8 @@ m_bLastTriggered(false)
        client_info->m_auxilary_info = NULL;
        client_info->m_sensors.push_back(this);
        
-       KX_SumoPhysicsController *sphy = dynamic_cast<KX_SumoPhysicsController *>(gameobj->GetPhysicsController());
-       if (sphy)
-               m_sumoObj = sphy->GetSumoObject();
-
+       m_physCtrl = dynamic_cast<PHY_IPhysicsController*>(gameobj->GetPhysicsController());
+       MT_assert( !gameobj->GetPhysicsController() || m_physCtrl );
 }
 
 
@@ -136,10 +134,10 @@ CValue* KX_TouchSensor::GetReplica()
 void   KX_TouchSensor::ReParent(SCA_IObject* parent)
 {
        KX_GameObject *gameobj = static_cast<KX_GameObject *>(parent);
-       KX_SumoPhysicsController *sphy = dynamic_cast<KX_SumoPhysicsController *>(((KX_GameObject*)parent)->GetPhysicsController());
+       PHY_IPhysicsController *sphy = dynamic_cast<PHY_IPhysicsController*>(((KX_GameObject*)parent)->GetPhysicsController());
        if (sphy)
-               m_sumoObj = sphy->GetSumoObject();
-
+               m_physCtrl = sphy;
+       
 //     m_solidHandle = m_sumoObj->getObjectHandle();
        KX_ClientObjectInfo *client_info = gameobj->getClientInfo();
        client_info->m_gameobject = gameobj;
@@ -150,25 +148,25 @@ void      KX_TouchSensor::ReParent(SCA_IObject* parent)
 
 void KX_TouchSensor::RegisterSumo(KX_TouchEventManager *touchman)
 {
-       if (m_sumoObj)
+       if (m_physCtrl)
        {
-               touchman->GetSumoScene()->requestCollisionCallback(*m_sumoObj);
+               touchman->GetPhysicsEnvironment()->requestCollisionCallback(m_physCtrl);
                // collision
                // Deprecated   
 
        }
 }
 
-DT_Bool    KX_TouchSensor::HandleCollision(void* obj1,void* obj2,const DT_CollData * coll_data)
+bool   KX_TouchSensor::NewHandleCollision(void*object1,void*object2,const PHY_CollData* colldata)
 {
-       // KX_TouchEventManager* toucheventmgr = (KX_TouchEventManager*)m_eventmgr; /*unused*/
+       KX_TouchEventManager* toucheventmgr = (KX_TouchEventManager*)m_eventmgr;
        KX_GameObject* parent = (KX_GameObject*)GetParent();
 
-       // need the mapping from SM_Objects to gameobjects now
+       // need the mapping from PHY_IPhysicsController to gameobjects now
        
-       KX_ClientObjectInfo* client_info = static_cast<KX_ClientObjectInfo*> (obj1 == m_sumoObj
-                                       ((SM_Object*)obj2)->getClientObject() 
-                                       ((SM_Object*)obj1)->getClientObject());
+       KX_ClientObjectInfo* client_info = static_cast<KX_ClientObjectInfo*> (object1 == m_physCtrl
+                                       ((PHY_IPhysicsController*)object2)->getNewClientInfo()
+                                       ((PHY_IPhysicsController*)object1)->getNewClientInfo());
 
        KX_GameObject* gameobj = ( client_info ? 
                        client_info->m_gameobject : 
@@ -336,11 +334,10 @@ PyObject* KX_TouchSensor::PyGetHitObjectList(PyObject* self,
                                 * - this also doesn't work (obviously) for multi-materials... 
                                 */
                                KX_GameObject* gameob = (KX_GameObject*) m_colliders->GetValue(i);
-                               KX_SumoPhysicsController* spc = dynamic_cast<KX_SumoPhysicsController*>(gameob->GetPhysicsController());
-                               SM_Object* smob = spc?spc->GetSumoObject():NULL;
+                               PHY_IPhysicsController* spc = dynamic_cast<PHY_IPhysicsController*>(gameob->GetPhysicsController());
                                
-                               if (smob) {
-                                       KX_ClientObjectInfo* cl_inf = static_cast<KX_ClientObjectInfo*>(smob->getClientObject());
+                               if (spc) {
+                                       KX_ClientObjectInfo* cl_inf = static_cast<KX_ClientObjectInfo*>(spc->getNewClientInfo());
                                        
                                        if (m_touchedpropname == ((char*)cl_inf->m_auxilary_info)) {
                                                newList->Add(m_colliders->GetValue(i)->AddRef());
index 9dd17a5fe83dbdb32ea09420bd52854f40589369..f1a2a26e822be5a5fd9c869ee98e00e25bee014d 100644 (file)
@@ -38,8 +38,7 @@
 #include "SCA_ISensor.h"
 #include "ListValue.h"
 
-#include <SOLID/SOLID.h>
-#include "SM_Scene.h"
+struct PHY_CollData;
 
 #include "KX_ClientObjectInfo.h"
 
@@ -57,10 +56,9 @@ protected:
        bool                                    m_bFindMaterial;
        class SCA_EventManager* m_eventmgr;
        
-       class SM_Object*                m_sumoObj;
-       DT_ObjectHandle                 m_solidHandle;
-       DT_RespTableHandle              m_resptable;
-
+       class PHY_IPhysicsController*   m_physCtrl;
+       class PHY_ResponseTable*                m_responstTable;
+       class PHY_PhysicsController*    m_responsObject;
 
        bool                                    m_bCollision;
        bool                                    m_bTriggered;
@@ -71,7 +69,6 @@ protected:
 public:
        KX_TouchSensor(class SCA_EventManager* eventmgr,
                class KX_GameObject* gameobj,
-               /*class SM_Object* sumoObj,*/
                bool fFindMaterial,
                const STR_String& touchedpropname,
                PyTypeObject* T=&Type) ;
@@ -84,12 +81,12 @@ public:
        
        virtual void RegisterSumo(KX_TouchEventManager* touchman);
 
-       virtual DT_Bool HandleCollision(void* obj1,void* obj2,
-                                                const DT_CollData * coll_data); 
-
+//     virtual DT_Bool HandleCollision(void* obj1,void* obj2,
+//                                              const DT_CollData * coll_data); 
 
-       SM_Object*      GetSumoObject() { return m_sumoObj; };
+       virtual bool    NewHandleCollision(void*obj1,void*obj2,const PHY_CollData* colldata);
 
+       PHY_PhysicsController*  GetPhysicsController() { return m_responsObject;}
   
 
        virtual bool IsPositiveTrigger() {
index 35cfa47700ea48a76f8f67fcd62b6020c05989ae..0407232a9ac35cd9a9696be0882f216f29221a8c 100644 (file)
@@ -26,6 +26,7 @@ source_files = ['KX_WorldIpoController.cpp',
                 'KX_SCA_AddObjectActuator.cpp',
                 'KX_RaySensor.cpp',
                 'KX_RayEventManager.cpp',
+               'KX_RayCast.cpp',
                 'KX_RadarSensor.cpp',
                 'KX_PyMath.cpp',
                 'KX_PythonInit.cpp',
index ec86e510c497a5caf6fdf77ede9055caa1ca7a55..e36aa4750af924ea4001da2747949ee5e64153cb 100644 (file)
@@ -58,6 +58,9 @@ void NG_LoopBackNetworkDeviceInterface::NextFrame()
 {
        // Release reference to the messages while emptying the queue
        while (m_messages[m_currentQueue].size() > 0) {
+#ifdef NAN_NET_DEBUG
+       printf("NG_LBNDI::NextFrame %d '%s'\n", m_currentQueue, m_messages[m_currentQueue][0]->GetSubject().ReadPtr());
+#endif
                // Should do assert(m_events[0]);
                m_messages[m_currentQueue][0]->Release();
                m_messages[m_currentQueue].pop_front();
@@ -75,7 +78,8 @@ STR_String NG_LoopBackNetworkDeviceInterface::GetNetworkVersion()
 void NG_LoopBackNetworkDeviceInterface::SendNetworkMessage(NG_NetworkMessage* nwmsg)
 {
 #ifdef NAN_NET_DEBUG
-       printf("NG_LBNDI::SendNetworkMessage '%s'->'%s' '%s' '%s'\n",
+       printf("NG_LBNDI::SendNetworkMessage %d, '%s'->'%s' '%s' '%s'\n",
+                  1-m_currentQueue,
                   nwmsg->GetDestinationName().ReadPtr(),
                   nwmsg->GetSenderName().ReadPtr(),
                   nwmsg->GetSubject().ReadPtr(),
@@ -102,7 +106,8 @@ vector<NG_NetworkMessage*> NG_LoopBackNetworkDeviceInterface::RetrieveNetworkMes
                messages.push_back(*mesit);
 
 #ifdef NAN_NET_DEBUG
-               printf("NG_LBNDI::RetrieveNetworkMessages '%s'->'%s' '%s' '%s'\n",
+               printf("NG_LBNDI::RetrieveNetworkMessages %d '%s'->'%s' '%s' '%s'\n",
+                       m_currentQueue,
                        (*mesit)->GetDestinationName().ReadPtr(),
                        (*mesit)->GetSenderName().ReadPtr(),
                        (*mesit)->GetSubject().ReadPtr(),
index 3c5ed35e539fc864b887539820817a5294631bb7..dd4819f46e59f3a65c6b8fff24c943cf43ee2216 100644 (file)
@@ -39,6 +39,7 @@ include nan_compile.mk
 CCFLAGS += $(LEVEL_1_CPP_WARNINGS)
 
 CPPFLAGS += -I$(NAN_STRING)/include    
+CPPFLAGS += -I$(NAN_MOTO)/include    
 CPPFLAGS += -I../GameLogic
 CPPFLAGS += -I../../kernel/gen_system
 
index b867791e12d1e47b224c7e74bfd453312bc90695..c66eb3730ac7b7e89183321cc174119c2cd2cdac 100644 (file)
@@ -31,7 +31,7 @@
  * NetworkSceneManagement generic implementation
  */
 #include <stdio.h>
-#include <assert.h>
+#include <MT_assert.h>
 #include <algorithm>
 
 #include "NG_NetworkScene.h"
@@ -199,7 +199,7 @@ vector<NG_NetworkMessage*> NG_NetworkScene::FindMessages(
                // possibly it's there, but maybe not (false hit)
                if (to.IsEmpty()) {
                        // take all messages, and check other fields
-                       assert("objectnames that are empty are not valid, so make it a hobby project :)\n");
+                       MT_assert(!"objectnames that are empty are not valid, so make it a hobby project :)\n");
                } else {
                        //todo: find intersection of messages (that are in other 2 maps)
                        vector<NG_NetworkMessage*>** tolistptr = m_messagesByDestinationName[to];
index 40e3278e9e90ec935436c8455dcbe68f55fea7ea..489bea7a970d8cf6f60984ac2af983bd0d573a05 100755 (executable)
@@ -10,7 +10,8 @@ source_files = ['NG_NetworkMessage.cpp',
 
 ng_network_env.Append (CPPPATH=['.',
                                 '#source/kernel/gen_system',
-                                '#intern/string'
+                                '#intern/string',
+                               '#intern/moto/include'
                                ])
 
 ng_network_env.Library (target='#'+user_options_dict['BUILD_DIR']+'/lib/NG_network', source=source_files)
index 6d4adc961c8f69096e10c0b5ac8a5a359708f3c1..d403d5100fc1a85f0d730e38efd9b8fab753d73e 100644 (file)
@@ -421,6 +421,12 @@ void ODEPhysicsController::getOrientation(float &quatImag0,float &quatImag1,floa
   quatReal=q[3];
 }
 
+void           ODEPhysicsController::getPosition(PHY__Vector3& pos) const
+{
+       m_MotionState->getWorldPosition(pos[0],pos[1],pos[2]);
+
+}
+       
 void ODEPhysicsController::setPosition(float posX,float posY,float posZ)
 {
   if (!m_bPhantom)
index d7d3ba160f776125d05c32e75508ae3d3ae5503c..4f4acb5cd1861a9bc33956ab88385de5f48d3b51 100644 (file)
@@ -62,6 +62,8 @@ public:
        virtual void            getOrientation(float &quatImag0,float &quatImag1,float &quatImag2,float &quatReal);
        virtual void            setOrientation(float quatImag0,float quatImag1,float quatImag2,float quatReal);
        virtual void            setPosition(float posX,float posY,float posZ);
+       virtual void            getPosition(PHY__Vector3&       pos) const;
+       
        virtual void            setScaling(float scaleX,float scaleY,float scaleZ);
        
        // physics methods
@@ -73,6 +75,10 @@ public:
        virtual void            SetActive(bool active){};
        virtual void            SuspendDynamics();
        virtual void            RestoreDynamics();
+       virtual void            resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ)
+       {
+               //todo ?
+       }
 
 
        /**  
@@ -102,9 +108,13 @@ public:
        */
        virtual bool    SynchronizeMotionStates(float time);
 
+       virtual void    calcXform(){}
+       virtual void SetMargin(float margin) {}
+       virtual float GetMargin() const {return 0.f;}
+
                // clientinfo for raycasts for example
-       virtual void*                           getClientInfo() { return m_clientInfo;}
-       virtual void                            setClientInfo(void* clientinfo) {m_clientInfo = clientinfo;};
+       virtual void*                           getNewClientInfo() { return m_clientInfo;}
+       virtual void                            setNewClientInfo(void* clientinfo) {m_clientInfo = clientinfo;};
        void*                                           m_clientInfo;
 
        struct  dxBody*                         GetOdeBodyId() { return m_bodyId; }
index 1316311b881747e4bbb68d1d0d5b07db39498249..54d94351815e493e99015b0a22db232ac5eb8b60 100644 (file)
 ODEPhysicsEnvironment::ODEPhysicsEnvironment()
 {
        m_OdeWorld = dWorldCreate();
-       m_OdeSpace = dHashSpaceCreate();
+       m_OdeSpace = dHashSpaceCreate(0);
        m_OdeContactGroup = dJointGroupCreate (0);
        dWorldSetCFM (m_OdeWorld,1e-5f);
 
        m_JointGroup = dJointGroupCreate(0);
-       
+
+       setFixedTimeStep(true,1.f/60.f);
 }
 
 
@@ -55,19 +56,60 @@ ODEPhysicsEnvironment::~ODEPhysicsEnvironment()
        dWorldDestroy (m_OdeWorld);
 }
 
-bool ODEPhysicsEnvironment::proceed(double timeStep)
+
+
+void           ODEPhysicsEnvironment::setFixedTimeStep(bool useFixedTimeStep,float fixedTimeStep)
 {
-       // ode collision update
-       dSpaceCollide (m_OdeSpace,this,&ODEPhysicsEnvironment::OdeNearCallback);
+       m_useFixedTimeStep = useFixedTimeStep;
 
-       int m_odeContacts = GetNumOdeContacts();
-       
-       //physics integrator + resolver update
-       dWorldStep (m_OdeWorld,timeStep);
-       
-       //clear collision points
-       this->ClearOdeContactGroup();
-       
+       if (useFixedTimeStep)
+       {
+               m_fixedTimeStep = fixedTimeStep;
+       } else
+       {
+               m_fixedTimeStep = 0.f;
+       }
+       m_currentTime = 0.f;
+
+       //todo:implement fixed timestepping
+
+}
+float          ODEPhysicsEnvironment::getFixedTimeStep()
+{
+       return m_fixedTimeStep;
+}
+
+
+
+bool           ODEPhysicsEnvironment::proceedDeltaTime(double  curTime,float timeStep1)
+{
+
+       float deltaTime = timeStep1;
+       int     numSteps = 1;
+
+       if (m_useFixedTimeStep)
+       {
+               m_currentTime += timeStep1;             
+               // equal to subSampling (might be a little smaller).
+               numSteps = (int)(m_currentTime / m_fixedTimeStep);
+               m_currentTime -= m_fixedTimeStep * (float)numSteps;
+               deltaTime = m_fixedTimeStep;
+               //todo: experiment by smoothing the remaining time over the substeps
+       }
+
+       for (int i=0;i<numSteps;i++)
+       {
+               // ode collision update
+               dSpaceCollide (m_OdeSpace,this,&ODEPhysicsEnvironment::OdeNearCallback);
+
+               int m_odeContacts = GetNumOdeContacts();
+               
+               //physics integrator + resolver update
+               dWorldStep (m_OdeWorld,deltaTime);
+               
+               //clear collision points
+               this->ClearOdeContactGroup();
+       }
        return true;
 }
 
@@ -168,9 +210,11 @@ void               ODEPhysicsEnvironment::removeConstraint(int constraintid)
        }
 }
 
-PHY_IPhysicsController* ODEPhysicsEnvironment::rayTest(void* ignoreClient,float fromX,float fromY,float fromZ, float toX,float toY,float toZ, 
+PHY_IPhysicsController* ODEPhysicsEnvironment::rayTest(PHY_IPhysicsController* ignoreClient,float fromX,float fromY,float fromZ, float toX,float toY,float toZ, 
                                                                        float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ)
 {
+
+       //m_OdeWorld
        //collision detection / raytesting
        return NULL;
 }
index 828e3ff3269058a9b5715b01b3e9b1531f71ad69..2214d642d7b858aaff229a3913aee8bd6c4106a6 100644 (file)
 class ODEPhysicsEnvironment : public PHY_IPhysicsEnvironment
 {
 
+       bool    m_useFixedTimeStep;
+       float   m_fixedTimeStep;
+       float   m_currentTime;
+
 public:
        ODEPhysicsEnvironment();
        virtual         ~ODEPhysicsEnvironment();
+       virtual void            beginFrame() {}
+       virtual void            endFrame() {}
+
+
 // Perform an integration step of duration 'timeStep'.
-       virtual bool            proceed(double  timeStep);
+       virtual bool            proceedDeltaTime(double  curTime,float timeStep);
+       virtual void            setFixedTimeStep(bool useFixedTimeStep,float fixedTimeStep);
+       virtual float           getFixedTimeStep();
+
        virtual void            setGravity(float x,float y,float z);
        virtual int                     createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,
                        float pivotX,float pivotY,float pivotZ,
                        float axisX,float axisY,float axisZ);
 
        virtual void            removeConstraint(int constraintid);
-       virtual PHY_IPhysicsController* rayTest(void* ignoreClient,float fromX,float fromY,float fromZ, float toX,float toY,float toZ, 
+       virtual PHY_IPhysicsController* rayTest(PHY_IPhysicsController* ignoreClient,float fromX,float fromY,float fromZ, float toX,float toY,float toZ, 
                                                                        float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ);
 
+
+       //gamelogic callbacks
+       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 PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) {return 0;}
+       virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight) { return 0;}
+
+
+
        struct dxWorld* GetOdeWorld() { return m_OdeWorld;      };
        struct  dxSpace* GetOdeSpace() { return m_OdeSpace;};
 
index d0abd6e38595d3d1cbff2c4165c15e68b1321fc1..a640acd9b3d66d489472604e27d7744bca820dd2 100644 (file)
@@ -58,7 +58,9 @@ void DummyPhysicsEnvironment::endFrame()
        // end of logic frame: clear forces
 }
 
-bool DummyPhysicsEnvironment::proceed(double timeStep)
+
+
+bool           DummyPhysicsEnvironment::proceedDeltaTime(double  curTime,float timeStep)
 {
        //step physics simulation, typically perform
        
@@ -68,6 +70,17 @@ bool DummyPhysicsEnvironment::proceed(double timeStep)
        // return true if an update was done.
        return true;
 }
+void           DummyPhysicsEnvironment::setFixedTimeStep(bool useFixedTimeStep,float fixedTimeStep)
+{
+}
+float          DummyPhysicsEnvironment::getFixedTimeStep()
+{
+       return 0.f;
+}
+
+
+
 
 void DummyPhysicsEnvironment::setGravity(float x,float y,float z)
 {
@@ -95,7 +108,7 @@ void         DummyPhysicsEnvironment::removeConstraint(int constraintid)
        }
 }
 
-PHY_IPhysicsController* DummyPhysicsEnvironment::rayTest(void* ignoreClient,float fromX,float fromY,float fromZ, float toX,float toY,float toZ, 
+PHY_IPhysicsController* DummyPhysicsEnvironment::rayTest(PHY_IPhysicsController* ignoreClient,float fromX,float fromY,float fromZ, float toX,float toY,float toZ, 
                                                                        float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ)
 {
        //collision detection / raytesting
index 65f421410458d9c6c4bd5088daa1fd04b21f8277..fde27e822d6fe37d7ad08c8602a0694198794182 100644 (file)
@@ -51,7 +51,10 @@ public:
        virtual void            beginFrame();
        virtual void            endFrame();
 // Perform an integration step of duration 'timeStep'.
-       virtual bool            proceed (double timeStep);
+       virtual bool            proceedDeltaTime(double  curTime,float timeStep);
+       virtual void            setFixedTimeStep(bool useFixedTimeStep,float fixedTimeStep);
+       virtual float           getFixedTimeStep();
+
        virtual void            setGravity(float x,float y,float z);
 
        virtual int                     createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,
@@ -59,10 +62,21 @@ public:
                        float axisX,float axisY,float axisZ);
 
        virtual void            removeConstraint(int constraintid);
-       virtual PHY_IPhysicsController* rayTest(void* ignoreClient, float fromX,float fromY,float fromZ, float toX,float toY,float toZ, 
+       virtual PHY_IPhysicsController* rayTest(PHY_IPhysicsController* ignoreClient, float fromX,float fromY,float fromZ, float toX,float toY,float toZ, 
                                                                        float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ);
 
 
+       //gamelogic callbacks
+               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 PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) {return 0;}
+               virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight) { return 0;}
+
+
 };
 
 #endif //_DUMMYPHYSICSENVIRONMENT
index 07eb5a7637fa8bc3d6e461324400681a4f803e50..1911e186a1c7d09485d46dd85f6b970a7f9dbc8d 100644 (file)
@@ -264,7 +264,13 @@ public:
        
        SM_ClientObject *getClientObject() { return m_client_object; }
        void setClientObject(SM_ClientObject *client_object) { m_client_object = client_object; }
-       
+       void    setPhysicsClientObject(void* physicsClientObject)
+       {
+               m_physicsClientObject = physicsClientObject;
+       }
+       void*   getPhysicsClientObject() {
+               return m_physicsClientObject;
+       }
        void relax();
        
        SM_MotionState &getCurrentFrame();
@@ -325,6 +331,8 @@ private:
        // on an SM_Object, there must be a way that the SM_Object client
        // can identify it's clientdata after a collision
        SM_ClientObject        *m_client_object;
+       
+       void*                                   m_physicsClientObject;
 
        DT_ShapeHandle          m_shape;                 // Shape for collision detection
 
index ab1db7c794191d8236fce3f257eaf12380b1e852..fe1ac9becd91d4e94f95a7f91af7115e42709574 100644 (file)
@@ -42,6 +42,8 @@
 #pragma warning( disable : 4786 )     
 #endif
 
+#include "MT_assert.h"
+
 #include "SM_Object.h"
 #include "SM_Scene.h"
 #include "SM_FhObject.h"
@@ -147,7 +149,7 @@ SM_Object::SM_Object(
        
        m_dynamicParent(dynamicParent),
        m_client_object(0),
-       
+       m_physicsClientObject(0),
        m_shape(shape),
        m_materialProps(materialProps),
        m_materialPropsBackup(0),
@@ -385,7 +387,7 @@ void SM_Object::dynamicCollision(const MT_Point3 &local2,
 
                        // I guess the GEN_max is not necessary, so let's check it
 
-                       assert(impulse >= 0.0);
+                       MT_assert(impulse >= 0.0);
 
                        /**
                         * Here's the trick. We compute the impulse to make the
@@ -481,7 +483,7 @@ DT_Bool SM_Object::boing(
        if (dist < MT_EPSILON)
                return DT_CONTINUE;
                
-       // Now we are definately intersecting.
+       // Now we are definitely intersecting.
 
        // Set callbacks for game engine.
        if ((obj1->getClientObject() && obj1->getClientObject()->hasCollisionCallback()) || 
@@ -595,7 +597,7 @@ void SM_Object::relax(void)
 SM_Object::SM_Object() :
        m_dynamicParent(0),
        m_client_object(0),
-       
+       m_physicsClientObject(0),
        m_shape(0),
        m_materialProps(0),
        m_materialPropsBackup(0),
@@ -868,7 +870,7 @@ SM_Object::
 setOrientation(
        const MT_Quaternion& orn
 ){
-       assert(!orn.fuzzyZero());
+       MT_assert(!orn.fuzzyZero());
        m_kinematic = true;
        getNextFrame().setOrientation(orn);
        endFrame();
index fdd8079b24185f4ce8979fd9292e81fac28eb9ce..081a2fb979463e91823a9f75ccca905e2cb61a1a 100644 (file)
@@ -140,7 +140,8 @@ void SM_Scene::requestCollisionCallback(SM_Object &object)
 //     DT_SetResponseClass(m_fixRespTable, object.getObjectHandle(), m_fixResponseClass[OBJECT_RESPONSE]);
 }
 
-void SM_Scene::remove(SM_Object& object) {     
+void SM_Scene::remove(SM_Object& object) {
+       //std::cout << "SM_Scene::remove this =" << this << "object = " << &object << std::endl;
        T_ObjectList::iterator i =
                std::find(m_objectList.begin(), m_objectList.end(), &object);
        if (!(i == m_objectList.end()))
@@ -358,6 +359,7 @@ DT_Bool SM_Scene::boing(
 
 SM_Scene::~SM_Scene()
 { 
+       //std::cout << "SM_Scene::~ SM_Scene(): destroy " << this << std::endl;
 //     if (m_objectList.begin() != m_objectList.end()) 
 //             std::cout << "SM_Scene::~SM_Scene: There are still objects in the Sumo scene!" << std::endl;
        for (T_ObjectList::iterator it = m_objectList.begin() ; it != m_objectList.end() ; it++)
index 46eeef264def978088ff339fd89aaec69ae9e167..5ff47b475d1ec8bb842168301243fc00e47512c0 100644 (file)
@@ -35,6 +35,7 @@
 #include "SM_Object.h"
 #include "MT_Quaternion.h"
 
+
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
@@ -54,7 +55,16 @@ SumoPhysicsController::SumoPhysicsController(
 {
        if (m_sumoObj)
        {
-               //m_sumoObj->setClientObject(this);
+
+               PHY__Vector3 pos1;
+               getPosition(pos1);
+               MT_Point3 pos(pos1);
+               
+               //temp debugging check
+               //assert(pos.length() < 100000.f);
+
+               //need this to do the upcast after the solid/sumo collision callback
+               m_sumoObj->setPhysicsClientObject(this);
                //if it is a dyna, register for a callback
                m_sumoObj->registerCallback(*this);
        }
@@ -105,8 +115,25 @@ void SumoPhysicsController::GetWorldOrientation(MT_Matrix3x3& mat)
 
 }
 
+void SumoPhysicsController::getPosition(PHY__Vector3&  pos) const
+{
+       assert(m_sumoObj);
+
+       pos[0] = m_sumoObj->getPosition()[0];
+       pos[1] = m_sumoObj->getPosition()[0];
+       pos[2] = m_sumoObj->getPosition()[0];
+
+       //m_MotionState->getWorldPosition(pos[0],pos[1],pos[2]);
+}
+
 void SumoPhysicsController::GetWorldPosition(MT_Point3& pos)
 {
+//     assert(m_sumoObj);
+
+//     pos[0] = m_sumoObj->getPosition()[0];
+//     pos[1] = m_sumoObj->getPosition()[0];
+//     pos[2] = m_sumoObj->getPosition()[0];
+
        float worldpos[3];
        m_MotionState->getWorldPosition(worldpos[0],worldpos[1],worldpos[2]);
        pos[0]=worldpos[0];
@@ -237,16 +264,15 @@ void              SumoPhysicsController::SetLinearVelocity(float lin_velX,float lin_velY,flo
        }
 }
 
-void SumoPhysicsController::resolveCombinedVelocities(
-               const MT_Vector3 & lin_vel,
-               const MT_Vector3 & ang_vel
-       )
+void           SumoPhysicsController::resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ)
 {
        if (m_sumoObj)
-               m_sumoObj->resolveCombinedVelocities(lin_vel, ang_vel);
+               m_sumoObj->resolveCombinedVelocities(MT_Vector3(linvelX,linvelY,linvelZ),MT_Vector3(angVelX,angVelY,angVelZ));
 }
 
 
+
+
 void           SumoPhysicsController::applyImpulse(float attachX,float attachY,float attachZ, float impulseX,float impulseY,float impulseZ)
 {
        if (m_sumoObj)
@@ -385,9 +411,11 @@ void       SumoPhysicsController::WriteMotionStateToDynamics(bool)
 
 void SumoPhysicsController::do_me()
 {
+       MT_assert(m_sumoObj);
        const MT_Point3& pos = m_sumoObj->getPosition();
        const MT_Quaternion& orn = m_sumoObj->getOrientation();
 
+       MT_assert(m_MotionState);
        m_MotionState->setWorldPosition(pos[0],pos[1],pos[2]);
        m_MotionState->setWorldOrientation(orn[0],orn[1],orn[2],orn[3]);
 }
@@ -418,4 +446,52 @@ void       SumoPhysicsController::setSumoTransform(bool nondynaonly)
                        m_sumoObj->calcXform();
                }
        }
+}
+
+
+       // clientinfo for raycasts for example
+void*                          SumoPhysicsController::getNewClientInfo()
+{
+       if (m_sumoObj)
+               return m_sumoObj->getClientObject();
+       return 0;
+
+}
+void                           SumoPhysicsController::setNewClientInfo(void* clientinfo)
+{
+       if (m_sumoObj)
+       {
+               SM_ClientObject* clOb = static_cast<SM_ClientObject*> (clientinfo);
+               m_sumoObj->setClientObject(clOb);
+       }
+
+}
+
+void   SumoPhysicsController::calcXform()
+{
+       if (m_sumoObj)
+               m_sumoObj->calcXform();
+}
+
+void SumoPhysicsController::SetMargin(float margin) 
+{
+       if (m_sumoObj)
+               m_sumoObj->setMargin(margin);
+}
+
+float SumoPhysicsController::GetMargin() const
+{
+       if (m_sumoObj)
+               m_sumoObj->getMargin();
+       return 0.f;
+}
+
+float SumoPhysicsController::GetRadius() const 
+{
+       if (m_sumoObj && m_sumoObj->getShapeProps())
+       {
+               return m_sumoObj->getShapeProps()->m_radius;
+       }
+       return 0.f;
+
 }
index 26ff52600f342d63d4d076fd3e813a06c5a20b5a..349c8cc24a6e7c8d7af62761970a1ae526b947b6 100644 (file)
@@ -72,6 +72,8 @@ public:
        virtual void            getOrientation(float &quatImag0,float &quatImag1,float &quatImag2,float &quatReal);
        virtual void            setOrientation(float quatImag0,float quatImag1,float quatImag2,float quatReal);
        virtual void            setPosition(float posX,float posY,float posZ);
+       virtual void            getPosition(PHY__Vector3&       pos) const;
+
        virtual void            setScaling(float scaleX,float scaleY,float scaleZ);
        /*@}*/
        
@@ -83,7 +85,7 @@ public:
        virtual void            ApplyForce(float forceX,float forceY,float forceZ,bool local);
        virtual void            SetAngularVelocity(float ang_velX,float ang_velY,float ang_velZ,bool local);
        virtual void            SetLinearVelocity(float lin_velX,float lin_velY,float lin_velZ,bool local);
-       virtual void            resolveCombinedVelocities(const MT_Vector3 & lin_vel, const MT_Vector3 & ang_vel );
+       virtual void            resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ);
        virtual void            applyImpulse(float attachX,float attachY,float attachZ, float impulseX,float impulseY,float impulseZ);
        virtual void            SetActive(bool active){};
        virtual void            SuspendDynamics();
@@ -117,10 +119,16 @@ public:
         */
        virtual bool    SynchronizeMotionStates(float time);
 
-       // clientinfo for raycasts for example
-       virtual void*                           getClientInfo() { return m_clientInfo;}
-       virtual void                            setClientInfo(void* clientinfo) {m_clientInfo = clientinfo;};
+       virtual void    calcXform();
+       virtual void SetMargin(float margin) ;
+       virtual float GetMargin() const;
+       virtual float GetRadius() const ;
+
 
+       // clientinfo for raycasts for example
+       virtual void*                           getNewClientInfo();
+       virtual void                            setNewClientInfo(void* clientinfo);
+       
        float   getFriction() { return m_friction;}
        float   getRestitution() { return m_restitution;}
 
@@ -173,8 +181,6 @@ private:
 
        class   PHY_IMotionState*       m_MotionState;
        
-       void*                           m_clientInfo;
-
        
 };
 
index f035bfb4cf2c188d3f05ac99bcdb958498937c58..2b29b2602a80281449957a21572786be6829fff0 100644 (file)
 #include "PHY_IMotionState.h"
 #include "SumoPhysicsController.h"
 #include "SM_Scene.h"
+#include "SumoPHYCallbackBridge.h"
+#include <SOLID/SOLID.h>
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 
-MT_Scalar SumoPhysicsEnvironment::PhysicsTicRate = 60.0;
 
 SumoPhysicsEnvironment::SumoPhysicsEnvironment()
 {
+       m_fixedTimeStep = 1.f/60.f;
+       m_useFixedTimeStep = true;
+       m_currentTime = 0.f;
+
        m_sumoScene = new SM_Scene();
 }
 
@@ -52,15 +57,7 @@ SumoPhysicsEnvironment::~SumoPhysicsEnvironment()
        delete m_sumoScene;
 }
 
-void SumoPhysicsEnvironment::setTicRate(MT_Scalar ticrate)
-{
-       PhysicsTicRate = ticrate;
-}
 
-MT_Scalar SumoPhysicsEnvironment::getTicRate()
-{
-       return PhysicsTicRate;
-}
 
 void SumoPhysicsEnvironment::beginFrame()
 {
@@ -72,9 +69,42 @@ void SumoPhysicsEnvironment::endFrame()
        m_sumoScene->endFrame();
 }
 
-bool SumoPhysicsEnvironment::proceed(double curtime)
+void           SumoPhysicsEnvironment::setFixedTimeStep(bool useFixedTimeStep,float fixedTimeStep)
 {
-       return m_sumoScene->proceed(curtime, PhysicsTicRate);
+       m_useFixedTimeStep = useFixedTimeStep;
+       if (m_useFixedTimeStep)
+       {
+               m_fixedTimeStep = fixedTimeStep;
+       } else
+       {
+               m_fixedTimeStep  = 0.f;
+       }
+       //reset current time ?
+       m_currentTime = 0.f;
+}
+float          SumoPhysicsEnvironment::getFixedTimeStep()
+{
+       return m_fixedTimeStep;
+}
+
+
+bool           SumoPhysicsEnvironment::proceedDeltaTime(double  curTime,float timeStep)
+{
+       
+       bool result = false;
+       if (m_useFixedTimeStep)
+       {
+               m_currentTime += timeStep;
+               float ticrate = 1.f/m_fixedTimeStep;
+
+               result = m_sumoScene->proceed(curTime, ticrate);
+       } else
+       {
+               m_currentTime += timeStep;
+               float ticrate = 1.f/timeStep;
+               result = m_sumoScene->proceed(m_currentTime, timeStep);
+       }
+       return result;
 }
 
 void SumoPhysicsEnvironment::setGravity(float x,float y,float z)
@@ -100,17 +130,28 @@ void SumoPhysicsEnvironment::removeConstraint(int constraintid)
        }
 }
 
-PHY_IPhysicsController* SumoPhysicsEnvironment::rayTest(void* ignoreClient
+PHY_IPhysicsController* SumoPhysicsEnvironment::rayTest(PHY_IPhysicsController* ignoreClientCtrl
        float fromX,float fromY,float fromZ, 
        float toX,float toY,float toZ, 
        float& hitX,float& hitY,float& hitZ,
        float& normalX,float& normalY,float& normalZ)
 {
+       SumoPhysicsController* ignoreCtr = static_cast<SumoPhysicsController*> (ignoreClientCtrl);
+
        //collision detection / raytesting
        MT_Point3 hit, normal;
-       /* FIXME: Return type is not a PHY_IPhysicsController */
-       PHY_IPhysicsController *ret = (PHY_IPhysicsController *) m_sumoScene->rayTest(ignoreClient,MT_Point3(fromX, fromY, fromZ),MT_Point3(toX, toY, toZ), hit, normal);
-       
+       PHY_IPhysicsController *ret = 0;
+
+       SM_Object* sm_ignore = 0;
+       if (ignoreCtr)
+               sm_ignore = ignoreCtr->GetSumoObject();
+
+
+       SM_Object* smOb = m_sumoScene->rayTest(sm_ignore,MT_Point3(fromX, fromY, fromZ),MT_Point3(toX, toY, toZ), hit, normal);
+       if (smOb)
+       {
+               ret = (PHY_IPhysicsController *) smOb->getPhysicsClientObject();
+       }
        hitX = hit[0];
        hitY = hit[1];
        hitZ = hit[2];
@@ -119,9 +160,101 @@ PHY_IPhysicsController* SumoPhysicsEnvironment::rayTest(void* ignoreClient,
        normalY = normal[1];
        normalZ = normal[2];
        
-       assert(false);
-       
        return ret;
 }
+//gamelogic callbacks
+void SumoPhysicsEnvironment::addSensor(PHY_IPhysicsController* ctrl)
+{
+       SumoPhysicsController* smctrl = dynamic_cast<SumoPhysicsController*>(ctrl);
+       SM_Object* smObject = smctrl->GetSumoObject();
+       assert(smObject);
+       if (smObject)
+       {
+               m_sumoScene->addSensor(*smObject);
+       }
+}
+void SumoPhysicsEnvironment::removeSensor(PHY_IPhysicsController* ctrl)
+{
+       SumoPhysicsController* smctrl = dynamic_cast<SumoPhysicsController*>(ctrl);
+       SM_Object* smObject = smctrl->GetSumoObject();
+       assert(smObject);
+       if (smObject)
+       {
+               m_sumoScene->remove(*smObject);
+       }
+}
+
+
+void SumoPhysicsEnvironment::addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user)
+{
+       
+       int sumoRespClass = 0;
+
+       //map PHY_ convention into SM_ convention
+       switch (response_class)
+       {
+       case    PHY_FH_RESPONSE:
+                       sumoRespClass = FH_RESPONSE; 
+               break;
+       case PHY_SENSOR_RESPONSE:
+               sumoRespClass = SENSOR_RESPONSE;
+               break;
+       case PHY_CAMERA_RESPONSE:
+               sumoRespClass =CAMERA_RESPONSE;
+               break;
+       case PHY_OBJECT_RESPONSE:
+               sumoRespClass = OBJECT_RESPONSE;
+               break;
+       case PHY_STATIC_RESPONSE:
+               sumoRespClass = PHY_STATIC_RESPONSE;
+               break;
+       default:
+               assert(0);
+               return;
+       }
+
+       SumoPHYCallbackBridge* bridge = new SumoPHYCallbackBridge(user,callback);
+
+       m_sumoScene->addTouchCallback(sumoRespClass,SumoPHYCallbackBridge::StaticSolidToPHYCallback,bridge);
+}
+void SumoPhysicsEnvironment::requestCollisionCallback(PHY_IPhysicsController* ctrl)
+{
+       SumoPhysicsController* smctrl = dynamic_cast<SumoPhysicsController*>(ctrl);
+       MT_assert(smctrl);
+       SM_Object* smObject = smctrl->GetSumoObject();
+       MT_assert(smObject);
+       if (smObject)
+       {
+               //assert(smObject->getPhysicsClientObject() == ctrl);
+               smObject->setPhysicsClientObject(ctrl);
+       
+               m_sumoScene->requestCollisionCallback(*smObject);
+       }
+}
+PHY_IPhysicsController*        SumoPhysicsEnvironment::CreateSphereController(float radius,const PHY__Vector3& position)
+{
+       DT_ShapeHandle shape    =       DT_NewSphere(0.0);
+       SM_Object* ob = new SM_Object(shape,0,0,0);     
+       ob->setPosition(MT_Point3(position));
+       //testing
+       MT_Quaternion rotquatje(MT_Vector3(0,0,1),MT_radians(90));              
+       ob->setOrientation(rotquatje);
+
+       PHY_IPhysicsController* ctrl = new SumoPhysicsController(m_sumoScene,ob,0,false);
+       ctrl->SetMargin(radius);
+       return ctrl;
+}
+PHY_IPhysicsController* SumoPhysicsEnvironment::CreateConeController(float coneradius,float coneheight)
+{
+       DT_ShapeHandle shape    =       DT_NewCone(coneradius,coneheight);
+       SM_Object* ob = new SM_Object(shape,0,0,0);     
+       ob->setPosition(MT_Point3(0.f,0.f,0.f));
+       MT_Quaternion rotquatje(MT_Vector3(0,0,1),MT_radians(90));              
+       ob->setOrientation(rotquatje);
+
+       PHY_IPhysicsController* ctrl = new SumoPhysicsController(m_sumoScene,ob,0,false);
+
+       return ctrl;
+}
 
 
index aba341360f994e7d909254f39bd3f965ed697e96..62672d8ba489a9f411c2377a8613d499cc6196b9 100644 (file)
@@ -35,7 +35,8 @@
 #include "MT_Scalar.h"
 
 #include "PHY_IPhysicsEnvironment.h"
-
+class SumoPHYCallbackBridge;
+#include <vector>
 /**
 *      Physics Environment takes care of stepping the simulation and is a container for physics entities (rigidbodies,constraints, materials etc.)
 *      A derived class may be able to 'construct' entities by loading and/or converting
@@ -44,6 +45,11 @@ class SumoPhysicsEnvironment : public PHY_IPhysicsEnvironment
 {
 
        class SM_Scene* m_sumoScene;
+       float   m_currentTime;
+       float   m_fixedTimeStep;
+       bool    m_useFixedTimeStep;
+
+       std::vector<SumoPHYCallbackBridge*>     m_callbacks;
 
 public:
        SumoPhysicsEnvironment();
@@ -51,19 +57,29 @@ public:
        virtual void            beginFrame();
        virtual void            endFrame();
 // Perform an integration step of duration 'timeStep'.
-       virtual bool            proceed(double curtime);
+       virtual bool            proceedDeltaTime(double  curTime,float timeStep);
+       virtual void            setFixedTimeStep(bool useFixedTimeStep,float fixedTimeStep);
+       virtual float           getFixedTimeStep();
+
        virtual void            setGravity(float x,float y,float z);
        virtual int             createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,
                        float pivotX,float pivotY,float pivotZ,
                        float axisX,float axisY,float axisZ);
 
        virtual void            removeConstraint(int constraintid);
-       virtual PHY_IPhysicsController* rayTest(void* ignoreClient,float fromX,float fromY,float fromZ, float toX,float toY,float toZ, 
+       virtual PHY_IPhysicsController* rayTest(PHY_IPhysicsController* ignoreClient,float fromX,float fromY,float fromZ, float toX,float toY,float toZ, 
                                                                        float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ);
 
-       static void setTicRate(MT_Scalar ticrate);
-       static MT_Scalar getTicRate();
-       // sumo specific
+       
+       //gamelogic callbacks
+       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 PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position);
+       virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight);
+
+
        SM_Scene* GetSumoScene()
        {
                return m_sumoScene;
index 336e29e827a84befa41bc2386e675cec9bec4907..f800a5494cb2eb57e9f5408bb16f835d0d3175a4 100644 (file)
@@ -42,6 +42,54 @@ typedef enum PHY_ScalarType {
        PHY_FIXEDPOINT88
 } PHY_ScalarType;
 
+class  PHY_ResponseTable;
+
+class PHY_Shape;
+
+struct PHY__Vector3
+{
+       float   m_vec[4];
+       operator const float* () const 
+       { 
+               return &m_vec[0];
+       }       
+       operator float* () 
+       { 
+               return &m_vec[0];
+       }       
+};
+//typedef      float   PHY__Vector3[4];
+
+typedef enum
+{
+       PHY_FH_RESPONSE,
+       PHY_SENSOR_RESPONSE,            /* Touch Sensors */
+       PHY_CAMERA_RESPONSE,    /* Visibility Culling */
+       PHY_OBJECT_RESPONSE,    /* Object Dynamic Geometry Response */
+       PHY_STATIC_RESPONSE,    /* Static Geometry Response */
+       
+       PHY_NUM_RESPONSE
+};
+
+       typedef struct PHY_CollData {
+               PHY__Vector3 m_point1;               /* Point in object1 in world coordinates */ 
+               PHY__Vector3 m_point2;               /* Point in object2 in world coordinates */
+               PHY__Vector3 m_normal;               /* point2 - point1 */ 
+       } PHY_CollData;
+
+/* A response callback is called by SOLID for each pair of collding objects. 'client-data'
+   is a pointer to an arbitrary structure in the client application. The client objects are
+   pointers to structures in the client application associated with the coliding objects.
+   'coll_data' is the collision data computed by SOLID.
+*/
+
+       typedef bool (*PHY_ResponseCallback)(void *client_data,
+                                                                                  void *client_object1,
+                                                                                  void *client_object2,
+                                                                                  const PHY_CollData *coll_data);
+               
+
+
 /// PHY_PhysicsType enumerates all possible Physics Entities.
 /// It is mainly used to create/add Physics Objects
 
index f517abc54ffe143ac2b3f0ef63a08aafdb6a29ff..cdf203ac17e626ca3de59e3a314e891560a4a20c 100644 (file)
@@ -32,7 +32,7 @@
 #ifndef PHY_IPHYSICSCONTROLLER_H
 #define PHY_IPHYSICSCONTROLLER_H
 
-#include "MT_Vector3.h"
+#include "PHY_DynamicTypes.h"
 
 /**
        PHY_IPhysicsController is the abstract simplified Interface to a physical object.
@@ -65,6 +65,7 @@ class PHY_IPhysicsController
                virtual void            getOrientation(float &quatImag0,float &quatImag1,float &quatImag2,float &quatReal)=0;
                virtual void            setOrientation(float quatImag0,float quatImag1,float quatImag2,float quatReal)=0;
                virtual void            setPosition(float posX,float posY,float posZ)=0;
+               virtual void            getPosition(PHY__Vector3&       pos) const=0;
                virtual void            setScaling(float scaleX,float scaleY,float scaleZ)=0;
                
                // physics methods
@@ -72,7 +73,8 @@ class PHY_IPhysicsController
                virtual void            ApplyForce(float forceX,float forceY,float forceZ,bool local)=0;
                virtual void            SetAngularVelocity(float ang_velX,float ang_velY,float ang_velZ,bool local)=0;
                virtual void            SetLinearVelocity(float lin_velX,float lin_velY,float lin_velZ,bool local)=0;
-               virtual void            resolveCombinedVelocities(const MT_Vector3 & lin_vel, const MT_Vector3 & ang_vel ) = 0;
+               virtual void            resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ) = 0;
+
                virtual void            applyImpulse(float attachX,float attachY,float attachZ, float impulseX,float impulseY,float impulseZ)=0;
                virtual void            SetActive(bool active)=0;
 
@@ -85,8 +87,16 @@ class PHY_IPhysicsController
                virtual void            setRigidBody(bool rigid)=0;
 
                // clientinfo for raycasts for example
-               virtual void*                           getClientInfo()=0;
-               virtual void                            setClientInfo(void* clientinfo)=0;
+               virtual void*                           getNewClientInfo()=0;
+               virtual void                            setNewClientInfo(void* clientinfo)=0;
+               virtual PHY_IPhysicsController* GetReplica() {return 0;}
+
+               virtual void    calcXform() =0;
+               virtual void SetMargin(float margin) =0;
+               virtual float GetMargin() const=0;
+               virtual float GetRadius() const { return 0.f;}
+               PHY__Vector3    GetWorldPosition(PHY__Vector3& localpos);
+
 };
 
 #endif //PHY_IPHYSICSCONTROLLER_H
index 0fdac35f514c729fe61118255ad478d1a4321b40..2ffcf80a62b4482a1aaf7f04d2d8cbcb6774b9f8 100644 (file)
@@ -46,7 +46,12 @@ class PHY_IPhysicsEnvironment
                virtual void            beginFrame() = 0;
                virtual void            endFrame() = 0;
                /// Perform an integration step of duration 'timeStep'.
-               virtual bool            proceed(double  timeStep)=0;
+               virtual bool            proceedDeltaTime(double curTime,float timeStep)=0;
+               virtual void            setFixedTimeStep(bool useFixedTimeStep,float fixedTimeStep)=0;
+               //returns 0.f if no fixed timestep is used
+               virtual float           getFixedTimeStep()=0;
+
+
                virtual void            setGravity(float x,float y,float z)=0;
 
                virtual int                     createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,
@@ -54,8 +59,19 @@ class PHY_IPhysicsEnvironment
                        float axisX,float axisY,float axisZ)=0;
                virtual void            removeConstraint(int constraintid)=0;
 
-               virtual PHY_IPhysicsController* rayTest(void* ignoreClient, float fromX,float fromY,float fromZ, float toX,float toY,float toZ, 
+               virtual PHY_IPhysicsController* rayTest(PHY_IPhysicsController* ignoreClient, float fromX,float fromY,float fromZ, float toX,float toY,float toZ, 
                                                                                float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ)=0;
+
+
+               //Methods for gamelogic collision/physics callbacks
+               //todo:
+               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 PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) =0;
+               virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight)=0;
+               
 };
 
 #endif //_IPHYSICSENVIRONMENT
index c86817a40f14654488c8cf6161f3619c024fad49..cfc4257f95d2f0c5f7bbe9c28e49e28463753d42 100644 (file)
@@ -120,7 +120,7 @@ class KX_PolygonMaterial:
                                        print "Shader failed to validate"
                                        return
                                
-                       def Activate(self, rasty, cachingInfo, mat):
+                       def activate(self, rasty, cachingInfo, mat):
                                self.pass_no+=1
                                if (self.pass_no == 1):
                                        glDisable(GL_COLOR_MATERIAL)
@@ -246,7 +246,7 @@ class KX_PolygonMaterial:
                Example::
                        class PyMaterial:
                                def __init__(self):
-                                       self.pass_no = 0
+                                       self.pass_no = -1
                                
                                def activate(self, rasty, cachingInfo, material):
                                        # Activate the material here.
@@ -262,13 +262,14 @@ class KX_PolygonMaterial:
                                        #          was added to
                                        
                                        # default material properties:
+                                       self.pass_no += 1
                                        if self.pass_no == 0:
                                                material.activate(rasty, cachingInfo)
-                                               self.pass_no = 1
                                                # Return True to do this pass
                                                return True
                                        
-                                       self.pass_no = 0
+                                       # clean up and return False to finish.
+                                       self.pass_no = -1
                                        return False
                        
                        # Create a new Python Material and pass it to the renderer.