MCPcopy Create free account
hub / github.com/REGoth-project/REGoth / getWaypointOnPath

Method getWaypointOnPath

src/engine/Waynet.cpp:200–227  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

198}
199
200size_t World::Waynet::getWaypointOnPath(const WaynetInstance& waynet, const std::vector<size_t>& path, float p)
201{
202 if (path.size() == 1)
203 return 0;
204
205 if (p >= 1.0f)
206 return path.size() - 1;
207
208 float pathLength = getPathLength(waynet, path);
209 float traveled = pathLength * p;
210
211 float d = 0.0f;
212 for (size_t i = 0; i < path.size() - 1; i++)
213 {
214 // Check if the percentage-value is inside the current region
215 float len = (waynet.waypoints[path[i]].position - waynet.waypoints[path[i + 1]].position).length();
216
217 if (d <= traveled && traveled < d + len)
218 {
219 float mid = (d + d + len) * 0.5f;
220 return traveled < mid ? i : i + 1;
221 }
222
223 d += len;
224 }
225
226 return static_cast<size_t>(-1);
227}
228
229size_t World::Waynet::findNearestWaypointTo(const WaynetInstance& waynet, const Math::float3& position)
230{

Callers

nothing calls this directly

Calls 2

lengthMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected