Commits

duststorm01 committed b9cd662 Draft

Fixed bug reports and comments from Saejox.
Added OgreRecast::getPath() and getTarget()

  • Participants
  • Parent commits b6ba7bb

Comments (0)

Files changed (3)

include/OgreRecast.h

    int FindPath(Ogre::Vector3 startPos, Ogre::Vector3 endPos, int nPathSlot, int nTarget);
 
    /**
+     * Retrieve the path at specified slot defined as a line along an ordered set of 3D positions.
+     * The path has a maximum length of MAX_PATHVERT, and is an empty list in case no path is
+     * defined or an invalid pathSlot index is given.
+     **/
+   std::vector<Ogre::Vector3> getPath(int pathSlot);
+
+   /**
+     * The ID number identifying the target for the path at specified slot. Targets have
+     * no meaning for OgreRecast but you can use them to give them their own meanings.
+     * Returns 0 when a faulty pathSlot is given.
+     **/
+   int getTarget(int pathSlot);
+
+   /**
      * Draw the nav mesh for debug purposes. The navmesh is converted to an Ogre::Mesh and
      * put inside the scene for rendering.
      **/

src/OgreDetourTileCache.cpp

 bool OgreDetourTileCache::isWithinBounds(Ogre::Vector3 pos)
 {
     Ogre::Vector2 tpos = getTileAtPos(pos);
-    isWithinBounds((int)tpos.x, (int)tpos.y);
+    return isWithinBounds((int)tpos.x, (int)tpos.y);
 }
 
 TileSelection OgreDetourTileCache::getBounds()

src/OgreRecast.cpp

 #include "OgreRecast.h"
 #include "RecastInputGeom.h"
 #include "DetourTileCache/DetourTileCacheBuilder.h"
-#include "OgreRecastNavmeshPruner.h"
+#include "include/OgreRecastNavmeshPruner.h"
 
 
 bool OgreRecast::STATIC_GEOM_DEBUG = false;
 
 OgreRecast::OgreRecast(Ogre::SceneManager* sceneMgr, OgreRecastConfigParams configParams)
     : m_pSceneMgr(sceneMgr),
-    m_pRecastSN(NULL),
+      m_pRecastSN(NULL),
       m_sg(NULL),
       m_rebuildSg(false),
       mFilter(0),
-      mNavmeshPruner(0)
+      mNavmeshPruner(0),
+      m_ctx(0)
 {
    // Init recast stuff in a safe state
    
    mFilter->setAreaCost(DT_TILECACHE_WALKABLE_AREA, 1.0f);
 
 
+   // Init path store. MaxVertex 0 means empty path slot
+   for(int i = 0; i < MAX_PATHSLOT; i++) {
+       m_PathStore[i].MaxVertex = 0;
+       m_PathStore[i].Target = 0;
+   }
+
 
    // Set configuration
    configure(configParams);
    dtFreeNavMeshQuery(m_navQuery);
    m_navQuery = 0 ;
 
-   if(m_ctx) delete m_ctx ;
+   if(m_ctx){
+       delete m_ctx;
+       m_ctx = 0;
+   }
 }
 
 
     // Smaller cellsizes are the most accurate at finding all the places we could go, but are also slow to generate.
     // Might be suitable for pre-generated meshes. Though it also produces a lot more polygons.
 
-    if(m_ctx)
+    if(m_ctx) {
         delete m_ctx;
+        m_ctx = 0;
+    }
     m_ctx=new rcContext(true);
 
     m_cellSize = params.getCellSize();
     return FindPath(start,end,nPathSlot,nTarget);
 }
 
+std::vector<Ogre::Vector3> OgreRecast::getPath(int pathSlot)
+{
+    std::vector<Ogre::Vector3> result;
+    if(pathSlot < 0 || pathSlot >= MAX_PATHSLOT || m_PathStore[pathSlot].MaxVertex <= 0)
+        return result;
 
+    PATHDATA *path = &(m_PathStore[pathSlot]);
+    result.reserve(path->MaxVertex);
+    for(int i = 0; i < path->MaxVertex; i++) {
+        result.push_back(Ogre::Vector3(path->PosX[i], path->PosY[i], path->PosZ[i]));
+    }
 
+    return result;
+}
+
+
+int OgreRecast::getTarget(int pathSlot)
+{
+    if(pathSlot < 0 || pathSlot >= MAX_PATHSLOT)
+        return 0;
+
+    return m_PathStore[pathSlot].Target;
+}