-
Notifications
You must be signed in to change notification settings - Fork 1
/
CollisionManager.cpp
52 lines (43 loc) · 1.79 KB
/
CollisionManager.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
#include "CollisionManager.h"
#include "ModelContainer.h"
#include "MyHelpers.h"
int CollisionManager::AddContainer(ModelContainer* container)
{
containers.push_back(container);
return containers.size() - 1;
}
void CollisionManager::RemoveContainer(ModelContainer* container)
{
auto containerLocation = find(containers.begin(), containers.end(), container);
if (containerLocation != containers.end())
containers.erase(containerLocation);
}
bool CollisionManager::IsColliding(ModelContainer* container, int index)
{
// In our bounding box vertices, the 1st vertex contains the minimum
// values (minX, minY, and minZ), and the 7th vertex contains the
// maximum values (maxX, maxY, and maxZ)
glm::vec3 targetMinVertices = container->GetMinimumVertices();
glm::vec3 targetMaxVertices = container->GetMaximumVertices();
// Used for debugging
// cout << "index = " << index << endl;
// cout << "\ttargetMinVer = " << targetMinVertices << endl;
// cout << "\ttargetMaxVer = " << targetMaxVertices << endl;
vector<glm::vec3> boundingBox;
glm::vec3 minVertices, maxVertices;
for (int i = 0; i < containers.size(); i++)
{
if (i == index)
continue;
minVertices = containers[i]->GetMinimumVertices();
maxVertices = containers[i]->GetMaximumVertices();
// Used for debugging
// cout << "\tminVer = " << minVertices << endl;
// cout << "\tmaxVer = " << maxVertices << endl;
if (targetMinVertices.x < maxVertices.x && targetMaxVertices.x > minVertices.x &&
targetMinVertices.y < maxVertices.y && targetMaxVertices.y > minVertices.y &&
targetMinVertices.z < maxVertices.z && targetMaxVertices.z > minVertices.z)
return true;
}
return false;
}