blob: b85d14029525f190c051531a6701e083eec4af8c (
plain)
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
41
42
|
#include "RandomSpawner.h"
#include <cmath>
#include <kurator/battles/components.h>
#include <kurator/battles/Point.h>
namespace kurator
{
namespace battles
{
RandomSpawner::RandomSpawner(const int total_teams, const double distance, const double variation) :
angle_step {2.0 * M_PI / total_teams},
device {},
distribution_d {distance - distance * variation, distance + distance * variation},
distribution_a {-variation * M_PI, variation * M_PI}
{
}
Transform
RandomSpawner::get(const int team)
{
const double distance = distribution_d(device);
const double clean_angle = angle_step * team;
const double angle = clean_angle + distribution_a(device);
double facing = clean_angle + M_PI;
if (facing > 2 * M_PI)
facing -= 2 * M_PI;
const Point position {
distance * std::cos(angle),
distance * std::sin(angle),
};
return {position, facing};
}
} // namespace battles
} // namespace kurator
|