Revision: 29481
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29481
Author:   nicks
Date:     2010-06-16 02:23:24 +0200 (Wed, 16 Jun 2010)

Log Message:
-----------
- registration obstacle in game object
- creation obstacle on object replication (including navmesh object)
- creation object transform for navigation mesh directly from blender object 
instead of using SGNode world transform (because SGNode doesn't exists yet when 
building navmesh  on ProcessReplica)

Modified Paths:
--------------
    
branches/soc-2010-nicks/source/gameengine/Converter/BL_BlenderDataConversion.cpp
    branches/soc-2010-nicks/source/gameengine/Ketsji/KX_GameObject.cpp
    branches/soc-2010-nicks/source/gameengine/Ketsji/KX_GameObject.h
    branches/soc-2010-nicks/source/gameengine/Ketsji/KX_NavMeshObject.cpp
    branches/soc-2010-nicks/source/gameengine/Ketsji/KX_ObstacleSimulation.cpp
    branches/soc-2010-nicks/source/gameengine/Ketsji/KX_ObstacleSimulation.h
    branches/soc-2010-nicks/source/gameengine/Ketsji/KX_SteeringActuator.cpp

Modified: 
branches/soc-2010-nicks/source/gameengine/Converter/BL_BlenderDataConversion.cpp
===================================================================
--- 
branches/soc-2010-nicks/source/gameengine/Converter/BL_BlenderDataConversion.cpp
    2010-06-15 21:51:15 UTC (rev 29480)
+++ 
branches/soc-2010-nicks/source/gameengine/Converter/BL_BlenderDataConversion.cpp
    2010-06-16 00:23:24 UTC (rev 29481)
@@ -2655,20 +2655,30 @@
                }
        }
 
-       //build navigation mesh
-       for ( i=0;i<objectlist->GetCount();i++)
+       //process navigation mesh objects
+       for ( i=0; i<objectlist->GetCount();i++)
        {
                KX_GameObject* gameobj = 
static_cast<KX_GameObject*>(objectlist->GetValue(i));
                struct Object* blenderobject = gameobj->GetBlenderObject();
                if (blenderobject->type==OB_MESH && (blenderobject->gameflag & 
OB_NAVMESH))
                {
                        KX_NavMeshObject* navmesh = 
static_cast<KX_NavMeshObject*>(gameobj);
+                       navmesh->SetVisible(0, true);
                        navmesh->BuildNavMesh();
-                       navmesh->SetVisible(0, true);
                        if (obssimulation)
                                obssimulation->AddObstaclesForNavMesh(navmesh);
                }
        }
+       for ( i=0; i<inactivelist->GetCount();i++)
+       {
+               KX_GameObject* gameobj = 
static_cast<KX_GameObject*>(inactivelist->GetValue(i));
+               struct Object* blenderobject = gameobj->GetBlenderObject();
+               if (blenderobject->type==OB_MESH && (blenderobject->gameflag & 
OB_NAVMESH))
+               {
+                       KX_NavMeshObject* navmesh = 
static_cast<KX_NavMeshObject*>(gameobj);
+                       navmesh->SetVisible(0, true);
+               }
+       }
 
 #define CONVERT_LOGIC
 #ifdef CONVERT_LOGIC

Modified: branches/soc-2010-nicks/source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- branches/soc-2010-nicks/source/gameengine/Ketsji/KX_GameObject.cpp  
2010-06-15 21:51:15 UTC (rev 29480)
+++ branches/soc-2010-nicks/source/gameengine/Ketsji/KX_GameObject.cpp  
2010-06-16 00:23:24 UTC (rev 29481)
@@ -67,6 +67,7 @@
 #include "SCA_ISensor.h"
 #include "SCA_IController.h"
 #include "NG_NetworkScene.h" //Needed for sendMessage()
+#include "KX_ObstacleSimulation.h"
 
 #include "PyObjectPlus.h" /* python stuff */
 
@@ -101,6 +102,7 @@
        m_pGraphicController(NULL),
        m_xray(false),
        m_pHitObject(NULL),
+       m_pObstacle(NULL),
        m_isDeformable(false)
 #ifndef DISABLE_PYTHON
        , m_attr_dict(NULL)
@@ -148,6 +150,14 @@
        {
                delete m_pGraphicController;
        }
