summaryrefslogtreecommitdiff
path: root/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/GLT/glt_bbox.h
blob: 9038913cde00dc302e4d6950585f938ce32a143f (plain)
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#ifndef MATH_BBOX_H
#define MATH_BBOX_H

/*

  GLT OpenGL C++ Toolkit (LGPL)
  Copyright (C) 2000-2002 Nigel Stewart  

  Email: nigels@nigels.com   
  WWW:   http://www.nigels.com/glt/

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*/

/*! \file 
    \brief   Axis-Aligned 3D Bounding Box Class
	\ingroup Math
*/

#include <vector>

#include "glt_vector3.h"

/*! \class   BoundingBox 
    \brief   Axis-Aligned 3D Bounding Box Class
	\ingroup Math
	\todo    Rename BoundingBox to AABB (Axis-Aligned Bounding Box?)
*/

class GltMatrix;
class GltViewport;

class BoundingBox
{
	/*!
		\brief Output AAB to stream
		\ingroup Math
	*/
	friend std::ostream &operator<<(std::ostream &os, const BoundingBox &b);

	/*!
		\brief Union of two axis aligned bounding boxes
		\ingroup Math
	*/
	friend BoundingBox sum         (const BoundingBox &a,const BoundingBox &b);

	/*!
		\brief Intersection of two axis aligned bounding boxes
		\ingroup Math
	*/
	friend BoundingBox intersection(const BoundingBox &a,const BoundingBox &b);

public:
	/// Default constructor
	BoundingBox();
	/// Constructor
	BoundingBox(const Vector &min,const Vector &max);
	
	//
	// Get/Set
	//

	/// Defined?
	      bool &defined();

	/// Defined?
	const bool  defined() const;

	/// Minimum x,y,z
	      Vector &min();
	/// Minimum x,y,z
	const Vector &min() const;

	/// Minimum x,y,z
	      Vector &max();
	/// Minimum x,y,z
	const Vector &max() const;

	/// Box center
	Vector center() const;

	/// Box width (Xmax - Xmin)
	real width() const;

	/// Box height (Ymax - Ymin)
	real height() const;

	/// Box depth (Zmax - Zmin)
	real depth() const;

	/// Extract the 8 corners of the box
	void points(std::vector<Vector> &p) const;

	//
	// Set operations
	//

	/// Empty set (undefined)
	void reset();

	/// Boolean union
	BoundingBox &operator+=(const Vector &p);
	/// Boolean union
	BoundingBox &operator+=(const std::vector<Vector> &p);
	/// Boolean union
	BoundingBox &operator+=(const BoundingBox &box);
	/// Boolean intersection
	BoundingBox &operator*=(const BoundingBox &box);

	/// Box equality operator
	bool operator==(const BoundingBox &box) const;

//	/// Closest distance to box
//	Real   dist(const Vector &pos) const;

	/// Volumetric classification
	bool inside(const Vector &pos) const;

	/// Intersection between boxes
	bool intersects(const BoundingBox &box) const;

	/// Map object co-ordinates to window co-ordinates
	bool project(const GltMatrix &model,const GltMatrix &proj,const GltViewport &view);

//	/// Intersect ray
//	Real   intersect        (const Vector &p0,const Vector &p1) const;
//	/// Intersect ray
//	Vector intersectPosition(const Vector &p0,const Vector &p1) const;

protected:

	/// Is the bounding box undefined?
	bool   _defined;
	/// Box minimum
	Vector _min;
	/// Box maximum
	Vector _max;
};

#endif