NGL  6.5
The NCCA Graphics Library
AABB.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 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 m_a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 #include "AABB.h"
18 //-----------------------------------------------------------------------------
21 //-----------------------------------------------------------------------------
22 namespace ngl
23 {
24 
25 //-----------------------------------------------------------------------------
26 AABB::AABB()noexcept
27 {
28  m_corner.set(0.0f,0.0f,0.0f,1.0f);
29 
30  m_x = 1.0f;
31  m_y = 1.0f;
32  m_z = 1.0f;
33 }
34 //-----------------------------------------------------------------------------
35 AABB::AABB(const Vec4 &_corner, Real _x, Real _y, Real _z ) noexcept
36 {
37  set(_corner,_x,_y,_z);
38 }
39 
40 //-----------------------------------------------------------------------------
42 {
43 
44 }
45 //-----------------------------------------------------------------------------
46 void AABB::set(const Vec4 &_corner,Real _x,Real _y, Real _z ) noexcept
47 {
48  m_corner=_corner;
49 
50  if (_x < 0.0f)
51  {
52  _x = -_x;
53  m_corner.m_x -= _x;
54  }
55  if (_y < 0.0f)
56  {
57  _y = -_y;
58  m_corner.m_y -= _y;
59  }
60  if (_z < 0.0f)
61  {
62  _z = -_z;
63  m_corner.m_z -= _z;
64  }
65  m_x = _x;
66  m_y = _y;
67  m_z = _z;
68 }
69 
70 Vec3 AABB::getVertexP(const Vec3 &_normal) const noexcept
71 {
72  Vec3 res = m_corner.toVec3();
73 
74  if (_normal.m_x > 0.0f)
75  {
76  res.m_x += m_x;
77  }
78  if (_normal.m_y > 0.0f)
79  {
80  res.m_y += m_y;
81  }
82 
83  if (_normal.m_z > 0.0f)
84  {
85  res.m_z += m_z;
86  }
87  return res;
88 }
89 
90 Vec3 AABB::getVertexN(const Vec3 &_normal) const noexcept
91 {
92  Vec3 res = m_corner.toVec3();
93 
94  if (_normal.m_x < 0.0f)
95  {
96  res.m_x += m_x;
97  }
98  if (_normal.m_y < 0.0f)
99  {
100  res.m_y += m_y;
101  }
102 
103  if (_normal.m_z < 0.0f)
104  {
105  res.m_z += m_z;
106  }
107  return res;
108 }
109 
110 
111 } // end of ngl namespace
simple Vector class for OpenGL graphics, contains overloaded operators for most math functions...
Definition: Vec4.h:57
Vec3 toVec3() const noexcept
get as a Vec3 for glsl etc
Definition: Vec4.h:128
an Axis Aligned Bounding Box
simple Vec3 encapsulates a 3 float object like glsl vec3 but not maths use the Vec3 class for maths a...
Definition: Vec3.h:51
implementation files for RibExport class
Definition: AABB.cpp:22
PRECISION Real
create a variable called Real which is the main data type we use (GLfloat for most cases) ...
Definition: Types.h:127
Real m_y
y component
Definition: Vec3.h:311
void set(Real _x, Real _y, Real _z, Real _w=1.0) noexcept
sets the vector component from 3 values
Definition: Vec4.cpp:41
Real m_x
Definition: AABB.h:86
AABB() noexcept
default ctor
Definition: AABB.cpp:26
Real m_z
z component
Definition: Vec4.h:323
Real m_y
Definition: AABB.h:87
~AABB()
dtor (not used)
Definition: AABB.cpp:41
Real m_x
x component
Definition: Vec3.h:310
Vec3 getVertexN(const Vec3 &_normal) const noexcept
Definition: AABB.cpp:90
Vec3 getVertexP(const Vec3 &_normal) const noexcept
Definition: AABB.cpp:70
void set(const Vec4 &_corner, Real _x, Real _y, Real _z) noexcept
set the AABB values
Definition: AABB.cpp:46
GLuint res
Definition: glew.h:11547
Real m_x
x component
Definition: Vec4.h:321
Real m_z
Definition: AABB.h:88
Vec4 m_corner
Definition: AABB.h:84
Real m_y
y component
Definition: Vec4.h:322
Real m_z
z component
Definition: Vec3.h:312
GLclampf f
Definition: glew.h:3511