gramods
AABB.hh
1 
2 #ifndef GRAMODS_GRAPHICS_AABB
3 #define GRAMODS_GRAPHICS_AABB
4 
5 #include <gmGraphics/config.hh>
6 #include <gmGraphics/IntersectionVisitor.hh>
7 
8 #include <Eigen/Eigen>
9 
10 BEGIN_NAMESPACE_GMGRAPHICS;
11 
15 class AABB {
16 
17 public:
18  AABB(const AABB &bb) : bmin(bb.bmin), bmax(bb.bmax) {}
19  AABB(const Eigen::Vector3f &p) : bmin(p), bmax(p) {}
20  AABB(const AABB &bb, const Eigen::Vector3f &p)
21  : bmin(bb.bmin.cwiseMin(p)), bmax(bb.bmax.cwiseMax(p)) {}
22  AABB(const AABB &op1, const AABB &op2)
23  : bmin(op1.bmin.cwiseMin(op2.bmin)), bmax(op1.bmax.cwiseMax(op2.bmax)) {}
24 
25  AABB operator+(const Eigen::Vector3f &op) { return AABB(*this, op); }
26  AABB operator+(const AABB &op) { return AABB(*this, op); }
27  AABB &operator+=(const Eigen::Vector3f &op) { return *this = *this + op; }
28  AABB &operator+=(const AABB &op) { return *this = *this + op; }
29 
30  const Eigen::Vector3f &min() const { return bmin; }
31  const Eigen::Vector3f &max() const { return bmax; }
32 
33  Eigen::Vector3f getCenter() { return 0.5f * (bmax + bmin); }
34 
35  AABB &addOffset(const Eigen::Vector3f &op) {
36  bmax += op;
37  bmin += op;
38  return *this;
39  }
40 
41  std::vector<Eigen::Vector3f> getCorners() const {
42  return {
43  Eigen::Vector3f(bmin.x(), bmin.y(), bmin.z()),
44  Eigen::Vector3f(bmin.x(), bmin.y(), bmax.z()),
45  Eigen::Vector3f(bmin.x(), bmax.y(), bmin.z()),
46  Eigen::Vector3f(bmin.x(), bmax.y(), bmax.z()),
47  Eigen::Vector3f(bmax.x(), bmin.y(), bmin.z()),
48  Eigen::Vector3f(bmax.x(), bmin.y(), bmax.z()),
49  Eigen::Vector3f(bmax.x(), bmax.y(), bmin.z()),
50  Eigen::Vector3f(bmax.x(), bmax.y(), bmax.z()),
51  };
52  }
53 
58 
62  bool isIntersecting(const Line &line);
63 
69  std::vector<float> getIntersections(const Line &line);
70 
71 private:
72  Eigen::Vector3f bmin;
73  Eigen::Vector3f bmax;
74 };
75 
76 END_NAMESPACE_GMGRAPHICS;
77 
78 #endif
Axis aligned bounding box values with operations.
Definition: AABB.hh:15
IntersectionLine Line
Line for intersection checking.
Definition: AABB.hh:57
Line for intersection with ray or segment.
Definition: IntersectionLine.hh:15