Browse Source

nav_query accepts nodepath

Ashwini Jha 5 years ago
parent
commit
a49b1abaff

+ 1 - 1
panda/src/navigation/navMeshNode.h

@@ -25,7 +25,7 @@ class EXPCL_NAVIGATION NavMeshNode: public PandaNode
 {
 PUBLISHED:
   NavMeshNode(const std::string &name, PT(NavMesh) nav_mesh);
-  PT(NavMesh) get_navmesh() { return _nav_mesh; }
+  PT(NavMesh) get_nav_mesh() { return _nav_mesh; }
 private:
   PT(NavMesh) _nav_mesh;
 

+ 14 - 0
panda/src/navigation/navMeshQuery.cxx

@@ -12,6 +12,7 @@
  */
 
 #include "navMeshQuery.h"
+#include "navMeshNode.h"
 #include "DetourNavMeshQuery.h"
 #include "lvecBase3.h"
 #include <iostream>
@@ -32,6 +33,14 @@ NavMeshQuery::NavMeshQuery(PT(NavMesh) nav_mesh):
   set_nav_query(nav_mesh);
 
 }
+NavMeshQuery::NavMeshQuery(NodePath nav_mesh_node_path):
+  _nav_query(0) {
+  
+  _nav_query = dtAllocNavMeshQuery();
+  set_nav_query(nav_mesh_node_path);
+
+}
+
 
 NavMeshQuery::~NavMeshQuery() {
   dtFreeNavMeshQuery(_nav_query);
@@ -54,6 +63,11 @@ bool NavMeshQuery::set_nav_query(PT(NavMesh) nav_mesh) {
   return true;
 }
 
+bool NavMeshQuery::set_nav_query(NodePath nav_mesh_node_path) {
+  NavMeshNode *node = dynamic_cast<NavMeshNode*>(nav_mesh_node_path.node());
+  return set_nav_query(node->get_nav_mesh());
+}
+
 /**
  * Given an input point, this function finds 
  * the nearest point to it lying over the navigation mesh surface.

+ 3 - 0
panda/src/navigation/navMeshQuery.h

@@ -20,6 +20,7 @@
 #include "pta_LVecBase3.h"
 #include "pandaFramework.h"
 #include "pandaSystem.h"
+#include "nodePath.h"
 
 class EXPCL_NAVIGATION NavMeshQuery
 {
@@ -29,6 +30,8 @@ PUBLISHED:
   NavMeshQuery();
   NavMeshQuery(PT(NavMesh) nav_mesh);
   bool set_nav_query(PT(NavMesh) nav_mesh);
+  NavMeshQuery(NodePath nav_mesh_node_path);
+  bool set_nav_query(NodePath nav_mesh_node_path);
   bool nearest_point(LPoint3 &p);
   PTA_LVecBase3 find_path(LPoint3 &start, LPoint3 &end);
   PTA_LVecBase3 find_straight_path(LPoint3 &start, LPoint3 &end, int opt=0);