-
Notifications
You must be signed in to change notification settings - Fork 0
/
DynamicSeparation.cpp
40 lines (32 loc) · 1.19 KB
/
DynamicSeparation.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 "DynamicSeparation.hpp"
#include "Mobile.hpp"
#include "Triple.hpp"
//#define DEBUG_DYNAMICSEPARATION
#ifdef DEBUG_DYNAMICSEPARATION
# include <iostream>
# define DEBUG_SEPARATION_PRINT(S) std::cout << "DEBUG: DynamicSeparation " << reinterpret_cast<void *>(this) << ": " #S << " == " << S << std::endl;
#else
# define DEBUG_SEPARATION_PRINT(S)
#endif
DynamicSeparation::DynamicSeparation(std::string name, Mobile *character, Mobile *target, double minForce, double separationRadius):
DynamicV(name),
character(character),
target(target),
minForce(minForce),
separationRadius(separationRadius)
{}
std::vector<Triple> DynamicSeparation::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 *= (minForce * separationRadius) / d;
return std::vector<Triple>(1, steering);
}
return std::vector<Triple>();
}