-
Notifications
You must be signed in to change notification settings - Fork 3
/
BoundingBox.cpp
47 lines (40 loc) · 933 Bytes
/
BoundingBox.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "BoundingBox.h"
#include <limits>
CBoundingBox::CBoundingBox()
{
m_pMin = glm::vec3(std::numeric_limits<float>::max());
m_pMax = glm::vec3(-999999.99);
}
CBoundingBox::~CBoundingBox()
{
}
///
/// Get the lenght/distance on each axis
///
/// @param iAxis indicates the axis: X, Y or Z
///
float CBoundingBox::getLength(int iAxis)
{
return std::abs(m_pMax[iAxis] - m_pMin[iAxis]);
}
///
/// Get the lenght/distance on each axis
///
float CBoundingBox::getDiagonal()
{
return sqrtf(getLength(0)*getLength(0) + getLength(1)*getLength(1) + getLength(2)*getLength(2));
}
///
/// Add a point to create the bounding box
///
/// @param p point to be added
///
void CBoundingBox::addPoint(glm::vec3 p)
{
if(p.x < m_pMin.x) m_pMin.x = p.x;
if(p.x > m_pMax.x) m_pMax.x = p.x;
if(p.y < m_pMin.y) m_pMin.y = p.y;
if(p.y > m_pMax.y) m_pMax.y = p.y;
if(p.z < m_pMin.z) m_pMin.z = p.z;
if(p.z > m_pMax.z) m_pMax.z = p.z;
}