| 356 | } |
| 357 | |
| 358 | void CPHMovementControl::PathNearestPoint(const xr_vector<DetailPathManager::STravelPathPoint>& path, // in path |
| 359 | const Fvector& new_position, // in position |
| 360 | int& index, // in start from; out nearest |
| 361 | bool& near_line // out type |
| 362 | ) |
| 363 | { |
| 364 | Fvector from_first, from_second, dir; |
| 365 | bool after_line = true; // to check first point |
| 366 | |
| 367 | Fvector path_point, vtemp; |
| 368 | float temp; |
| 369 | int i = 0; |
| 370 | |
| 371 | for (; i < m_path_size - 1; ++i) |
| 372 | { |
| 373 | const Fvector &first = path[i].position, &second = path[i + 1].position; |
| 374 | from_first.sub(new_position, first); |
| 375 | from_second.sub(new_position, second); |
| 376 | dir.sub(second, first); |
| 377 | dir.normalize_safe(); |
| 378 | |
| 379 | if (from_first.dotproduct(dir) < 0.f) // befor this line |
| 380 | { |
| 381 | if (after_line) // after previous line && befor this line = near first point |
| 382 | { |
| 383 | vtemp.sub(new_position, first); |
| 384 | temp = vtemp.magnitude(); |
| 385 | if (temp < m_path_distance) |
| 386 | { |
| 387 | m_path_distance = temp; |
| 388 | index = i; |
| 389 | vPathPoint.set(first); |
| 390 | SetPathDir(dir); |
| 391 | near_line = false; |
| 392 | } |
| 393 | } |
| 394 | after_line = false; |
| 395 | } |
| 396 | else // after first |
| 397 | { |
| 398 | if (from_second.dotproduct(dir) < 0.f) // befor second && after first = near line |
| 399 | { |
| 400 | // temp=dir.dotproduct(new_position); seems to be wrong |
| 401 | temp = dir.dotproduct(from_first); |
| 402 | vtemp.set(dir); |
| 403 | vtemp.mul(temp); |
| 404 | path_point.add(vtemp, first); |
| 405 | vtemp.sub(path_point, new_position); |
| 406 | temp = vtemp.magnitude(); |
| 407 | if (temp < m_path_distance) |
| 408 | { |
| 409 | m_path_distance = temp; |
| 410 | index = i; |
| 411 | vPathPoint.set(path_point); |
| 412 | SetPathDir(dir); |
| 413 | near_line = true; |
| 414 | } |
| 415 | } |
nothing calls this directly
no test coverage detected