+
+       if (m_pObstacle)
+       {
+               KX_Scene *scene = KX_GetActiveScene();
+               KX_ObstacleSimulation* obstacleSimulation = 
scene->GetObstacleSimulation();
+               obstacleSimulation->DestroyObstacle(m_pObstacle);
+       }
+
 #ifndef DISABLE_PYTHON
        if (m_attr_dict) {
                PyDict_Clear(m_attr_dict); /* incase of circular refs or other 
weired cases */
@@ -348,6 +358,14 @@
        m_pClient_info->m_gameobject = this;
        m_state = 0;
 
+       KX_Scene* scene = KX_GetActiveScene();
+       KX_ObstacleSimulation* obssimulation = scene->GetObstacleSimulation();
+       struct Object* blenderobject = GetBlenderObject();
+       if (obssimulation && (blenderobject->gameflag & OB_HASOBSTACLE))
+       {
+               obssimulation->AddObstacleForObj(this);
+       }
+
 #ifndef DISABLE_PYTHON
        if(m_attr_dict)
                m_attr_dict= PyDict_Copy(m_attr_dict);

Modified: branches/soc-2010-nicks/source/gameengine/Ketsji/KX_GameObject.h
===================================================================
--- branches/soc-2010-nicks/source/gameengine/Ketsji/KX_GameObject.h    
2010-06-15 21:51:15 UTC (rev 29480)
+++ branches/soc-2010-nicks/source/gameengine/Ketsji/KX_GameObject.h    
2010-06-16 00:23:24 UTC (rev 29481)
@@ -59,6 +59,7 @@
 class PHY_IGraphicController;
 class PHY_IPhysicsEnvironment;
 struct Object;
+struct KX_Obstacle;
 
 #ifndef DISABLE_PYTHON
 /* utility conversion function */
@@ -107,6 +108,8 @@
        SG_Node*                                                        
m_pSGNode;
 
        MT_CmMatrix4x4                                          
m_OpenGL_4x4Matrix;
+
+       KX_Obstacle*                                            m_pObstacle;
        
 public:
        bool                                                            
m_isDeformable;
@@ -790,12 +793,24 @@
                }
                m_bSuspendDynamics = false;
        }
+
+       void RegisterObstacle(KX_Obstacle* obstacle)
+       {
+               m_pObstacle = obstacle;
+       }
        
+       void UnregisterObstacle()
+       {
+               m_pObstacle = NULL;
+       }
+               
+
        KX_ClientObjectInfo* getClientInfo() { return m_pClient_info; }
        
        CListValue* GetChildren();
        CListValue* GetChildrenRecursive();
 
