blob: a0b0f784a32d7386ab782fdedd5bc1b5d62992db (
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/engine/Point.h>
#include <kurator/sim/components.h>
namespace kurator
{
namespace sim
{
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 = M_PI + 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 engine::Point position {
distance * std::cos(angle),
distance * std::sin(angle),
};
return {position, facing};
}
} // namespace sim
} // namespace kurator
|