-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMap.cpp
99 lines (78 loc) · 1.47 KB
/
Map.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#pragma once
#include "stdafx.h"
#include "Map.h"
#include "EPA.h"
#include "Contact.h"
#include "Resolution.h"
#include "SpatialGrid.h"
#include "NSquared.h"
Map::Map(){}
Map::~Map(){}
void Map::Add(Object* Object)
{
Objects.push_back(Object);
}
void Map::Remove(unsigned int ID)
{
auto itr = Objects.begin();
while (itr != Objects.end())
{
if ((*itr)->ID == ID)
{
Objects.erase(itr);
break;
}
itr++;
}
}
void Map::RemoveAll()
{
Objects.clear();
}
int Map::Size()
{
return Objects.size();
}
Object* Map::Get(unsigned int ID)
{
for (int i = 0; i < Objects.size(); i++)
{
if (Objects[i]->ID == ID) { return Objects[i]; }
}
}
void Map::DrawAll(sf::RenderWindow& mainWindow)
{
auto itr = Objects.begin();
for (int i = 0; i < Objects.size(); i++)
{
sf::VertexArray *a = (*itr)->ptr;
mainWindow.draw((*a), (*itr)->matrix);
itr++;
}
}
void Map::UpdateAll()
{
auto itr = Objects.begin();
while (itr != Objects.end())
{
(*itr)->Update();
itr++;
}
}
void Map::Collisions()
{
std::list<std::pair<Object*, Object*>> pairs;
pairs = nsquared.ComputePairs();
for (auto itr = pairs.begin(); itr != pairs.end(); ++itr) {
GJK gjk;
if (gjk.Check(itr->first, itr->second))
{
EPA epa;
epa.Update(itr->first, itr->second, &gjk.simplex);
Contact contacts;
contacts.getPoints(itr->first, itr->second, epa.normal, epa.depth);
Resolution resolution;
resolution.Update(itr->first, itr->second, contacts.clippedPoints, epa.normal);
}
}
}