DetourObstacleAvoidance.h
4.81 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//
// Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#ifndef DETOUROBSTACLEAVOIDANCE_H
#define DETOUROBSTACLEAVOIDANCE_H
struct dtObstacleCircle
{
float p[3]; ///< Position of the obstacle
float vel[3]; ///< Velocity of the obstacle
float dvel[3]; ///< Velocity of the obstacle
float rad; ///< Radius of the obstacle
float dp[3], np[3]; ///< Use for side selection during sampling.
};
struct dtObstacleSegment
{
float p[3], q[3]; ///< End points of the obstacle segment
bool touch;
};
class dtObstacleAvoidanceDebugData
{
public:
dtObstacleAvoidanceDebugData();
~dtObstacleAvoidanceDebugData();
bool init(const int maxSamples);
void reset();
void addSample(const float* vel, const float ssize, const float pen,
const float vpen, const float vcpen, const float spen, const float tpen);
void normalizeSamples();
inline int getSampleCount() const { return m_nsamples; }
inline const float* getSampleVelocity(const int i) const { return &m_vel[i*3]; }
inline float getSampleSize(const int i) const { return m_ssize[i]; }
inline float getSamplePenalty(const int i) const { return m_pen[i]; }
inline float getSampleDesiredVelocityPenalty(const int i) const { return m_vpen[i]; }
inline float getSampleCurrentVelocityPenalty(const int i) const { return m_vcpen[i]; }
inline float getSamplePreferredSidePenalty(const int i) const { return m_spen[i]; }
inline float getSampleCollisionTimePenalty(const int i) const { return m_tpen[i]; }
private:
int m_nsamples;
int m_maxSamples;
float* m_vel;
float* m_ssize;
float* m_pen;
float* m_vpen;
float* m_vcpen;
float* m_spen;
float* m_tpen;
};
dtObstacleAvoidanceDebugData* dtAllocObstacleAvoidanceDebugData();
void dtFreeObstacleAvoidanceDebugData(dtObstacleAvoidanceDebugData* ptr);
static const int DT_MAX_PATTERN_DIVS = 32; ///< Max numver of adaptive divs.
static const int DT_MAX_PATTERN_RINGS = 4; ///< Max number of adaptive rings.
struct dtObstacleAvoidanceParams
{
float velBias;
float weightDesVel;
float weightCurVel;
float weightSide;
float weightToi;
float horizTime;
unsigned char gridSize; ///< grid
unsigned char adaptiveDivs; ///< adaptive
unsigned char adaptiveRings; ///< adaptive
unsigned char adaptiveDepth; ///< adaptive
};
class dtObstacleAvoidanceQuery
{
public:
dtObstacleAvoidanceQuery();
~dtObstacleAvoidanceQuery();
bool init(const int maxCircles, const int maxSegments);
void reset();
void addCircle(const float* pos, const float rad,
const float* vel, const float* dvel);
void addSegment(const float* p, const float* q);
int sampleVelocityGrid(const float* pos, const float rad, const float vmax,
const float* vel, const float* dvel, float* nvel,
const dtObstacleAvoidanceParams* params,
dtObstacleAvoidanceDebugData* debug = 0);
int sampleVelocityAdaptive(const float* pos, const float rad, const float vmax,
const float* vel, const float* dvel, float* nvel,
const dtObstacleAvoidanceParams* params,
dtObstacleAvoidanceDebugData* debug = 0);
inline int getObstacleCircleCount() const { return m_ncircles; }
const dtObstacleCircle* getObstacleCircle(const int i) { return &m_circles[i]; }
inline int getObstacleSegmentCount() const { return m_nsegments; }
const dtObstacleSegment* getObstacleSegment(const int i) { return &m_segments[i]; }
private:
void prepare(const float* pos, const float* dvel);
float processSample(const float* vcand, const float cs,
const float* pos, const float rad,
const float* vel, const float* dvel,
const float minPenalty,
dtObstacleAvoidanceDebugData* debug);
dtObstacleAvoidanceParams m_params;
float m_invHorizTime;
float m_vmax;
float m_invVmax;
int m_maxCircles;
dtObstacleCircle* m_circles;
int m_ncircles;
int m_maxSegments;
dtObstacleSegment* m_segments;
int m_nsegments;
};
dtObstacleAvoidanceQuery* dtAllocObstacleAvoidanceQuery();
void dtFreeObstacleAvoidanceQuery(dtObstacleAvoidanceQuery* ptr);
#endif // DETOUROBSTACLEAVOIDANCE_H