NGL  6.5
The NCCA Graphics Library
BBox.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 Jon Macey
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 #ifndef BBOX_H_
18 #define BBOX_H_
19 // must include types.h first for Real and GLEW if required
22 #include "Types.h"
23 #include "Vec3.h"
24 #include "Vec4.h"
25 #include "AbstractVAO.h"
26 #include <memory>
27 
28 
29 namespace ngl
30 {
31 
32 //----------------------------------------------------------------------------------------------------------------------
38 //----------------------------------------------------------------------------------------------------------------------
39 
41 {
42 public :
43 
44  //----------------------------------------------------------------------------------------------------------------------
50  //----------------------------------------------------------------------------------------------------------------------
51  BBox(const Vec3 &_center, Real _width,Real _height, Real _depth) noexcept;
52 
53  //----------------------------------------------------------------------------------------------------------------------
61  //----------------------------------------------------------------------------------------------------------------------
62  BBox(Real _minX,Real _maxX,Real _minY,Real _maxY,Real _minZ,Real _maxZ) noexcept;
63  //----------------------------------------------------------------------------------------------------------------------
66  //----------------------------------------------------------------------------------------------------------------------
67  BBox() noexcept;
68  //----------------------------------------------------------------------------------------------------------------------
71  //----------------------------------------------------------------------------------------------------------------------
72  BBox(const BBox &_b) noexcept;
73  BBox& operator=(const BBox &_other);
74  //----------------------------------------------------------------------------------------------------------------------
76  //----------------------------------------------------------------------------------------------------------------------
77  void draw() const noexcept;
78  //----------------------------------------------------------------------------------------------------------------------
81  //----------------------------------------------------------------------------------------------------------------------
82  void setDrawMode(GLenum _mode)noexcept;
83  //----------------------------------------------------------------------------------------------------------------------
85  //----------------------------------------------------------------------------------------------------------------------
86  ~BBox()noexcept;
87  //----------------------------------------------------------------------------------------------------------------------
88  // accesors
90  //----------------------------------------------------------------------------------------------------------------------
91  Real minX()const noexcept { return m_minX;}
92  //----------------------------------------------------------------------------------------------------------------------
94  //----------------------------------------------------------------------------------------------------------------------
95  Real maxX()const noexcept{ return m_maxX;}
96  //----------------------------------------------------------------------------------------------------------------------
98  //----------------------------------------------------------------------------------------------------------------------
99  Real minY()const noexcept{ return m_minY;}
100  //----------------------------------------------------------------------------------------------------------------------
102  //----------------------------------------------------------------------------------------------------------------------
103  Real maxY()const noexcept{ return m_maxY;}
104  //----------------------------------------------------------------------------------------------------------------------
106  //----------------------------------------------------------------------------------------------------------------------
107  Real minZ()const noexcept{ return m_minZ;}
108  //----------------------------------------------------------------------------------------------------------------------
110  //----------------------------------------------------------------------------------------------------------------------
111  Real maxZ()const noexcept{ return m_maxZ;}
112  //----------------------------------------------------------------------------------------------------------------------
114  //----------------------------------------------------------------------------------------------------------------------
115  Vec3 center()const noexcept{ return m_center; }
116  //----------------------------------------------------------------------------------------------------------------------
119  //----------------------------------------------------------------------------------------------------------------------
120  Real width()const noexcept{ return m_width; }
121  //----------------------------------------------------------------------------------------------------------------------
125  //----------------------------------------------------------------------------------------------------------------------
126  void width(Real _w, bool _recalc=true) noexcept;
127  //----------------------------------------------------------------------------------------------------------------------
129  //----------------------------------------------------------------------------------------------------------------------
130  Real height()const noexcept{return m_height;}
131  //----------------------------------------------------------------------------------------------------------------------
135  //----------------------------------------------------------------------------------------------------------------------
136  void height(Real _h, bool _recalc=true) noexcept;
137  //----------------------------------------------------------------------------------------------------------------------
139  //----------------------------------------------------------------------------------------------------------------------
140  Real depth()const noexcept{return m_depth;}
141  //----------------------------------------------------------------------------------------------------------------------
145  //----------------------------------------------------------------------------------------------------------------------
146  void depth(Real _d, bool _recalc=true) noexcept;
147  //----------------------------------------------------------------------------------------------------------------------
149  //----------------------------------------------------------------------------------------------------------------------
150  Vec3 * getNormalArray()noexcept{return &m_norm[0];}
151  //----------------------------------------------------------------------------------------------------------------------
153  //----------------------------------------------------------------------------------------------------------------------
154  Vec3 * getVertexArray()noexcept{return &m_vert[0];}
155  //----------------------------------------------------------------------------------------------------------------------
158  //----------------------------------------------------------------------------------------------------------------------
159  void setCenter(const Vec3 &_center, bool _recalc=true) noexcept;
160  //----------------------------------------------------------------------------------------------------------------------
163  //----------------------------------------------------------------------------------------------------------------------
164  void recalculate() noexcept;
165 
166 protected :
167 
168  //----------------------------------------------------------------------------------------------------------------------
170  //----------------------------------------------------------------------------------------------------------------------
171  void setVAO();
172  //----------------------------------------------------------------------------------------------------------------------
177  //----------------------------------------------------------------------------------------------------------------------
178  Vec3 m_vert[8];
179  //----------------------------------------------------------------------------------------------------------------------
181  //----------------------------------------------------------------------------------------------------------------------
183  //----------------------------------------------------------------------------------------------------------------------
185  //----------------------------------------------------------------------------------------------------------------------
187  //----------------------------------------------------------------------------------------------------------------------
189  //----------------------------------------------------------------------------------------------------------------------
191  //----------------------------------------------------------------------------------------------------------------------
193  //----------------------------------------------------------------------------------------------------------------------
195  //----------------------------------------------------------------------------------------------------------------------
197  //----------------------------------------------------------------------------------------------------------------------
199  //----------------------------------------------------------------------------------------------------------------------
201  //----------------------------------------------------------------------------------------------------------------------
203  //----------------------------------------------------------------------------------------------------------------------
205  //----------------------------------------------------------------------------------------------------------------------
207  //----------------------------------------------------------------------------------------------------------------------
209  //----------------------------------------------------------------------------------------------------------------------
210  Vec3 m_norm[6];
211  //----------------------------------------------------------------------------------------------------------------------
213  //----------------------------------------------------------------------------------------------------------------------
215  //----------------------------------------------------------------------------------------------------------------------
217  //----------------------------------------------------------------------------------------------------------------------
219  //----------------------------------------------------------------------------------------------------------------------
221  //----------------------------------------------------------------------------------------------------------------------
223  //----------------------------------------------------------------------------------------------------------------------
225  //----------------------------------------------------------------------------------------------------------------------
226  std::unique_ptr< AbstractVAO >m_vao;
227  //----------------------------------------------------------------------------------------------------------------------
230  //----------------------------------------------------------------------------------------------------------------------
232 
233 }; // end class
234 } // end namespace
235 
236 #endif
237 
238 //----------------------------------------------------------------------------------------------------------------------
Vec3 m_center
This is the center of the BBox stored for caluculations in other classes s.
Definition: BBox.h:206
unsigned int GLuint
Definition: glew.h:280
Real depth() const noexcept
Depth of the BBox.
Definition: BBox.h:140
Real minY() const noexcept
the min y value of the bbox
Definition: BBox.h:99
GLint GLint GLsizei GLsizei GLsizei depth
Definition: glew.h:1257
Vec3 * getVertexArray() noexcept
the array of verts for the BBox
Definition: BBox.h:154
Real minZ() const noexcept
the min z value of the bbox
Definition: BBox.h:107
main definition of types and namespace
Real m_maxX
the max x value of the bbox
Definition: BBox.h:186
#define NGL_DLLEXPORT
Definition: Types.h:65
Real m_minZ
the min z value of the bbox
Definition: BBox.h:198
Real m_width
Width of the BBox.
Definition: BBox.h:214
Real maxY() const noexcept
the max y value of the bbox
Definition: BBox.h:103
Real m_height
Height of the BBox.
Definition: BBox.h:218
Vec3 * getNormalArray() noexcept
the array of normals for the BBox
Definition: BBox.h:150
Real maxX() const noexcept
the max x value of the bbox
Definition: BBox.h:95
unsigned int GLenum
Definition: glew.h:278
simple Vec3 encapsulates a 3 float object like glsl vec3 but not maths use the Vec3 class for maths a...
Definition: Vec3.h:51
Real m_depth
Depth of the BBox.
Definition: BBox.h:222
implementation files for RibExport class
Definition: AABB.cpp:22
Vec3 center() const noexcept
This is the center of the BBox stored for caluculations in other classes s.
Definition: BBox.h:115
Real width() const noexcept
accessor for the width of the BBox
Definition: BBox.h:120
PRECISION Real
create a variable called Real which is the main data type we use (GLfloat for most cases) ...
Definition: Types.h:127
encapsulates a 4d Homogenous Point / Vector object
Real m_minX
the min x value of the bbox
Definition: BBox.h:182
Real m_maxY
the max y value of the bbox
Definition: BBox.h:194
a simple 3 tuple container for compatibility with glsl
std::unique_ptr< AbstractVAO > m_vao
a pointer to the VAO buffer used for drawing the bbox
Definition: BBox.h:226
Real minX() const noexcept
the min x value of the bbox
Definition: BBox.h:91
Real height() const noexcept
Height of the BBox.
Definition: BBox.h:130
GLuint m_drawMode
sets the draw mode for the BBox Faces, set to GL_LINE for line faces and GL_FILL for filled ...
Definition: BBox.h:231
Real m_maxZ
the max z value of the bbox
Definition: BBox.h:202
Real maxZ() const noexcept
the max z value of the bbox
Definition: BBox.h:111
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
Definition: glew.h:1255
Simple Bounding box class used in various parts of ngl and other example programs.
Definition: BBox.h:40
GLint GLint GLint GLint GLint GLint GLsizei width
Definition: glew.h:1255
Real m_minY
the min y value of the bbox
Definition: BBox.h:190