SHOW:
|
|
- or go back to the newest paste.
| 1 | Vector2D edgeAvoidance(Agent &agent, const std::vector<Edge>& edges) | |
| 2 | {
| |
| 3 | int ClosestEdge = -1; | |
| 4 | ||
| 5 | /* What you'd want to do here is iterate through a series of | |
| 6 | * lines connected to the agent ("feelers"; denoted 'flr') and check to see
| |
| 7 | * if they intersect with an edge in the list. Do this and find the closest | |
| 8 | * edge for each of them. Once found, we will calculate the steering force | |
| 9 | * AWAY from said edge.*/ | |
| 10 | ||
| 11 | ... | |
| 12 | ||
| 13 | // for all the "feelers": flr, also iterate through all the edges: curEdge | |
| 14 | {
| |
| 15 | ||
| 16 | if (ClosestEdge >=0) | |
| 17 | {
| |
| 18 | - | Vector2D OverShoot = agent.feelers[flr] - (*curEdge)->getPosition(); |
| 18 | + | Vector2D OverShoot = agent.feelers[flr] - (*curEdge).normal(); |
| 19 | ||
| 20 | /* Create a force in the direction of the edge's normal, with a | |
| 21 | * magnitude of the overshoot*/ | |
| 22 | SteeringForce = edges[ClosestEdge].normal() * OverShoot.length(); | |
| 23 | } | |
| 24 | ||
| 25 | } | |
| 26 | return SteeringForce; | |
| 27 | } |