-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoid.cpp
60 lines (51 loc) · 1.4 KB
/
Boid.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "Boid.h"
Boid::Boid(glm::vec3 startPosition)
{
this->position = startPosition;
this->velocity = glm::vec3(1, 0, 0);
this->wanderAngle = 0;
this->centerDistance = glm::length(this->position);
this->currentTarget = this->position;
}
void Boid::AddAcceleration(glm::vec3 acc)
{
this->velocity += acc;
}
void Boid::Seek(glm::vec3 target)
{
// Find the direction target - this->velocity;
//
this->AddAcceleration(target - this->velocity);
}
void Boid::SphericalWander(float sphereRadius)
{
if(frameCounter >= 100)
{
this->currentTarget = Mathematics::GetRandomPointOnSphere(sphereRadius);
frameCounter = 0;
}
this->Seek(this->currentTarget);
}
void Boid::Update()
{
this->SphericalWander(this->centerDistance);
//std::cout << "Wander Angle: " << this->wanderAngle << std::endl;
this->SetSpherePosition(glm::normalize(this->velocity) * steeringIntensity);
frameCounter++;
}
glm::vec3 Boid::GetPosition()
{
return position;
}
void Boid::Draw(Shader& shader, Camera& camera, Mesh& mesh)
{
this->Update();
//std::cout << "Boid at: ";
//Utils::showGlmVec3(this->position);
mesh.DrawInstance(shader, camera, mesh.matrix, this->position, mesh.rotation, mesh.scale);
}
void Boid::SetSpherePosition(glm::vec3 vel)
{
this->position += vel;
this->position = glm::normalize(this->position) * this->centerDistance;
}