forked from webaverse/physics-wasm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PathFinder.h
98 lines (90 loc) · 2.66 KB
/
PathFinder.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#ifndef _PATHFINDER_H
#define _PATHFINDER_H
#include "physics.h"
#include <vector>
using namespace physx;
struct Voxel {
Vec position;
bool _isStart = false;
bool _isDest = false;
bool _isReached = false;
float _priority = 0;
float _costSoFar = 0;
Voxel *_prev = NULL;
Voxel *_next = NULL;
Voxel *_leftVoxel = NULL;
Voxel *_rightVoxel = NULL;
Voxel *_btmVoxel = NULL;
Voxel *_topVoxel = NULL;
Voxel *_backVoxel = NULL;
Voxel *_frontVoxel = NULL;
bool _canLeft = false;
bool _canRight = false;
bool _canBtm = false;
bool _canTop = false;
bool _canBack = false;
bool _canFront = false;
bool _isPath = false;
bool _isFrontier = false;
};
enum DETECT_DIR {
UNKNOWN = 0,
UP = 1,
DOWN = -1,
};
class PathFinder {
public:
PathFinder(std::vector<PxRigidActor *> _actors, float _hy, float _heightTolerance, unsigned int _maxIterdetect, unsigned int _maxIterStep, unsigned int _numIgnorePhysicsIds, unsigned int *_ignorePhysicsIds);
void resetVoxelAStar(Voxel *voxel);
void reset();
float roundToHeightTolerance(float y);
void interpoWaypointResult();
int getIndex(std::vector<Voxel *> v, Voxel * K);
void simplifyWaypointResult(Voxel *result);
Voxel *getVoxel(Vec position);
void setVoxelo(Voxel *voxel);
bool detect(Vec *position, bool isGlobal);
bool detect(Vec *position);
Voxel *createVoxel(Vec position);
void setNextOfPathVoxel(Voxel *voxel);
void found(Voxel *voxel);
void generateVoxelMapLeft(Voxel *currentVoxel);
void generateVoxelMapRight(Voxel *currentVoxel);
void generateVoxelMapBtm(Voxel *currentVoxel);
void generateVoxelMapTop(Voxel *currentVoxel);
void generateVoxelMapBack(Voxel *currentVoxel);
void generateVoxelMapFront(Voxel *currentVoxel);
void stepVoxel(Voxel *voxel, Voxel *prevVoxel, float cost);
void step();
void untilFound();
void detectDestGlobal(Vec *position, DETECT_DIR detectDir);
std::vector<Voxel *> getPath(Vec _start, Vec _dest, bool _isWalk);
//
std::vector<PxRigidActor *> actors;
Vec up = Vec(0, 1, 0);
float heightTolerance;
unsigned int maxIterStep;
unsigned int *ignorePhysicsIds;
unsigned int iterStep = 0;
bool allowNearest = true;
unsigned int iterDetect = 0;
unsigned int maxIterDetect;
Vec start;
Vec dest;
Vec startGlobal;
Vec destGlobal;
float voxelHeightHalf;
std::vector<Voxel *> frontiers;
std::vector<Voxel *> voxels;
std::map<std::string, Voxel *> voxelo;
Quat startDestQuaternion;
bool isWalk = true;
bool isFound = false;
std::vector<Voxel *> waypointResult;
Voxel *startVoxel;
Voxel *destVoxel;
PxBoxGeometry geom;
unsigned int numIgnorePhysicsIds;
bool canLeft, canRight, canBtm, canTop, canBack, canFront;
};
#endif