| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#ifndef DETOUROBSTACLEAVOIDANCE_H |
| 20 |
#define DETOUROBSTACLEAVOIDANCE_H |
| 21 |
|
| 22 |
struct dtObstacleCircle |
| 23 |
{ |
| 24 |
float p[3]; |
| 25 |
float vel[3]; |
| 26 |
float dvel[3]; |
| 27 |
float rad; |
| 28 |
float dp[3], np[3]; |
| 29 |
}; |
| 30 |
|
| 31 |
struct dtObstacleSegment |
| 32 |
{ |
| 33 |
float p[3], q[3]; |
| 34 |
bool touch; |
| 35 |
}; |
| 36 |
|
| 37 |
|
| 38 |
class dtObstacleAvoidanceDebugData |
| 39 |
{ |
| 40 |
public: |
| 41 |
dtObstacleAvoidanceDebugData(); |
| 42 |
~dtObstacleAvoidanceDebugData(); |
| 43 |
|
| 44 |
bool init(const int maxSamples); |
| 45 |
void reset(); |
| 46 |
void addSample(const float* vel, const float ssize, const float pen, |
| 47 |
const float vpen, const float vcpen, const float spen, const float tpen); |
| 48 |
|
| 49 |
void normalizeSamples(); |
| 50 |
|
| 51 |
inline int getSampleCount() const { return m_nsamples; } |
| 52 |
inline const float* getSampleVelocity(const int i) const { return &m_vel[i*3]; } |
| 53 |
inline float getSampleSize(const int i) const { return m_ssize[i]; } |
| 54 |
inline float getSamplePenalty(const int i) const { return m_pen[i]; } |
| 55 |
inline float getSampleDesiredVelocityPenalty(const int i) const { return m_vpen[i]; } |
| 56 |
inline float getSampleCurrentVelocityPenalty(const int i) const { return m_vcpen[i]; } |
| 57 |
inline float getSamplePreferredSidePenalty(const int i) const { return m_spen[i]; } |
| 58 |
inline float getSampleCollisionTimePenalty(const int i) const { return m_tpen[i]; } |
| 59 |
|
| 60 |
private: |
| 61 |
|
| 62 |
dtObstacleAvoidanceDebugData(const dtObstacleAvoidanceDebugData&); |
| 63 |
dtObstacleAvoidanceDebugData& operator=(const dtObstacleAvoidanceDebugData&); |
| 64 |
|
| 65 |
int m_nsamples; |
| 66 |
int m_maxSamples; |
| 67 |
float* m_vel; |
| 68 |
float* m_ssize; |
| 69 |
float* m_pen; |
| 70 |
float* m_vpen; |
| 71 |
float* m_vcpen; |
| 72 |
float* m_spen; |
| 73 |
float* m_tpen; |
| 74 |
}; |
| 75 |
|
| 76 |
dtObstacleAvoidanceDebugData* dtAllocObstacleAvoidanceDebugData(); |
| 77 |
void dtFreeObstacleAvoidanceDebugData(dtObstacleAvoidanceDebugData* ptr); |
| 78 |
|
| 79 |
|
| 80 |
static const int DT_MAX_PATTERN_DIVS = 32; |
| 81 |
static const int DT_MAX_PATTERN_RINGS = 4; |
| 82 |
|
| 83 |
struct dtObstacleAvoidanceParams |
| 84 |
{ |
| 85 |
float velBias; |
| 86 |
float weightDesVel; |
| 87 |
float weightCurVel; |
| 88 |
float weightSide; |
| 89 |
float weightToi; |
| 90 |
float horizTime; |
| 91 |
unsigned char gridSize; |
| 92 |
unsigned char adaptiveDivs; |
| 93 |
unsigned char adaptiveRings; |
| 94 |
unsigned char adaptiveDepth; |
| 95 |
}; |
| 96 |
|
| 97 |
class dtObstacleAvoidanceQuery |
| 98 |
{ |
| 99 |
public: |
| 100 |
dtObstacleAvoidanceQuery(); |
| 101 |
~dtObstacleAvoidanceQuery(); |
| 102 |
|
| 103 |
bool init(const int maxCircles, const int maxSegments); |
| 104 |
|
| 105 |
void reset(); |
| 106 |
|
| 107 |
void addCircle(const float* pos, const float rad, |
| 108 |
const float* vel, const float* dvel); |
| 109 |
|
| 110 |
void addSegment(const float* p, const float* q); |
| 111 |
|
| 112 |
int sampleVelocityGrid(const float* pos, const float rad, const float vmax, |
| 113 |
const float* vel, const float* dvel, float* nvel, |
| 114 |
const dtObstacleAvoidanceParams* params, |
| 115 |
dtObstacleAvoidanceDebugData* debug = 0); |
| 116 |
|
| 117 |
int sampleVelocityAdaptive(const float* pos, const float rad, const float vmax, |
| 118 |
const float* vel, const float* dvel, float* nvel, |
| 119 |
const dtObstacleAvoidanceParams* params, |
| 120 |
dtObstacleAvoidanceDebugData* debug = 0); |
| 121 |
|
| 122 |
inline int getObstacleCircleCount() const { return m_ncircles; } |
| 123 |
const dtObstacleCircle* getObstacleCircle(const int i) { return &m_circles[i]; } |
| 124 |
|
| 125 |
inline int getObstacleSegmentCount() const { return m_nsegments; } |
| 126 |
const dtObstacleSegment* getObstacleSegment(const int i) { return &m_segments[i]; } |
| 127 |
|
| 128 |
private: |
| 129 |
|
| 130 |
dtObstacleAvoidanceQuery(const dtObstacleAvoidanceQuery&); |
| 131 |
dtObstacleAvoidanceQuery& operator=(const dtObstacleAvoidanceQuery&); |
| 132 |
|
| 133 |
void prepare(const float* pos, const float* dvel); |
| 134 |
|
| 135 |
float processSample(const float* vcand, const float cs, |
| 136 |
const float* pos, const float rad, |
| 137 |
const float* vel, const float* dvel, |
| 138 |
const float minPenalty, |
| 139 |
dtObstacleAvoidanceDebugData* debug); |
| 140 |
|
| 141 |
dtObstacleAvoidanceParams m_params; |
| 142 |
float m_invHorizTime; |
| 143 |
float m_vmax; |
| 144 |
float m_invVmax; |
| 145 |
|
| 146 |
int m_maxCircles; |
| 147 |
dtObstacleCircle* m_circles; |
| 148 |
int m_ncircles; |
| 149 |
|
| 150 |
int m_maxSegments; |
| 151 |
dtObstacleSegment* m_segments; |
| 152 |
int m_nsegments; |
| 153 |
}; |
| 154 |
|
| 155 |
dtObstacleAvoidanceQuery* dtAllocObstacleAvoidanceQuery(); |
| 156 |
void dtFreeObstacleAvoidanceQuery(dtObstacleAvoidanceQuery* ptr); |
| 157 |
|
| 158 |
|
| 159 |
#endif |