Planeshift
DetourObstacleAvoidance.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
3 //
4 // This software is provided 'as-is', without any express or implied
5 // warranty. In no event will the authors be held liable for any damages
6 // arising from the use of this software.
7 // Permission is granted to anyone to use this software for any purpose,
8 // including commercial applications, and to alter it and redistribute it
9 // freely, subject to the following restrictions:
10 // 1. The origin of this software must not be misrepresented; you must not
11 // claim that you wrote the original software. If you use this software
12 // in a product, an acknowledgment in the product documentation would be
13 // appreciated but is not required.
14 // 2. Altered source versions must be plainly marked as such, and must not be
15 // misrepresented as being the original software.
16 // 3. This notice may not be removed or altered from any source distribution.
17 //
18 
19 #ifndef DETOUROBSTACLEAVOIDANCE_H
20 #define DETOUROBSTACLEAVOIDANCE_H
21 
23 {
24  float p[3];
25  float vel[3];
26  float dvel[3];
27  float rad;
28  float dp[3], np[3];
29 };
30 
32 {
33  float p[3], q[3];
34  bool touch;
35 };
36 
37 
39 {
40 public:
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  int m_nsamples;
62  int m_maxSamples;
63  float* m_vel;
64  float* m_ssize;
65  float* m_pen;
66  float* m_vpen;
67  float* m_vcpen;
68  float* m_spen;
69  float* m_tpen;
70 };
71 
74 
75 
76 static const int DT_MAX_PATTERN_DIVS = 32;
77 static const int DT_MAX_PATTERN_RINGS = 4;
78 
80 {
81  float velBias;
82  float weightDesVel;
83  float weightCurVel;
84  float weightSide;
85  float weightToi;
86  float horizTime;
87  unsigned char gridSize;
88  unsigned char adaptiveDivs;
89  unsigned char adaptiveRings;
90  unsigned char adaptiveDepth;
91 };
92 
94 {
95 public:
98 
99  bool init(const int maxCircles, const int maxSegments);
100 
101  void reset();
102 
103  void addCircle(const float* pos, const float rad,
104  const float* vel, const float* dvel);
105 
106  void addSegment(const float* p, const float* q);
107 
108  int sampleVelocityGrid(const float* pos, const float rad, const float vmax,
109  const float* vel, const float* dvel, float* nvel,
110  const dtObstacleAvoidanceParams* params,
111  dtObstacleAvoidanceDebugData* debug = 0);
112 
113  int sampleVelocityAdaptive(const float* pos, const float rad, const float vmax,
114  const float* vel, const float* dvel, float* nvel,
115  const dtObstacleAvoidanceParams* params,
116  dtObstacleAvoidanceDebugData* debug = 0);
117 
118  inline int getObstacleCircleCount() const { return m_ncircles; }
119  const dtObstacleCircle* getObstacleCircle(const int i) { return &m_circles[i]; }
120 
121  inline int getObstacleSegmentCount() const { return m_nsegments; }
122  const dtObstacleSegment* getObstacleSegment(const int i) { return &m_segments[i]; }
123 
124 private:
125 
126  void prepare(const float* pos, const float* dvel);
127 
128  float processSample(const float* vcand, const float cs,
129  const float* pos, const float rad,
130  const float* vel, const float* dvel,
132 
133  dtObstacleCircle* insertCircle(const float dist);
134  dtObstacleSegment* insertSegment(const float dist);
135 
136  dtObstacleAvoidanceParams m_params;
137  float m_invHorizTime;
138  float m_vmax;
139  float m_invVmax;
140 
141  int m_maxCircles;
142  dtObstacleCircle* m_circles;
143  int m_ncircles;
144 
145  int m_maxSegments;
146  dtObstacleSegment* m_segments;
147  int m_nsegments;
148 };
149 
152 
153 
154 #endif // DETOUROBSTACLEAVOIDANCE_H
float getSamplePenalty(const int i) const
float getSampleSize(const int i) const
unsigned char adaptiveRings
adaptive
void dtFreeObstacleAvoidanceQuery(dtObstacleAvoidanceQuery *ptr)
float vel[3]
Velocity of the obstacle.
float getSampleCurrentVelocityPenalty(const int i) const
dtObstacleAvoidanceDebugData * dtAllocObstacleAvoidanceDebugData()
static const int DT_MAX_PATTERN_RINGS
Max number of adaptive rings.
unsigned char adaptiveDepth
adaptive
float getSamplePreferredSidePenalty(const int i) const
float p[3]
Position of the obstacle.
float dvel[3]
Velocity of the obstacle.
const dtObstacleSegment * getObstacleSegment(const int i)
const dtObstacleCircle * getObstacleCircle(const int i)
float getSampleDesiredVelocityPenalty(const int i) const
float np[3]
Use for side selection during sampling.
unsigned char adaptiveDivs
adaptive
float getSampleCollisionTimePenalty(const int i) const
float rad
Radius of the obstacle.
const float * getSampleVelocity(const int i) const
dtObstacleAvoidanceQuery * dtAllocObstacleAvoidanceQuery()
void dtFreeObstacleAvoidanceDebugData(dtObstacleAvoidanceDebugData *ptr)
static const int DT_MAX_PATTERN_DIVS
Max numver of adaptive divs.