-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBBox.cpp
More file actions
139 lines (113 loc) · 3.9 KB
/
BBox.cpp
File metadata and controls
139 lines (113 loc) · 3.9 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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include "BBox.h"
BBox::BBox()
{
min.set(std::numeric_limits<float>::max(), std::numeric_limits<float>::max(), std::numeric_limits<float>::max() ) ;
max.set( -1.f * std::numeric_limits<float>::max(), -1.f * std::numeric_limits<float>::max(), -1.f * std::numeric_limits<float>::max() );
}
// BBox::BBox()
// {
// }
BBox::~BBox()
{
}
//Will remove this in favour of a more central/generic input type
//Multiple versions will make things confusing. Might look into something like
//this later.
// /*--------------------------track bounds of a vector of Particle pointers-------------------------*/
// void BBox::trackBounds(const std::vector<Particle*> &particles)
// {
// if(!particles.empty())
// {
// //unable to use numeric_limits in initialisation
// //need to get a way to use that instead of these
// //hardcoded numbers..
// min.set(1000000.f, 1000000.f, 1000000.f) ;
// max.set(-1000000.f, -1000000.f, -1000000.f) ;
// // min = ofVec3f(tmp_min, tmp_min, tmp_min) ;
// for(std::vector<Particle*>::const_iterator it = particles.begin(); it != particles.end(); ++it)
// {
// //set min and max XPOS
// if( (*it)->getPosition().x < min.x )
// min.x = (*it)->getPosition().x ;
// if( (*it)->getPosition().x > max.x )
// max.x = (*it)->getPosition().x ;
// //set min and max YPOS
// if( (*it)->getPosition().y < min.y )
// min.y = (*it)->getPosition().y ;
// if( (*it)->getPosition().y > max.y )
// max.y = (*it)->getPosition().y ;
// //set min and max XPOS
// if( (*it)->getPosition().z < min.z )
// min.z = (*it)->getPosition().z ;
// if( (*it)->getPosition().z > max.z )
// max.z = (*it)->getPosition().z ;
// }
// }
// }
// ////////////////////////////////////////////////////////////////////////////////////////////////////////
/*------------------------------------track bounds of OFMESH-------------------------------------------*/
//to avoid any dynamic memory alloc supply this a Vector of Vertices.
void BBox::trackBounds(const std::vector<ofVec3f> &meshVertices )
{
if(!meshVertices.empty())
{
//unable to use numeric_limits in initialisation
//need to get a way to use that instead of these
//hardcoded numbers..
min.set(1000000.f, 1000000.f, 1000000.f) ;
max.set(-1000000.f, -1000000.f, -1000000.f) ;
// min = ofVec3f(tmp_min, tmp_min, tmp_min) ;
for(std::vector<ofVec3f>::const_iterator it = meshVertices.begin(); it != meshVertices.end(); ++it)
{
//set min and max XPOS
if( it->x < min.x )
min.x = it->x ;
if( it->x > max.x )
max.x = it->x ;
//set min and max YPOS
if( it->y < min.y )
min.y = it->y ;
if( it->y > max.y )
max.y = it->y ;
//set min and max XPOS
if( it->z < min.z )
min.z = it->z ;
if( it->z > max.z )
max.z = it->z ;
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
void BBox::draw(const ofColor &color)
{
ofSetColor(color) ;
//only need to draw 6 faces..
//no need to draw common/shared edges for each face
//draw MIN ZX plane
ofLine(min.x, min.y, min.z, max.x, min.y, min.z) ;
ofLine(min.x, min.y, max.z, max.x, min.y, max.z) ;
ofLine(min.x, min.y, min.z, min.x, min.y, max.z) ;
ofLine(max.x, min.y, min.z, max.x, min.y, max.z) ;
//draw MAX ZX plane
ofLine(min.x, max.y, min.z, max.x, max.y, min.z) ;
ofLine(min.x, max.y, max.z, max.x, max.y, max.z) ;
ofLine(min.x, max.y, min.z, min.x, max.y, max.z) ;
ofLine(max.x, max.y, min.z, max.x, max.y, max.z) ;
//draw xy plane
//draw MIN YZ plane
ofLine(min.x, min.y, min.z, min.x, max.y, min.z) ;
ofLine(min.x, min.y, max.z, min.x, max.y, max.z) ;
ofLine(min.x, min.y, min.z, min.x, max.y, min.z) ;
//draw MIN YZ plane
ofLine(max.x, min.y, min.z, max.x, max.y, min.z) ;
ofLine(max.x, min.y, max.z, max.x, max.y, max.z) ;
ofLine(min.x, min.y, min.z, min.x, max.y, min.z) ;
}
ofVec3f& BBox::getMin()
{
return min ;
}
ofVec3f& BBox::getMax()
{
return max ;
}