Allolib  1.0
C++ Components For Interactive Multimedia
al_BoundingBox.hpp
1 
2 #ifndef AL_BOUNDINGBOX_HPP
3 #define AL_BOUNDINGBOX_HPP
4 
5 #include <limits>
6 
7 #include "al/graphics/al_Graphics.hpp"
8 #include "al/graphics/al_Mesh.hpp"
9 #include "al/graphics/al_Shapes.hpp"
10 #include "al/math/al_Vec.hpp"
11 
12 namespace al {
13 
15 
17  Vec3f min, max;
18  Vec3f cen, dim;
19 
21  BoundingBoxData(const Vec3f &min_, const Vec3f &max_);
22 
23  void set(const Vec3f &min_, const Vec3f &max_);
24 
25  void setCenterDim(const Vec3f &cen_, const Vec3f &dim_);
26 
27  bool contains(const Vec3d &p);
28 
29  inline void reset();
30 
36  inline void resetInv() {
37  max = {std::numeric_limits<float>::lowest(),
38  std::numeric_limits<float>::lowest(),
39  std::numeric_limits<float>::lowest()};
42  }
43 
44  inline void includePoint(al::Vec3f &pos) {
45  if (pos.x > max.x) {
46  max.x = pos.x;
47  } else if (pos.x < min.x) {
48  min.x = pos.x;
49  }
50  if (pos.y > max.y) {
51  max.y = pos.y;
52  } else if (pos.y < min.y) {
53  min.y = pos.y;
54  }
55  if (pos.z > max.z) {
56  max.z = pos.z;
57  } else if (pos.z < min.z) {
58  min.z = pos.z;
59  }
60  }
61 };
62 
65 struct BoundingBox : public BoundingBoxData {
66  Mesh mesh, tics, gridMesh[2];
67  float glUnitLength;
68  float ticsPerUnit;
69 
70  BoundingBox();
71 
72  BoundingBox(const Vec3f &min_, const Vec3f &max_);
73 
74  // set bounds from mesh
75  void set(const Mesh &mesh);
76 
77  void set(const Vec3f &min_, const Vec3f &max_);
78 
79  void setCenterDim(const Vec3f &cen_, const Vec3f &dim_);
80 
81  Mesh &getMesh();
82 
83  void draw(Graphics &g, bool drawTics = false);
84 
85  // tic marks
86  Mesh &getTics();
87 };
88 
89 } // namespace al
90 
91 #endif // AL_BOUNDINGBOX_HPP
Interface for loading fonts and rendering text.
Definition: al_Graphics.hpp:63
Stores buffers related to rendering graphical objects.
Definition: al_Mesh.hpp:62
T min(const T &v1, const T &v2, const T &v3)
T max(const T &v1, const T &v2, const T &v3)
Definition: al_App.hpp:23
void resetInv()
reset box to float value inverse extremes