Recast Navigation
Navigation-mesh Toolset for Games
Loading...
Searching...
No Matches
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{
40public:
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
60private:
61 // Explicitly disabled copy constructor and copy assignment operator.
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
78
79
80static const int DT_MAX_PATTERN_DIVS = 32;
81static const int DT_MAX_PATTERN_RINGS = 4;
82
84{
85 float velBias;
89 float weightToi;
90 float horizTime;
91 unsigned char gridSize;
92 unsigned char adaptiveDivs;
93 unsigned char adaptiveRings;
94 unsigned char adaptiveDepth;
95};
96
98{
99public:
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,
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,
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
128private:
129 // Explicitly disabled copy constructor and copy assignment operator.
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,
140
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
157
158
159#endif // DETOUROBSTACLEAVOIDANCE_H
dtObstacleAvoidanceQuery * dtAllocObstacleAvoidanceQuery()
Definition DetourObstacleAvoidance.cpp:194
static const int DT_MAX_PATTERN_DIVS
Max numver of adaptive divs.
Definition DetourObstacleAvoidance.h:80
void dtFreeObstacleAvoidanceDebugData(dtObstacleAvoidanceDebugData *ptr)
Definition DetourObstacleAvoidance.cpp:79
void dtFreeObstacleAvoidanceQuery(dtObstacleAvoidanceQuery *ptr)
Definition DetourObstacleAvoidance.cpp:201
dtObstacleAvoidanceDebugData * dtAllocObstacleAvoidanceDebugData()
Definition DetourObstacleAvoidance.cpp:72
static const int DT_MAX_PATTERN_RINGS
Max number of adaptive rings.
Definition DetourObstacleAvoidance.h:81
Definition DetourObstacleAvoidance.h:39
void reset()
Definition DetourObstacleAvoidance.cpp:141
float getSamplePenalty(const int i) const
Definition DetourObstacleAvoidance.h:54
int getSampleCount() const
Definition DetourObstacleAvoidance.h:51
bool init(const int maxSamples)
Definition DetourObstacleAvoidance.cpp:111
float getSamplePreferredSidePenalty(const int i) const
Definition DetourObstacleAvoidance.h:57
void addSample(const float *vel, const float ssize, const float pen, const float vpen, const float vcpen, const float spen, const float tpen)
Definition DetourObstacleAvoidance.cpp:146
float getSampleCollisionTimePenalty(const int i) const
Definition DetourObstacleAvoidance.h:58
float getSampleSize(const int i) const
Definition DetourObstacleAvoidance.h:53
float getSampleDesiredVelocityPenalty(const int i) const
Definition DetourObstacleAvoidance.h:55
const float * getSampleVelocity(const int i) const
Definition DetourObstacleAvoidance.h:52
void normalizeSamples()
Definition DetourObstacleAvoidance.cpp:184
~dtObstacleAvoidanceDebugData()
Definition DetourObstacleAvoidance.cpp:100
float getSampleCurrentVelocityPenalty(const int i) const
Definition DetourObstacleAvoidance.h:56
dtObstacleAvoidanceDebugData()
Definition DetourObstacleAvoidance.cpp:87
Definition DetourObstacleAvoidance.h:98
const dtObstacleSegment * getObstacleSegment(const int i)
Definition DetourObstacleAvoidance.h:126
dtObstacleAvoidanceQuery()
Definition DetourObstacleAvoidance.cpp:209
int getObstacleSegmentCount() const
Definition DetourObstacleAvoidance.h:125
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)
Definition DetourObstacleAvoidance.cpp:435
~dtObstacleAvoidanceQuery()
Definition DetourObstacleAvoidance.cpp:222
void reset()
Definition DetourObstacleAvoidance.cpp:247
bool init(const int maxCircles, const int maxSegments)
Definition DetourObstacleAvoidance.cpp:228
const dtObstacleCircle * getObstacleCircle(const int i)
Definition DetourObstacleAvoidance.h:123
void addSegment(const float *p, const float *q)
Definition DetourObstacleAvoidance.cpp:266
void addCircle(const float *pos, const float rad, const float *vel, const float *dvel)
Definition DetourObstacleAvoidance.cpp:253
int getObstacleCircleCount() const
Definition DetourObstacleAvoidance.h:122
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)
Definition DetourObstacleAvoidance.cpp:507
Definition DetourObstacleAvoidance.h:84
float horizTime
Definition DetourObstacleAvoidance.h:90
float weightSide
Definition DetourObstacleAvoidance.h:88
unsigned char gridSize
grid
Definition DetourObstacleAvoidance.h:91
float weightDesVel
Definition DetourObstacleAvoidance.h:86
unsigned char adaptiveDepth
adaptive
Definition DetourObstacleAvoidance.h:94
float weightToi
Definition DetourObstacleAvoidance.h:89
unsigned char adaptiveDivs
adaptive
Definition DetourObstacleAvoidance.h:92
float velBias
Definition DetourObstacleAvoidance.h:85
unsigned char adaptiveRings
adaptive
Definition DetourObstacleAvoidance.h:93
float weightCurVel
Definition DetourObstacleAvoidance.h:87
Definition DetourObstacleAvoidance.h:23
float np[3]
Use for side selection during sampling.
Definition DetourObstacleAvoidance.h:28
float dp[3]
Definition DetourObstacleAvoidance.h:28
float p[3]
Position of the obstacle.
Definition DetourObstacleAvoidance.h:24
float dvel[3]
Velocity of the obstacle.
Definition DetourObstacleAvoidance.h:26
float vel[3]
Velocity of the obstacle.
Definition DetourObstacleAvoidance.h:25
float rad
Radius of the obstacle.
Definition DetourObstacleAvoidance.h:27
Definition DetourObstacleAvoidance.h:32
bool touch
Definition DetourObstacleAvoidance.h:34
float q[3]
End points of the obstacle segment.
Definition DetourObstacleAvoidance.h:33
float p[3]
Definition DetourObstacleAvoidance.h:33