-
Notifications
You must be signed in to change notification settings - Fork 0
/
glBbox.cpp
70 lines (47 loc) · 1.91 KB
/
glBbox.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*-----------------------------------------------------------------------------
glBbox.cpp
2006 Shamus Young
-------------------------------------------------------------------------------
This module has a few functions useful for manipulating the bounding-box
structs.
-----------------------------------------------------------------------------*/
#define MAX_VALUE 999999999999999.9f
#include <math.h>
#include "macro.h"
#include "glTypes.h"
/*-----------------------------------------------------------------------------
Does the given point fall within the given Bbox?
-----------------------------------------------------------------------------*/
bool glBboxTestPoint (GLbbox box, GLvector point)
{
if (point.x > box.max.x || point.x < box.min.x)
return false;
if (point.y > box.max.y || point.y < box.min.y)
return false;
if (point.z > box.max.z || point.z < box.min.z)
return false;
return true;
}
/*-----------------------------------------------------------------------------
Expand Bbox (if needed) to contain given point
-----------------------------------------------------------------------------*/
GLbbox glBboxContainPoint (GLbbox box, GLvector point)
{
box.min.x = MIN (box.min.x, point.x);
box.min.y = MIN (box.min.y, point.y);
box.min.z = MIN (box.min.z, point.z);
box.max.x = MAX (box.max.x, point.x);
box.max.y = MAX (box.max.y, point.y);
box.max.z = MAX (box.max.z, point.z);
return box;
}
/*-----------------------------------------------------------------------------
This will invalidate the bbox.
-----------------------------------------------------------------------------*/
GLbbox glBboxClear (void)
{
GLbbox result;
result.max = glVector (-MAX_VALUE, -MAX_VALUE, -MAX_VALUE);
result.min = glVector ( MAX_VALUE, MAX_VALUE, MAX_VALUE);
return result;
}