|
|
@@ -15,6 +15,7 @@
|
|
|
#include "navMeshNode.h"
|
|
|
#include "DetourNavMeshQuery.h"
|
|
|
#include "lvecBase3.h"
|
|
|
+#include "config_navigation.h"
|
|
|
#include <iostream>
|
|
|
|
|
|
/**
|
|
|
@@ -65,7 +66,7 @@ bool NavMeshQuery::set_nav_query(PT(NavMesh) nav_mesh) {
|
|
|
dtStatus status = _nav_query->init(nav_mesh->get_nav_mesh(), MAX_NODES);
|
|
|
|
|
|
if (dtStatusFailed(status)) {
|
|
|
- std::cout<<"\nCannot set nav query!\n";
|
|
|
+ navigation_cat.error() << "\nCannot set nav query!\n";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -78,7 +79,8 @@ bool NavMeshQuery::set_nav_query(PT(NavMesh) nav_mesh) {
|
|
|
* and can be used multiple times.
|
|
|
*/
|
|
|
bool NavMeshQuery::set_nav_query(NodePath nav_mesh_node_path) {
|
|
|
- NavMeshNode *node = dynamic_cast<NavMeshNode*>(nav_mesh_node_path.node());
|
|
|
+ // NavMeshNode *node = dynamic_cast<NavMeshNode*>(nav_mesh_node_path.node());
|
|
|
+ NavMeshNode *node = DCAST(NavMeshNode, nav_mesh_node_path.node());
|
|
|
return set_nav_query(node->get_nav_mesh());
|
|
|
}
|
|
|
|
|
|
@@ -88,7 +90,7 @@ bool NavMeshQuery::set_nav_query(NodePath nav_mesh_node_path) {
|
|
|
*/
|
|
|
bool NavMeshQuery::nearest_point(LPoint3 &p) {
|
|
|
if (!_nav_query) {
|
|
|
- std::cout << "\nNavMeshQuery not created!\n";
|
|
|
+ navigation_cat.error() << "\nNavMeshQuery not created!\n";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -103,7 +105,7 @@ bool NavMeshQuery::nearest_point(LPoint3 &p) {
|
|
|
dtStatus status = _nav_query->findNearestPoly(center, extents, &filter, &nearest_poly_ref_id, nearest_p);
|
|
|
|
|
|
if (dtStatusFailed(status)) {
|
|
|
- std::cout << "\nCannot find nearest point on polymesh.\n";
|
|
|
+ navigation_cat.error() << "\nCannot find nearest point on polymesh.\n";
|
|
|
return false;
|
|
|
}
|
|
|
p = LPoint3(nearest_p[0], -nearest_p[2], nearest_p[1]); // convert back from y-up system to z-up system
|
|
|
@@ -133,26 +135,21 @@ PTA_LVecBase3 NavMeshQuery::find_path(LPoint3 &start, LPoint3 &end) {
|
|
|
|
|
|
dtStatus status = _nav_query->findNearestPoly(start_pos, extents, &filter, &start_ref, nearest_start);
|
|
|
if (dtStatusFailed(status)) {
|
|
|
- std::cout << "\nCannot find nearest point on polymesh for start point.\n";
|
|
|
+ navigation_cat.error() << "\nCannot find nearest point on polymesh for start point.\n";
|
|
|
return path_array;
|
|
|
}
|
|
|
- std::cout<<"\nStart_ref: "<<start_ref<<"\n";
|
|
|
- std::cout<<"\nStarting point:\t"<<nearest_start[0]<<"\t"<<-nearest_start[2]<<"\t"<<nearest_start[1]<<"\n";
|
|
|
-
|
|
|
+
|
|
|
status = _nav_query->findNearestPoly(end_pos, extents, &filter, &end_ref, nearest_end);
|
|
|
if (dtStatusFailed(status)) {
|
|
|
- std::cout << "\nCannot find nearest point on polymesh for end point.\n";
|
|
|
+ navigation_cat.error() << "\nCannot find nearest point on polymesh for end point.\n";
|
|
|
return path_array;
|
|
|
}
|
|
|
- std::cout<<"\nEnd_ref: "<<end_ref<<"\n";
|
|
|
- std::cout<<"\nEnding point:\t"<<nearest_end[0]<<"\t"<<-nearest_end[2]<<"\t"<<nearest_end[1]<<"\n";
|
|
|
|
|
|
status = _nav_query->findPath(start_ref, end_ref, nearest_start, nearest_end, &filter, path, &path_count, MAX_POLYS);
|
|
|
if (dtStatusFailed(status)) {
|
|
|
- std::cout << "\nCannot find the path.\n";
|
|
|
+ navigation_cat.error() << "\nCannot find the path.\n";
|
|
|
return path_array;
|
|
|
}
|
|
|
- std::cout<<"\nNumber of polygons included in path: "<<path_count<<"\n";
|
|
|
|
|
|
float pos[3] = {start_pos[0], start_pos[1], start_pos[2]};
|
|
|
|
|
|
@@ -162,7 +159,7 @@ PTA_LVecBase3 NavMeshQuery::find_path(LPoint3 &start, LPoint3 &end) {
|
|
|
|
|
|
status = _nav_query->closestPointOnPolyBoundary(path[i], pos, closest);
|
|
|
if (dtStatusFailed(status)) {
|
|
|
- std::cout << "\nCannot find the nearest point on polygon.\n";
|
|
|
+ navigation_cat.error() << "\nCannot find the nearest point on polygon.\n";
|
|
|
return path_array;
|
|
|
}
|
|
|
|
|
|
@@ -199,27 +196,22 @@ PTA_LVecBase3 NavMeshQuery::find_straight_path(LPoint3 &start, LPoint3 &end, int
|
|
|
|
|
|
dtStatus status = _nav_query->findNearestPoly(start_pos, extents, &filter, &start_ref, nearest_start);
|
|
|
if (dtStatusFailed(status)) {
|
|
|
- std::cout << "\nCannot find nearest point on polymesh for start point.\n";
|
|
|
+ navigation_cat.error() << "\nCannot find nearest point on polymesh for start point.\n";
|
|
|
return straight_path_array;
|
|
|
}
|
|
|
- std::cout<<"\nStart_ref: "<<start_ref<<"\n";
|
|
|
- std::cout<<"\nStarting point:\t"<<nearest_start[0]<<"\t"<<-nearest_start[2]<<"\t"<<nearest_start[1]<<"\n";
|
|
|
-
|
|
|
+
|
|
|
status = _nav_query->findNearestPoly(end_pos, extents, &filter, &end_ref, nearest_end);
|
|
|
if (dtStatusFailed(status)) {
|
|
|
- std::cout << "\nCannot find nearest point on polymesh for end point.\n";
|
|
|
+ navigation_cat.error() << "\nCannot find nearest point on polymesh for end point.\n";
|
|
|
return straight_path_array;
|
|
|
}
|
|
|
- std::cout<<"\nEnd_ref: "<<end_ref<<"\n";
|
|
|
- std::cout<<"\nEnding point:\t"<<nearest_end[0]<<"\t"<<-nearest_end[2]<<"\t"<<nearest_end[1]<<"\n";
|
|
|
|
|
|
status = _nav_query->findPath(start_ref, end_ref, nearest_start, nearest_end, &filter, path, &path_count, MAX_POLYS);
|
|
|
if (dtStatusFailed(status)) {
|
|
|
- std::cout << "\nCannot find the path.\n";
|
|
|
+ navigation_cat.error() << "\nCannot find the path.\n";
|
|
|
return straight_path_array;
|
|
|
}
|
|
|
- std::cout<<"\nNumber of polygons included in path: "<<path_count<<"\n";
|
|
|
-
|
|
|
+
|
|
|
float straight_path[MAX_POLYS*3];
|
|
|
unsigned char straight_path_flags[MAX_POLYS];
|
|
|
dtPolyRef straight_path_refs[MAX_POLYS];
|
|
|
@@ -227,11 +219,10 @@ PTA_LVecBase3 NavMeshQuery::find_straight_path(LPoint3 &start, LPoint3 &end, int
|
|
|
|
|
|
status = _nav_query->findStraightPath(nearest_start, nearest_end, path, path_count, straight_path, straight_path_flags, straight_path_refs, &straight_path_count, MAX_POLYS, opt);
|
|
|
if (dtStatusFailed(status)) {
|
|
|
- std::cout << "\nCannot find the straight path.\n";
|
|
|
+ navigation_cat.error() << "\nCannot find the straight path.\n";
|
|
|
return straight_path_array;
|
|
|
}
|
|
|
- std::cout<<"\nNumber of points included in straight path: "<<straight_path_count<<"\n";
|
|
|
-
|
|
|
+
|
|
|
for(int i=0;i<straight_path_count*3;i+=3) {
|
|
|
|
|
|
LVecBase3 point = LVecBase3( straight_path[i], -straight_path[i+2], straight_path[i+1]); // convert back from y-up system to z-up system
|