Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
BoundingIntervalHierarchyWrapper.h
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#ifndef _BIH_WRAP
7#define _BIH_WRAP
8
9#include "G3D/Table.h"
10#include "G3D/Array.h"
11#include "G3D/Set.h"
13
14
15template<class T, class BoundsFunc = BoundsTrait<T> >
17{
18 template<class RayCallback>
20 {
21 const T* const* objects;
22 RayCallback& _callback;
24
25 MDLCallback(RayCallback& callback, const T* const* objects_array, uint32 objects_size ) : objects(objects_array), _callback(callback), objects_size(objects_size) { }
26
28 bool operator() (const G3D::Ray& ray, uint32 idx, float& maxDist, bool /*stopAtFirst*/)
29 {
30 if (idx >= objects_size)
31 return false;
32 if (const T* obj = objects[idx])
33 return _callback(ray, *obj, maxDist/*, stopAtFirst*/);
34 return false;
35 }
36
38 void operator() (const G3D::Vector3& p, uint32 idx)
39 {
40 if (idx >= objects_size)
41 return;
42 if (const T* obj = objects[idx])
43 _callback(p, *obj);
44 }
45 };
46
47 typedef G3D::Array<const T*> ObjArray;
48
51 G3D::Table<const T*, uint32> m_obj2Idx;
52 G3D::Set<const T*> m_objects_to_push;
54
55public:
57
58 void insert(const T& obj)
59 {
61 m_objects_to_push.insert(&obj);
62 }
63
64 void remove(const T& obj)
65 {
67 uint32 Idx = 0;
68 const T * temp;
69 if (m_obj2Idx.getRemove(&obj, temp, Idx))
70 m_objects[Idx] = NULL;
71 else
72 m_objects_to_push.remove(&obj);
73 }
74
75 void balance()
76 {
77 if (unbalanced_times == 0)
78 return;
79
81 m_objects.fastClear();
82 m_obj2Idx.getKeys(m_objects);
83 m_objects_to_push.getMembers(m_objects);
84 //assert that m_obj2Idx has all the keys
85
86 m_tree.build(m_objects, BoundsFunc::getBounds2);
87 }
88
89 template<typename RayCallback>
90 void intersectRay(const G3D::Ray& ray, RayCallback& intersectCallback, float& maxDist)
91 {
92 balance();
93 MDLCallback<RayCallback> temp_cb(intersectCallback, m_objects.getCArray(), m_objects.size());
94 m_tree.intersectRay(ray, temp_cb, maxDist, true);
95 }
96
97 template<typename IsectCallback>
98 void intersectPoint(const G3D::Vector3& point, IsectCallback& intersectCallback)
99 {
100 balance();
101 MDLCallback<IsectCallback> callback(intersectCallback, m_objects.getCArray(), m_objects.size());
102 m_tree.intersectPoint(point, callback);
103 }
104};
105
106#endif // _BIH_WRAP
std::uint32_t uint32
Definition Define.h:77
G3D::Table< const T *, uint32 > m_obj2Idx
G3D::Array< const T * > ObjArray
void insert(const T &obj)
G3D::Set< const T * > m_objects_to_push
void remove(const T &obj)
void intersectRay(const G3D::Ray &ray, RayCallback &intersectCallback, float &maxDist)
void intersectPoint(const G3D::Vector3 &point, IsectCallback &intersectCallback)
MDLCallback(RayCallback &callback, const T *const *objects_array, uint32 objects_size)
bool operator()(const G3D::Ray &ray, uint32 idx, float &maxDist, bool)
Intersect ray.