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
|
#ifndef UNIFORMGRID_H
#define UNIFORMGRID_H
#include "Game/Components/CollisionComponents/BoundingTriangle.h"
#include "Game/GameObjects/GameObject.h"
#include <set>
#include <vector>
struct GridSquare {
Bounds3f bounds;
glm::vec3 centroid = (bounds.max - bounds.min)/ 2.f;
// bool operator<( const GridSquare & s ) const {
// return glm::all(glm::lessThan(this->bounds.min,s.bounds.min)); // for example
// }
};
//bool operator<(const GridSquare& l, const GridSquare& r)
//{
// return glm::all(glm::lessThan(l.bounds.min, r.bounds.min));
//}
//bool operator==(const GridSquare& l, const GridSquare& r)
//{
// return l.bounds.min == r.bounds.min;
//}
//bool operator<(const glm::vec3& l, const glm::vec3& r)
//{
// return glm::all(glm::lessThan(l, r));;
//}
//bool operator==(const glm::vec3& l, const glm::vec3& r)
//{
// return glm::all(glm::equal(l, r));;
//}
class UniformGrid
{
public:
UniformGrid(std::map<std::string, std::shared_ptr<GameObject>>& dynamic_gameobjects);
std::set<std::set<std::string>> detectPossibleCollisions();
void updateAllGrid();
private:
void populateContainingCell(glm::vec3 bound_corner, std::string entity_id);
void updateUniformGrid(const std::pair<std::string, std::shared_ptr<GameObject>> &go);
void moveEntityGridPosition(const std::pair<std::string, std::shared_ptr<GameObject>> &go);
void initializeGrid();
std::string vecToString(glm::vec3 v);
std::map<std::string, std::shared_ptr<GameObject>>& m_dynamic_gameobjects;
// maps square corner to set of strings
std::map<std::string, std::set<std::string>> m_grid_map;
glm::vec3 m_square_dimensions;
};
#endif // UNIFORMGRID_H
|