-
Notifications
You must be signed in to change notification settings - Fork 0
/
Boid.hpp
43 lines (33 loc) · 1.2 KB
/
Boid.hpp
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
#pragma once
#include <vector>
#include <cmath>
#include "Math.hpp"
#include "Obstacle.hpp"
#include "olcPixelGameEngine.h"
class Boid final
{
public:
static constexpr float speed = 100.0f;
static constexpr float turnSpeed = 6.0f;
static constexpr float visionRange = 75.0f;
static constexpr float alignment = 1.0f;
static constexpr float coherence = 1.0f;
static constexpr float seperation = 4.0f;
static constexpr float obstacleAvoidance = 12.0f;
public:
void Update(const std::vector<Boid> &nearbyBoids, const std::vector<Obstacle> &nearbyObstacles, const float dt);
void SetPosition(const olc::vf2d &position);
olc::vf2d GetPosition() const;
void SetVelocity(const olc::vf2d &velocity);
olc::vf2d GetVelocity() const;
float Distance(const Boid &otherBoid) const;
private:
void Steer(const olc::vf2d &desiredVelocity, const float dt, const float modifier = 1.0f);
void Align(const std::vector<Boid> &nearbyBoids, const float dt);
void Cohere(const std::vector<Boid> &nearbyBoids, const float dt);
void Seperate(const std::vector<Boid> &nearbyBoids, const float dt);
void Avoid(const std::vector<Obstacle> &nearbyObstacles, const float dt);
private:
olc::vf2d position;
olc::vf2d velocity;
};