-
Notifications
You must be signed in to change notification settings - Fork 0
/
BoundedDynamicSeparation.cpp
40 lines (32 loc) · 1.22 KB
/
BoundedDynamicSeparation.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
35
36
37
38
39
40
#include <vector>
#include "BoundedDynamicSeparation.hpp"
#include "Mobile.hpp"
#include "Triple.hpp"
#define DEBUG_BOUNDEDDYNAMICSEPARATION
#ifdef DEBUG_BOUNDEDDYNAMICSEPARATION
# include <iostream>
# define DEBUG_SEPARATION_PRINT(S) std::cout << "DEBUG: Separation " << reinterpret_cast<void *>(this) << ": " #S << " == " << S << std::endl;
#else
# define DEBUG_SEPARATION_PRINT(S)
#endif
BoundedDynamicSeparation::BoundedDynamicSeparation(std::string name, Mobile *character, Mobile *target, double maxForce, double separationRadius):
DynamicV(name),
character(character),
target(target),
maxForce(maxForce),
separationRadius(separationRadius)
{}
std::vector<Triple> BoundedDynamicSeparation::getForce(unsigned int ticks, unsigned int delta_ticks) {
Triple steering;
double d;
Triple cp, tp;
std::tie(cp, tp) = points(character, target);
steering = cp - tp;
d = steering.length();
DEBUG_SEPARATION_PRINT(d);
if (0 < d && d < separationRadius) {
steering *= maxForce * (d / separationRadius);
return std::vector<Triple>(1, steering);
}
return std::vector<Triple>();
}