-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuadTree.h
88 lines (69 loc) · 2.11 KB
/
QuadTree.h
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
#pragma once
#include "Entity.h"
// Axis Aligned Bounding Box
struct AABB
{
float x, y;
float w, h;
bool Contains(const Entity* point)
{
XMFLOAT3 pos = point->GetPositionFloat3();
return (pos.x >= this->x - this->w &&
pos.x <= this->x + this->w &&
pos.y >= this->y - this->h &&
pos.y <= this->y + this->h);
}
};
class QuadTreeNode
{
public:
// Enumeration for the quadrants
enum EQuadrant
{
NE = 0,
NW,
SW,
SE,
NONE
};
QuadTreeNode(const XMFLOAT2& min, const XMFLOAT2& max, QuadTreeNode* parent);
~QuadTreeNode();
bool IsRoot() const;
bool IsExternal() const;
bool WasTooClose() const;
int GetNumRenegades() const;
int GetNum() const;
const XMFLOAT2& GetCenterOfMass() const;
const XMFLOAT2& GetMin() const;
const XMFLOAT2& GetMax() const;
double GetTheta() const;
void SetTheta(double theta);
EQuadrant GetQuadrant(float x, float y) const;
QuadTreeNode* CreateQuadNode(EQuadrant eQuad);
void Reset(const XMFLOAT2& min, const XMFLOAT2& max);
void Insert(Entity* newParticle, int level);
void ComputeMassDistribution();
XMFLOAT2 CalcAcc(Entity* p1, Entity* p2) const;
XMFLOAT2 CalcForce(Entity* particle) const;
XMFLOAT2 CalcTreeForce(Entity* particle) const;
void DrawEntities(const XMMATRIX& viewProjectionMatrix);
void ReleaseEntities();
private:
Entity* _assignedEntity;
float _mass; // mass of all particles inside the node
XMFLOAT2 _cm; // center of Mass
XMFLOAT2 _min; // upper left edge of the node
XMFLOAT2 _max; // lower right edge of the node
XMFLOAT2 _center; // center of the node
QuadTreeNode* _parent; // the parent node
int _num; // the number of particles in this node
mutable bool _bSubdivided; // true if this node is too close to use the approximation for the force calculation
std::vector<Entity*> s_renegades;
QuadTreeNode* _quadNode[4];
public:
double s_theta = 0.9;
double s_soft = 0.1 * 0.1;
float s_range = 1000.0f;
float s_attractionThreshold = 3.0f;
double gamma_1 = 6.673e-11 / (3.08567758129e16 * 3.08567758129e16 * 3.08567758129e16) * 1.988435e30 * (365.25 * 86400) * (365.25 * 86400);
};