xoreos  0.0.5
boundingbox.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef COMMON_BOUNDINGBOX_H
26 #define COMMON_BOUNDINGBOX_H
27 
28 #include "glm/mat4x4.hpp"
29 
30 namespace Common {
31 
33 class BoundingBox {
34 public:
35  BoundingBox();
36  ~BoundingBox();
37 
38  void clear();
39 
40  bool empty() const;
41 
42  const glm::mat4 &getOrigin() const;
43 
44  void getMin(float &x, float &y, float &z) const;
45  void getMax(float &x, float &y, float &z) const;
46 
47  float getWidth () const;
48  float getHeight() const;
49  float getDepth () const;
50 
51  bool isIn(float x, float y ) const;
52  bool isIn(float x, float y, float z) const;
53 
54  bool isIn(float x1, float y1, float z1, float x2, float y2, float z2) const;
55 
56  void add(float x, float y, float z);
57  void add(const BoundingBox &box);
58 
59  void translate(float x, float y, float z);
60  void scale (float x, float y, float z);
61 
62  void rotate(float angle, float x, float y, float z);
63 
64  void transform(const glm::mat4 &m);
65 
67  void absolutize();
68 
70  BoundingBox getAbsolute() const;
71 
72 private:
73  bool _empty;
74  bool _absolute;
75 
76  glm::mat4 _origin;
77 
78  float _coords[8][3];
79 
80  float _min[3];
81  float _max[3];
82 
83  inline float getCoordMin(int i) const;
84  inline float getCoordMax(int i) const;
85 
86  bool getIntersection(float fDst1, float fDst2,
87  float x1, float y1, float z1,
88  float x2, float y2, float z2,
89  float &x, float &y, float &z) const;
90  bool inBox(float x, float y, float z, float minX, float minY, float minZ,
91  float maxX, float maxY, float maxZ, int axis) const;
92 };
93 
94 } // End of namespace Common
95 
96 #endif // COMMON_BOUNDINGBOX_H
bool isIn(float x, float y) const
Definition: 2dafile.h:39
float getDepth() const
Get the depth of the bounding box.
void scale(float x, float y, float z)
A bounding box around 3D points.
Definition: boundingbox.h:33
bool empty() const
Definition: boundingbox.cpp:60
const glm::mat4 & getOrigin() const
Definition: boundingbox.cpp:64
float getHeight() const
Get the height of the bounding box.
void getMin(float &x, float &y, float &z) const
Definition: boundingbox.cpp:68
float getCoordMin(int i) const
void getMax(float &x, float &y, float &z) const
Definition: boundingbox.cpp:87
float getWidth() const
Get the width of the bounding box.
void transform(const glm::mat4 &m)
float getCoordMax(int i) const
void absolutize()
Apply the origin transformations directly to the coordinates.
void rotate(float angle, float x, float y, float z)
float _coords[8][3]
Definition: boundingbox.h:78
bool inBox(float x, float y, float z, float minX, float minY, float minZ, float maxX, float maxY, float maxZ, int axis) const
void add(float x, float y, float z)
BoundingBox getAbsolute() const
Return a copy with the origin transformations directly applied to the coordinates.
bool getIntersection(float fDst1, float fDst2, float x1, float y1, float z1, float x2, float y2, float z2, float &x, float &y, float &z) const
void translate(float x, float y, float z)