forked from c-f-h/vpinball
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kdtree.h
87 lines (58 loc) · 2.04 KB
/
kdtree.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
#pragma once
#include "pin/ball.h"
#include "pin/collide.h"
#define KDTREE_SSE_LEAFTEST
class HitKD;
class HitKDNode
{
private:
void Reset() { m_children = NULL; m_hitoct = NULL; m_start = 0; m_items = 0; }
void HitTestBall(Ball * const pball, CollisionEvent& coll) const;
void HitTestXRay(Ball * const pball, Vector<HitObject> * const pvhoHit, CollisionEvent& coll) const;
void CreateNextLevel();
#ifdef KDTREE_SSE_LEAFTEST
void HitTestBallSse(Ball * const pball, CollisionEvent& coll) const;
void HitTestBallSseInner(Ball * const pball, const int i, CollisionEvent& coll) const;
#endif
FRect3D m_rectbounds;
unsigned int m_start;
unsigned int m_items; // contains the 2 bits for axis (bits 30/31)
HitKDNode * m_children; // if NULL, is a leaf; otherwise keeps the 2 children
HitKD * m_hitoct; //!! meh, stupid
friend class HitKD;
};
class HitKD
{
public:
HitKD();
~HitKD();
void Init(Vector<HitObject> *vho, const unsigned int num_items);
void AddElementByIndex(unsigned i)
{ m_org_idx.push_back( i ); }
void FillFromVector(Vector<HitObject>& vho);
void FillFromIndices();
void FillFromIndices(const FRect3D& initialBounds);
// call when the bounding boxes of the HitObjects have changed to update the tree
void Update();
void HitTestBall(Ball * const pball, CollisionEvent& coll) const
{ m_rootNode.HitTestBallSse(pball, coll); }
void HitTestXRay(Ball * const pball, Vector<HitObject> * const pvhoHit, CollisionEvent& coll) const
{ m_rootNode.HitTestXRay(pball, pvhoHit, coll); }
private:
void InitSseArrays();
std::vector<unsigned int> m_org_idx;
HitKDNode m_rootNode;
unsigned int m_num_items;
unsigned int m_max_items;
HitObject* GetItemAt(unsigned i)
{ return m_org_vho->ElementAt( m_org_idx[i] ); }
HitKDNode* AllocTwoNodes();
Vector<HitObject> *m_org_vho;
std::vector<unsigned int> tmp;
#ifdef KDTREE_SSE_LEAFTEST
float * __restrict l_r_t_b_zl_zh;
#endif
std::vector< HitKDNode > m_nodes;
unsigned m_num_nodes;
friend class HitKDNode;
};