-
Notifications
You must be signed in to change notification settings - Fork 0
/
KinematicArrive.cpp
34 lines (27 loc) · 982 Bytes
/
KinematicArrive.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <vector>
#include "Ent.hpp"
#include "KinematicArrive.hpp"
#include "Triple.hpp"
const double KinematicArrive::timeToTarget;
KinematicArrive::KinematicArrive(std::string name, Ent *character, Ent *target, double maxSpeed, double radius):
DirectKinematicV(name),
character(character),
target(target),
maxSpeed(maxSpeed),
radius(radius)
{}
std::vector<Triple> KinematicArrive::getVel(unsigned int ticks, unsigned int delta_ticks) {
Triple steering;
Triple cp, tp;
std::tie(cp, tp) = points(this->character, this->target);
steering = tp - cp;
if (steering.length() > radius) {
steering /= timeToTarget;
if (steering.length() > maxSpeed) {
steering.normalized();
steering *= maxSpeed;
}
return std::vector<Triple>(1, steering);
}
return std::vector<Triple>();
}