1
This commit is contained in:
parent
9126cb486c
commit
ec5ae7f997
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
#include "roommgr.h"
|
#include "roommgr.h"
|
||||||
|
|
||||||
static const int MAX_POLYS = 256;
|
|
||||||
static const int NAV_ERROR_NEARESTPOLY = -2;
|
static const int NAV_ERROR_NEARESTPOLY = -2;
|
||||||
|
|
||||||
static const int NAV_ERROR = -1;
|
static const int NAV_ERROR = -1;
|
||||||
@ -260,7 +259,6 @@ int MapInstance::FindStraightPath(int layer,
|
|||||||
return NAV_ERROR_NEARESTPOLY;
|
return NAV_ERROR_NEARESTPOLY;
|
||||||
}
|
}
|
||||||
|
|
||||||
dtPolyRef polys[MAX_POLYS];
|
|
||||||
int npolys;
|
int npolys;
|
||||||
float straightPath[MAX_POLYS * 3];
|
float straightPath[MAX_POLYS * 3];
|
||||||
unsigned char straightPathFlags[MAX_POLYS];
|
unsigned char straightPathFlags[MAX_POLYS];
|
||||||
@ -274,7 +272,7 @@ int MapInstance::FindStraightPath(int layer,
|
|||||||
startNearestPt,
|
startNearestPt,
|
||||||
endNearestPt,
|
endNearestPt,
|
||||||
&filter,
|
&filter,
|
||||||
polys,
|
polys_,
|
||||||
&npolys,
|
&npolys,
|
||||||
MAX_POLYS);
|
MAX_POLYS);
|
||||||
nstraightPath = 0;
|
nstraightPath = 0;
|
||||||
@ -284,13 +282,13 @@ int MapInstance::FindStraightPath(int layer,
|
|||||||
float epos1[3];
|
float epos1[3];
|
||||||
dtVcopy(epos1, endNearestPt);
|
dtVcopy(epos1, endNearestPt);
|
||||||
|
|
||||||
if (polys[npolys-1] != endRef) {
|
if (polys_[npolys-1] != endRef) {
|
||||||
navmesh_query_->closestPointOnPoly(polys[npolys-1], endNearestPt, epos1, 0);
|
navmesh_query_->closestPointOnPoly(polys_[npolys-1], endNearestPt, epos1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
navmesh_query_->findStraightPath(startNearestPt,
|
navmesh_query_->findStraightPath(startNearestPt,
|
||||||
endNearestPt,
|
endNearestPt,
|
||||||
polys,
|
polys_,
|
||||||
npolys,
|
npolys,
|
||||||
straightPath,
|
straightPath,
|
||||||
straightPathFlags,
|
straightPathFlags,
|
||||||
@ -357,8 +355,6 @@ int MapInstance::FindRandomPointAroundCircle(int layer,
|
|||||||
|
|
||||||
int MapInstance::Raycast(int layer, const glm::vec3& start, const glm::vec3& end, glm::vec3& hit_point)
|
int MapInstance::Raycast(int layer, const glm::vec3& start, const glm::vec3& end, glm::vec3& hit_point)
|
||||||
{
|
{
|
||||||
float hitPoint[3];
|
|
||||||
|
|
||||||
float spos[3];
|
float spos[3];
|
||||||
spos[0] = start.x;
|
spos[0] = start.x;
|
||||||
spos[1] = start.y;
|
spos[1] = start.y;
|
||||||
@ -384,31 +380,29 @@ int MapInstance::Raycast(int layer, const glm::vec3& start, const glm::vec3& end
|
|||||||
}
|
}
|
||||||
|
|
||||||
float t = 0;
|
float t = 0;
|
||||||
float hitNormal[3];
|
memset(hit_normal_, 0, sizeof(hit_normal_));
|
||||||
memset(hitNormal, 0, sizeof(hitNormal));
|
|
||||||
|
|
||||||
dtPolyRef polys[MAX_POLYS];
|
|
||||||
int npolys;
|
int npolys;
|
||||||
|
|
||||||
navmesh_query_->raycast(startRef, spos, epos, &filter, &t, hitNormal, polys, &npolys, MAX_POLYS);
|
navmesh_query_->raycast(startRef, spos, epos, &filter, &t, hit_normal_, polys_, &npolys, MAX_POLYS);
|
||||||
|
|
||||||
if (t > 1) {
|
if (t > 1) {
|
||||||
return NAV_ERROR;
|
return NAV_ERROR;
|
||||||
} else {
|
} else {
|
||||||
// Hit
|
// Hit
|
||||||
hitPoint[0] = spos[0] + (epos[0] - spos[0]) * t;
|
hit_pos_[0] = spos[0] + (epos[0] - spos[0]) * t;
|
||||||
hitPoint[1] = spos[1] + (epos[1] - spos[1]) * t;
|
hit_pos_[1] = spos[1] + (epos[1] - spos[1]) * t;
|
||||||
hitPoint[2] = spos[2] + (epos[2] - spos[2]) * t;
|
hit_pos_[2] = spos[2] + (epos[2] - spos[2]) * t;
|
||||||
if (npolys) {
|
if (npolys) {
|
||||||
float h = 0;
|
float h = 0;
|
||||||
navmesh_query_->getPolyHeight(polys[npolys-1], hitPoint, &h);
|
navmesh_query_->getPolyHeight(polys_[npolys-1], hit_pos_, &h);
|
||||||
hitPoint[1] = h;
|
hit_pos_[1] = h;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hit_point.x = hitPoint[0];
|
hit_point.x = hit_pos_[0];
|
||||||
hit_point.y = hitPoint[1];
|
hit_point.y = hit_pos_[1];
|
||||||
hit_point.z = hitPoint[2];
|
hit_point.z = hit_pos_[2];
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@ namespace MetaData
|
|||||||
struct Map;
|
struct Map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const int MAX_POLYS = 256;
|
||||||
|
|
||||||
class Entity;
|
class Entity;
|
||||||
class Obstacle;
|
class Obstacle;
|
||||||
class MapService;
|
class MapService;
|
||||||
@ -47,6 +49,10 @@ class MapInstance
|
|||||||
dtNavMesh* navmesh_ = nullptr;
|
dtNavMesh* navmesh_ = nullptr;
|
||||||
dtNavMeshQuery* navmesh_query_ = nullptr;
|
dtNavMeshQuery* navmesh_query_ = nullptr;
|
||||||
|
|
||||||
|
float hit_normal_[3];
|
||||||
|
float hit_pos_[3];
|
||||||
|
dtPolyRef polys_[MAX_POLYS];
|
||||||
|
|
||||||
int current_uniid_ = 0;
|
int current_uniid_ = 0;
|
||||||
std::map<int, Entity*> uniid_hash_;
|
std::map<int, Entity*> uniid_hash_;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user