-
Notifications
You must be signed in to change notification settings - Fork 0
/
boundingbox.h
102 lines (86 loc) · 2.48 KB
/
boundingbox.h
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef _BOUNDING_BOX_H_
#define _BOUNDING_BOX_H_
#include <cassert>
#include <algorithm>
#include "vectors.h"
#if defined(_WIN32)
// windows already has them defined...
#define my_max std::max
#define my_min std::min
#else
#define my_max std::max
#define my_min std::min
#endif
// ====================================================================
// ====================================================================
class BoundingBox {
public:
// ========================
// CONSTRUCTOR & DESTRUCTOR
BoundingBox() { Set(Vec3f(0,0,0),Vec3f(0,0,0)); }
BoundingBox(const Vec3f &v) { Set(v,v); }
BoundingBox(const Vec3f &_minimum, const Vec3f &_maximum) { Set(_minimum,_maximum); }
~BoundingBox() { }
// =========
// ACCESSORS
void Get(Vec3f &_minimum, Vec3f &_maximum) const {
_minimum = minimum;
_maximum = maximum; }
Vec3f getMin() const { return minimum; }
Vec3f getMax() const { return maximum; }
void getCenter(Vec3f &c) const {
c = maximum;
c -= minimum;
c *= 0.5f;
c += minimum;
}
double maxDim() const {
double x = maximum.x() - minimum.x();
double y = maximum.y() - minimum.y();
double z = maximum.z() - minimum.z();
return my_max(x,my_max(y,z));
}
// =========
// MODIFIERS
void Set(const BoundingBox &bb) {
Set(bb.minimum,bb.maximum);
}
void Set(const Vec3f &_minimum, const Vec3f &_maximum) {
assert (minimum.x() <= maximum.x() &&
minimum.y() <= maximum.y() &&
minimum.z() <= maximum.z());
minimum = _minimum;
maximum = _maximum; }
void Extend(const Vec3f &v) {
minimum = Vec3f(my_min(minimum.x(),v.x()),
my_min(minimum.y(),v.y()),
my_min(minimum.z(),v.z()));
maximum = Vec3f(my_max(maximum.x(),v.x()),
my_max(maximum.y(),v.y()),
my_max(maximum.z(),v.z()));
}
void Extend(const BoundingBox &bb) {
Extend(bb.minimum);
Extend(bb.maximum);
}
// =========
// DEBUGGING
void Print(const char *s="") const {
printf ("BOUNDING BOX %s: %f %f %f -> %f %f %f\n", s,
minimum.x(),minimum.y(),minimum.z(),
maximum.x(),maximum.y(),maximum.z()); }
void initializeVBOs();
void setupVBOs();
void drawVBOs();
void cleanupVBOs();
private:
// ==============
// REPRESENTATION
Vec3f minimum;
Vec3f maximum;
GLuint bb_verts_VBO;
GLuint bb_edge_indices_VBO;
};
// ====================================================================
// ====================================================================
#endif