+       
 #ifndef DISABLE_PYTHON
        /**
         * @section Python interface functions.

Modified: branches/soc-2010-nicks/source/gameengine/Ketsji/KX_NavMeshObject.cpp
===================================================================
--- branches/soc-2010-nicks/source/gameengine/Ketsji/KX_NavMeshObject.cpp       
2010-06-15 21:51:15 UTC (rev 29480)
+++ branches/soc-2010-nicks/source/gameengine/Ketsji/KX_NavMeshObject.cpp       
2010-06-16 00:23:24 UTC (rev 29481)
@@ -42,6 +42,7 @@
 #include "Value.h"
 #include "Recast.h"
 #include "DetourStatNavMeshBuilder.h"
+#include "KX_ObstacleSimulation.h"
 
 static const int MAX_PATH_LEN = 256;
 static const float polyPickExt[3] = {2, 4, 2};
@@ -91,7 +92,13 @@
 void KX_NavMeshObject::ProcessReplica()
 {
        KX_GameObject::ProcessReplica();
+
        BuildNavMesh();
+       KX_Scene* scene = KX_GetActiveScene();
+       KX_ObstacleSimulation* obssimulation = scene->GetObstacleSimulation();
+       if (obssimulation)
+               obssimulation->AddObstaclesForNavMesh(this);
+
 }
 
 bool KX_NavMeshObject::BuildVertIndArrays(RAS_MeshObject* meshobj, float 
*&vertices, int& nverts,
@@ -171,7 +178,16 @@
                return false;
        
        //prepare vertices and indices
-       MT_Transform worldTransform = GetSGNode()->GetWorldTransform();
+       struct Object* blenderobject = GetBlenderObject();      
+       MT_Point3 posobj;
+       posobj.setValue(blenderobject->loc[0]+blenderobject->dloc[0],
+                                       
blenderobject->loc[1]+blenderobject->dloc[1],
+                                       
blenderobject->loc[2]+blenderobject->dloc[2]);
+       MT_Vector3 eulxyzobj(blenderobject->rot);
+       MT_Vector3 scaleobj(blenderobject->size);
+       MT_Matrix3x3 rotMatrix(eulxyzobj);
+       MT_Transform worldTransform(posobj, rotMatrix.scaled(scaleobj[0], 
scaleobj[1], scaleobj[2])); 
+       
        MT_Point3 pos;
        for (int i=0; i<nverts; i++)
        {

Modified: 
branches/soc-2010-nicks/source/gameengine/Ketsji/KX_ObstacleSimulation.cpp
===================================================================
--- branches/soc-2010-nicks/source/gameengine/Ketsji/KX_ObstacleSimulation.cpp  
2010-06-15 21:51:15 UTC (rev 29480)
+++ branches/soc-2010-nicks/source/gameengine/Ketsji/KX_ObstacleSimulation.cpp  
2010-06-16 00:23:24 UTC (rev 29481)
@@ -195,9 +195,23 @@
        obstacle->m_shape = KX_OBSTACLE_CIRCLE;
        obstacle->m_rad = blenderobject->obstacleRad;
        obstacle->m_gameObj = gameobj;
-       
+       gameobj->RegisterObstacle(obstacle);
 }
 
+void KX_ObstacleSimulation::DestroyObstacle(KX_Obstacle* obstacle)
+{
+       for (size_t i=0; i<m_obstacles.size(); i++)
+       {
+               if (m_obstacles[i] == obstacle)
+               {
+                       obstacle->m_gameObj->UnregisterObstacle();
+                       m_obstacles[i] = m_obstacles.back();
+                       m_obstacles.pop_back();
+                       delete obstacle;
+               }
+       }
+}
+
 void KX_ObstacleSimulation::AddObstaclesForNavMesh(KX_NavMeshObject* 
navmeshobj)
 {      
        dtStatNavMesh* navmesh = navmeshobj->GetNavMesh();

Modified: 
branches/soc-2010-nicks/source/gameengine/Ketsji/KX_ObstacleSimulation.h
===================================================================
--- branches/soc-2010-nicks/source/gameengine/Ketsji/KX_ObstacleSimulation.h    
2010-06-15 21:51:15 UTC (rev 29480)
+++ branches/soc-2010-nicks/source/gameengine/Ketsji/KX_ObstacleSimulation.h    
2010-06-16 00:23:24 UTC (rev 29481)
@@ -81,6 +81,7 @@
        void DrawObstacles();
 
        void AddObstacleForObj(KX_GameObject* gameobj);
+       void DestroyObstacle(KX_Obstacle* obstacle);
        void AddObstaclesForNavMesh(KX_NavMeshObject* navmesh);
        KX_Obstacle* GetObstacle(KX_GameObject* gameobj);
        void UpdateObstacles(); 

Modified: 
branches/soc-2010-nicks/source/gameengine/Ketsji/KX_SteeringActuator.cpp
===================================================================
--- branches/soc-2010-nicks/source/gameengine/Ketsji/KX_SteeringActuator.cpp    
2010-06-15 21:51:15 UTC (rev 29480)
+++ branches/soc-2010-nicks/source/gameengine/Ketsji/KX_SteeringActuator.cpp    
2010-06-16 00:23:24 UTC (rev 29481)
@@ -105,13 +105,13 @@
 {
        if (clientobj == m_target)
        {
-               // this object is being deleted, we cannot continue to track it.
+               // this object is being deleted, we cannot continue to use it.
                m_target = NULL;
                return true;
        }
        else if (clientobj == m_navmesh)
        {
-               // this object is being deleted, we cannot continue to track it.
+               // this object is being deleted, we cannot continue to useit.
                m_navmesh = NULL;
                return true;
        }
@@ -159,6 +159,9 @@
                if (bNegativeEvent || !delta)
                        return false; // do nothing on negative events
 
+               if (!m_target)
+                       return false;
+
                KX_GameObject *obj = (KX_GameObject*) GetParent();
                const MT_Point3& mypos = obj->NodeGetWorldPosition();
                const MT_Point3& targpos = m_target->NodeGetWorldPosition();


_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to