UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
DetourObstacleAvoidance.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2// Modified version of Recast/Detour's source file
3
4//
5// Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
6//
7// This software is provided 'as-is', without any express or implied
8// warranty. In no event will the authors be held liable for any damages
9// arising from the use of this software.
10// Permission is granted to anyone to use this software for any purpose,
11// including commercial applications, and to alter it and redistribute it
12// freely, subject to the following restrictions:
13// 1. The origin of this software must not be misrepresented; you must not
14// claim that you wrote the original software. If you use this software
15// in a product, an acknowledgment in the product documentation would be
16// appreciated but is not required.
17// 2. Altered source versions must be plainly marked as such, and must not be
18// misrepresented as being the original software.
19// 3. This notice may not be removed or altered from any source distribution.
20//
21
22#ifndef DETOUROBSTACLEAVOIDANCE_H
23#define DETOUROBSTACLEAVOIDANCE_H
24
25#include "CoreMinimal.h"
27
36
38{
39 dtReal p[3], q[3];
40 unsigned char touch : 1;
41 unsigned char canIgnore : 1;
42};
43
45{
46public:
49
50 NAVMESH_API bool init(const int maxSamples);
51 NAVMESH_API void reset();
52 NAVMESH_API void addSample(const dtReal* vel, const dtReal ssize, const dtReal pen,
53 const dtReal vpen, const dtReal vcpen, const dtReal spen, const dtReal tpen);
54
56
57 inline int getSampleCount() const { return m_nsamples; }
58 inline const dtReal* getSampleVelocity(const int i) const { return &m_vel[i*3]; }
59 inline dtReal getSampleSize(const int i) const { return m_ssize[i]; }
60 inline dtReal getSamplePenalty(const int i) const { return m_pen[i]; }
61 inline dtReal getSampleDesiredVelocityPenalty(const int i) const { return m_vpen[i]; }
62 inline dtReal getSampleCurrentVelocityPenalty(const int i) const { return m_vcpen[i]; }
63 inline dtReal getSamplePreferredSidePenalty(const int i) const { return m_spen[i]; }
64 inline dtReal getSampleCollisionTimePenalty(const int i) const { return m_tpen[i]; }
65
66private:
67 int m_nsamples;
68 int m_maxSamples;
69 dtReal* m_vel;
70 dtReal* m_ssize;
71 dtReal* m_pen;
72 dtReal* m_vpen;
73 dtReal* m_vcpen;
74 dtReal* m_spen;
75 dtReal* m_tpen;
76};
77
80
81
82static const int DT_MAX_PATTERN_DIVS = 32;
83static const int DT_MAX_PATTERN_RINGS = 4;
84static const int DT_MAX_CUSTOM_SAMPLES = 16;
85
99
100// [UE] custom sampling patterns
102{
103 dtReal angles[DT_MAX_CUSTOM_SAMPLES];
104 dtReal radii[DT_MAX_CUSTOM_SAMPLES];
106};
107
109{
110public:
113
114 NAVMESH_API bool init(const int maxCircles, const int maxSegments, const int maxCustomPatterns);
115
116 NAVMESH_API void reset();
117
118 NAVMESH_API void addCircle(const dtReal* pos, const dtReal rad,
119 const dtReal* vel, const dtReal* dvel);
120
121 NAVMESH_API void addSegment(const dtReal* p, const dtReal* q, int flags = 0);
122
123 // [UE] store new sampling pattern
124 NAVMESH_API bool setCustomSamplingPattern(int idx, const dtReal* angles, const dtReal* radii, int nsamples);
125
126 // [UE] get custom sampling pattern
127 NAVMESH_API bool getCustomSamplingPattern(int idx, dtReal* angles, dtReal* radii, int* nsamples);
128
129 // [UE] sample velocity using custom patterns
130 NAVMESH_API int sampleVelocityCustom(const dtReal* pos, const dtReal rad,
131 const dtReal vmax, const dtReal vmult,
132 const dtReal* vel, const dtReal* dvel, dtReal* nvel,
133 const dtObstacleAvoidanceParams* params,
135
136 NAVMESH_API int sampleVelocityAdaptive(const dtReal* pos, const dtReal rad,
137 const dtReal vmax, const dtReal vmult,
138 const dtReal* vel, const dtReal* dvel, dtReal* nvel,
139 const dtObstacleAvoidanceParams* params,
141
142 // [UE] main sampling function
143 inline int sampleVelocity(const dtReal* pos, const dtReal rad,
144 const dtReal vmax, const dtReal vmult,
145 const dtReal* vel, const dtReal* dvel, dtReal* nvel,
146 const dtObstacleAvoidanceParams* params,
148 {
149 return (params->patternIdx == 0xff) ?
150 sampleVelocityAdaptive(pos, rad, vmax, vmult, vel, dvel, nvel, params, debug) :
151 sampleVelocityCustom(pos, rad, vmax, vmult, vel, dvel, nvel, params, debug);
152 }
153
154 inline int getObstacleCircleCount() const { return m_ncircles; }
155 const dtObstacleCircle* getObstacleCircle(const int i) { return &m_circles[i]; }
156
157 inline int getObstacleSegmentCount() const { return m_nsegments; }
158 const dtObstacleSegment* getObstacleSegment(const int i) { return &m_segments[i]; }
159
160 // [UE] sampling pattern count accessors
161 inline int getCustomPatternCount() const { return m_maxPatterns; }
162
163private:
164
165 NAVMESH_API void prepare(const dtReal* pos, const dtReal* dvel);
166
167 NAVMESH_API dtReal processSample(const dtReal* vcand, const dtReal cs,
168 const dtReal* pos, const dtReal rad,
169 const dtReal* vel, const dtReal* dvel,
171
172 NAVMESH_API dtObstacleCircle* insertCircle(const dtReal dist);
173 NAVMESH_API dtObstacleSegment* insertSegment(const dtReal dist);
174
176 dtReal m_invHorizTime;
177 dtReal m_vmax;
178 dtReal m_invVmax;
179
180 dtObstacleAvoidancePattern* m_customPatterns;
181 dtObstacleCircle* m_circles;
182 dtObstacleSegment* m_segments;
183
184 int m_maxPatterns;
185
186 int m_maxCircles;
187 int m_ncircles;
188
189 int m_maxSegments;
190 int m_nsegments;
191};
192
195
196
197#endif // DETOUROBSTACLEAVOIDANCE_H
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
double dtReal
Definition DetourLargeWorldCoordinates.h:15
NAVMESH_API void dtFreeObstacleAvoidanceQuery(dtObstacleAvoidanceQuery *ptr)
Definition DetourObstacleAvoidance.cpp:199
NAVMESH_API dtObstacleAvoidanceDebugData * dtAllocObstacleAvoidanceDebugData()
Definition DetourObstacleAvoidance.cpp:70
NAVMESH_API dtObstacleAvoidanceQuery * dtAllocObstacleAvoidanceQuery()
Definition DetourObstacleAvoidance.cpp:192
NAVMESH_API void dtFreeObstacleAvoidanceDebugData(dtObstacleAvoidanceDebugData *ptr)
Definition DetourObstacleAvoidance.cpp:77
Definition DetourObstacleAvoidance.h:45
const dtReal * getSampleVelocity(const int i) const
Definition DetourObstacleAvoidance.h:58
dtReal getSamplePenalty(const int i) const
Definition DetourObstacleAvoidance.h:60
dtReal getSamplePreferredSidePenalty(const int i) const
Definition DetourObstacleAvoidance.h:63
dtReal getSampleSize(const int i) const
Definition DetourObstacleAvoidance.h:59
NAVMESH_API void reset()
Definition DetourObstacleAvoidance.cpp:139
dtReal getSampleCurrentVelocityPenalty(const int i) const
Definition DetourObstacleAvoidance.h:62
int getSampleCount() const
Definition DetourObstacleAvoidance.h:57
NAVMESH_API bool init(const int maxSamples)
Definition DetourObstacleAvoidance.cpp:109
dtReal getSampleDesiredVelocityPenalty(const int i) const
Definition DetourObstacleAvoidance.h:61
NAVMESH_API void normalizeSamples()
Definition DetourObstacleAvoidance.cpp:182
dtReal getSampleCollisionTimePenalty(const int i) const
Definition DetourObstacleAvoidance.h:64
NAVMESH_API ~dtObstacleAvoidanceDebugData()
Definition DetourObstacleAvoidance.cpp:98
NAVMESH_API dtObstacleAvoidanceDebugData()
Definition DetourObstacleAvoidance.cpp:85
NAVMESH_API void addSample(const dtReal *vel, const dtReal ssize, const dtReal pen, const dtReal vpen, const dtReal vcpen, const dtReal spen, const dtReal tpen)
Definition DetourObstacleAvoidance.cpp:144
Definition DetourObstacleAvoidance.h:109
const dtObstacleSegment * getObstacleSegment(const int i)
Definition DetourObstacleAvoidance.h:158
int sampleVelocity(const dtReal *pos, const dtReal rad, const dtReal vmax, const dtReal vmult, const dtReal *vel, const dtReal *dvel, dtReal *nvel, const dtObstacleAvoidanceParams *params, dtObstacleAvoidanceDebugData *debug=0)
Definition DetourObstacleAvoidance.h:143
NAVMESH_API void addCircle(const dtReal *pos, const dtReal rad, const dtReal *vel, const dtReal *dvel)
Definition DetourObstacleAvoidance.cpp:257
NAVMESH_API bool getCustomSamplingPattern(int idx, dtReal *angles, dtReal *radii, int *nsamples)
Definition DetourObstacleAvoidance.cpp:443
NAVMESH_API dtObstacleAvoidanceQuery()
Definition DetourObstacleAvoidance.cpp:207
int getObstacleSegmentCount() const
Definition DetourObstacleAvoidance.h:157
NAVMESH_API int sampleVelocityAdaptive(const dtReal *pos, const dtReal rad, const dtReal vmax, const dtReal vmult, const dtReal *vel, const dtReal *dvel, dtReal *nvel, const dtObstacleAvoidanceParams *params, dtObstacleAvoidanceDebugData *debug=0)
Definition DetourObstacleAvoidance.cpp:520
int getCustomPatternCount() const
Definition DetourObstacleAvoidance.h:161
NAVMESH_API ~dtObstacleAvoidanceQuery()
Definition DetourObstacleAvoidance.cpp:219
NAVMESH_API bool setCustomSamplingPattern(int idx, const dtReal *angles, const dtReal *radii, int nsamples)
Definition DetourObstacleAvoidance.cpp:428
NAVMESH_API int sampleVelocityCustom(const dtReal *pos, const dtReal rad, const dtReal vmax, const dtReal vmult, const dtReal *vel, const dtReal *dvel, dtReal *nvel, const dtObstacleAvoidanceParams *params, dtObstacleAvoidanceDebugData *debug=0)
Definition DetourObstacleAvoidance.cpp:455
NAVMESH_API void addSegment(const dtReal *p, const dtReal *q, int flags=0)
Definition DetourObstacleAvoidance.cpp:270
NAVMESH_API void reset()
Definition DetourObstacleAvoidance.cpp:251
const dtObstacleCircle * getObstacleCircle(const int i)
Definition DetourObstacleAvoidance.h:155
int getObstacleCircleCount() const
Definition DetourObstacleAvoidance.h:154
NAVMESH_API bool init(const int maxCircles, const int maxSegments, const int maxCustomPatterns)
Definition DetourObstacleAvoidance.cpp:226
Definition DetourObstacleAvoidance.h:87
dtReal weightToi
Definition DetourObstacleAvoidance.h:92
dtReal velBias
Definition DetourObstacleAvoidance.h:88
dtReal horizTime
Definition DetourObstacleAvoidance.h:93
unsigned char adaptiveDepth
adaptive
Definition DetourObstacleAvoidance.h:97
unsigned char patternIdx
[UE] index of custom sampling pattern or 0xff for adaptive
Definition DetourObstacleAvoidance.h:94
dtReal weightSide
Definition DetourObstacleAvoidance.h:91
unsigned char adaptiveDivs
adaptive
Definition DetourObstacleAvoidance.h:95
dtReal weightDesVel
Definition DetourObstacleAvoidance.h:89
unsigned char adaptiveRings
adaptive
Definition DetourObstacleAvoidance.h:96
dtReal weightCurVel
Definition DetourObstacleAvoidance.h:90
Definition DetourObstacleAvoidance.h:102
int nsamples
Number of samples.
Definition DetourObstacleAvoidance.h:105
dtReal angles[DT_MAX_CUSTOM_SAMPLES]
sample's angle (radians) from desired velocity direction
Definition DetourObstacleAvoidance.h:103
dtReal radii[DT_MAX_CUSTOM_SAMPLES]
sample's radius (0...1)
Definition DetourObstacleAvoidance.h:104
Definition DetourObstacleAvoidance.h:29
dtReal p[3]
Position of the obstacle.
Definition DetourObstacleAvoidance.h:30
dtReal dvel[3]
Velocity of the obstacle.
Definition DetourObstacleAvoidance.h:32
dtReal np[3]
Use for side selection during sampling.
Definition DetourObstacleAvoidance.h:34
dtReal vel[3]
Velocity of the obstacle.
Definition DetourObstacleAvoidance.h:31
dtReal dp[3]
Definition DetourObstacleAvoidance.h:34
dtReal rad
Radius of the obstacle.
Definition DetourObstacleAvoidance.h:33
Definition DetourObstacleAvoidance.h:38
unsigned char canIgnore
Definition DetourObstacleAvoidance.h:41
dtReal p[3]
Definition DetourObstacleAvoidance.h:39
dtReal q[3]
End points of the obstacle segment.
Definition DetourObstacleAvoidance.h:39
unsigned char touch
Definition DetourObstacleAvoidance.h:40