-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathBoundingBox.cpp
More file actions
executable file
·70 lines (60 loc) · 1.2 KB
/
BoundingBox.cpp
File metadata and controls
executable file
·70 lines (60 loc) · 1.2 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "BoundingBox.h"
//BoundingBox
BoundingBox::BoundingBox()
{
Reset();
}
float BoundingBox::Max(float a, float b)
{
if (a > b)
return a;
else
return b;
}
float BoundingBox::Min(float a, float b)
{
if (a > b)
return b;
else
return a;
}
void BoundingBox::Reset()
{
m_fMin[0] = m_fMin[1] = m_fMin[2] = 1e10;
m_fMax[0] = m_fMax[1] = m_fMax[2] = -1e10;
}
void BoundingBox::Push(float m_fVertex[3])
{
for (int i = 0; i < 3; i++) {
if (m_fVertex[i] < m_fMin[i])
m_fMin[i] = m_fVertex[i];
if (m_fVertex[i] > m_fMax[i])
m_fMax[i] = m_fVertex[i];
}
}
Vector3D BoundingBox::GetPosition()
{
return Vector3D(
(m_fMin[0] + m_fMax[0]) / 2.0,
(m_fMin[1] + m_fMax[1]) / 2.0,
(m_fMin[2] + m_fMax[2]) / 2.0
);
}
float BoundingBox::GetLength()
{
return Max(m_fMax[2] - m_fMin[2], Max(m_fMax[1] - m_fMin[1], m_fMax[0] - m_fMin[0]));
}
float BoundingBox::GetMaxLength()
{
return (float)(2.0 * GetLength());
}
Vector3D BoundingBox::GetCorner(int i, int j, int k)
{
Vector3D vPos = GetPosition();
float fLength = GetLength();
return vPos + Vector3D(
(i - 0.5) * fLength,
(j - 0.5) * fLength,
(k - 0.5) * fLength
);
}