Voxellancer  0.3
A game about voxels in space
 All Classes Functions Pages
voxelclusterbounds.h
1 #pragma once
2 
3 #include <set>
4 
5 #include "geometry/aabb.h"
6 #include "geometry/gridaabb.h"
7 #include "geometry/sphere.h"
8 
9 #include "voxelgridcmp.h"
10 
11 
12 class Voxel;
13 class VoxelCluster;
14 
15 /*
16  This class stores and calculates bound-informations of
17  a voxelcluster. It is optimized for speed which means:
18 
19  * It uses sorted sets on each axis to be able to recalc the GridAABBB fast on voxel addition or removal
20  * The aabb is only recalculated if the cluster or the passed transform changes, since it is very likely that
21  the same transform will be queried multiple times during e.g. Worldtreequeries and collisiondetection
22  * The aabb is stored in an I(nteger)AABB because it is only an estimation anyway and calculation on integers
23  are faster than on float AND this function is queried quite frequently
24 */
26 public:
27  VoxelClusterBounds(VoxelCluster* voxelCluster);
28 
29  void addVoxel(Voxel* voxel);
30  void removeVoxel(Voxel* voxel);
31 
32  const GridAABB& minimalGridAABB();
33  const Sphere& minimalGridSphere();
34 
35  /*
36  The aabb is stored in an I(nteger)AABB because it is only an estimation anyway and calculation on integers
37  are faster than on float AND this function is queried quite frequently
38  */
39  const IAABB& aabb();
40  IAABB aabb(const Transform& transform);
41 
42  const Sphere& sphere();
43  Sphere sphere(const Transform& transform);
44 
45 
46 
47 protected:
48  VoxelCluster* m_voxelCluster;
49 
50  std::set<Voxel*, VoxelGridCmp<XAxis, YAxis, ZAxis>> m_voxelsXSorted;
51  std::set<Voxel*, VoxelGridCmp<YAxis, XAxis, ZAxis>> m_voxelsYSorted;
52  std::set<Voxel*, VoxelGridCmp<ZAxis, XAxis, YAxis>> m_voxelsZSorted;
53 
54  void calculateMinimalGridAABB();
55  void calculateMinimalGridSphere();
56  const IAABB calculateAABB(const Transform& transform);
57 
58 
59 private:
60  GridAABB m_minimalGridAABB;
61  bool m_minimalGridAABBValid;
62 
63  Sphere m_minimalGridSphere;
64  bool m_minimalGridSphereValid;
65 
66  IAABB m_aabb;
67  Transform m_cachedAABBTransform;
68  bool m_aabbValid;
69 
70  Sphere m_sphere;
71 };
72 
Definition: voxelcluster.h:21
Definition: transform.h:9
Definition: voxelclusterbounds.h:25
Definition: voxel.h:15
Definition: gridaabb.h:12
Definition: sphere.h:11