-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboid_simulator.h
More file actions
51 lines (32 loc) · 1.15 KB
/
boid_simulator.h
File metadata and controls
51 lines (32 loc) · 1.15 KB
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
43
44
45
46
47
48
49
50
#pragma once
#include <vector>
#include <SDL_render.h>
#include "vector2.h"
#include "utility.h"
struct Boid {
Vector2 position;
Vector2 velocity;
};
struct SimulationConfiguration {
float separation_force = 0.05;
float cohesion_force = 0.05;
float alignment_force = 0.005;
float maximal_speed = 8;
float visual_range = 75;
float boid_margin = 20;
};
class BoidSimulator {
public:
std::vector<Boid> boids;
void Render(SDL_Renderer* renderer, SDL_Texture* boid_texture);
void Advance(SDL_Window* window, SimulationConfiguration* configuration);
void Repopulate(int amount, int spawn_area_width, int spawn_area_height);
private:
void AvoidEdges(Boid* boid, int screen_width, int screen_height, float visual_range);
void PortalEdges(Boid* boid, int screen_width, int screen_height);
void LimitSpeed(Boid* boid, float max_speed);
void Separation(Boid* boid, float force, float BoidPersonalSpace);
void Alignment(Boid* boid, float force, float visual_range);
void Cohesion(Boid* boid, float force, float visual_range);
double VelocityToAngle(double xv, double yv);
};