source: projectionDesigner/trunk/projdesigner/include/gmtl/OOBox.h @ 110

Last change on this file since 110 was 4, checked in by Torben Dannhauer, 15 years ago
File size: 5.2 KB
RevLine 
[4]1/************************************************************** ggt-head beg
2 *
3 * GGT: Generic Graphics Toolkit
4 *
5 * Original Authors:
6 *   Allen Bierbaum
7 *
8 * -----------------------------------------------------------------
9 * File:          OOBox.h,v
10 * Date modified: 2002/05/20 22:39:22
11 * Version:       1.5
12 * -----------------------------------------------------------------
13 *
14 *********************************************************** ggt-head end */
15/*************************************************************** ggt-cpr beg
16*
17* GGT: The Generic Graphics Toolkit
18* Copyright (C) 2001,2002 Allen Bierbaum
19*
20* This library is free software; you can redistribute it and/or
21* modify it under the terms of the GNU Lesser General Public
22* License as published by the Free Software Foundation; either
23* version 2.1 of the License, or (at your option) any later version.
24*
25* This library is distributed in the hope that it will be useful,
26* but WITHOUT ANY WARRANTY; without even the implied warranty of
27* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28* Lesser General Public License for more details.
29*
30* You should have received a copy of the GNU Lesser General Public
31* License along with this library; if not, write to the Free Software
32* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33*
34 ************************************************************ ggt-cpr end */
35#ifndef _GMTL_OOBox_H_
36#define _GMTL_OOBox_H_
37
38#include <gmtl/Vec3.h>
39#include <gmtl/Point3.h>
40#include <gmtl/matVecFuncs.h>
41
42namespace gmtl
43{
44
45// AABox : Defines an object aligned box
46//
47// For definition of an OOB, see pg 293-294 of Real-Time Rendering
48class  OOBox
49{
50
51public:
52   OOBox()
53   { ident(); }
54
55   OOBox(OOBox& box);
56
57public:
58   // Accessors
59   Point3& center();
60   const Point3& center() const;
61
62   Vec3& axis (int i);
63   const Vec3& axis (int i) const;
64   Vec3* axes ();
65   const Vec3* axes () const;
66
67   float& halfLen(int i);
68   const float& halfLen(int i) const;
69   float* halfLens();
70   const float* halfLens() const;
71
72   // Assignment
73   OOBox& operator=(const OOBox& box);
74
75   // Comparison
76   bool operator==(const OOBox& box) const;
77
78   //  return the verts that define the box
79   // Order: XYZ: 000, 100, 110, 010,
80   //             001, 101, 111, 011
81   void getVerts(Point3 verts[8]) const;
82
83   // Merge current box with other box to get new box covering both
84   void mergeWith(const OOBox& box);
85
86   void ident()
87   {
88      mCenter = ZeroVec3;
89      mAxis[0] = XUnitVec3;
90      mAxis[1] = YUnitVec3;
91      mAxis[2] = ZUnitVec3;
92      mHalfLen[0] = mHalfLen[1] = mHalfLen[2] = 0.0f;
93   }
94
95public:
96   Point3  mCenter;     // The center point of the box
97   Vec3    mAxis[3];    // The axes of the oriented box (xAxis, yAxis, zAxis)
98   float   mHalfLen[3]; // Half lengths of the box  ASSERT: HalfLens >= 0.0f
99};
100
101
102// ------------------------------------------------- //
103// --------------- Member definitions -------------- //
104// ------------------------------------------------- //
105inline
106OOBox::OOBox(OOBox& box)
107{
108   mCenter = box.mCenter;
109   mAxis[0] = box.mAxis[0];
110   mAxis[1] = box.mAxis[1];
111   mAxis[2] = box.mAxis[2];
112   mHalfLen[0] = box.mHalfLen[0];
113   mHalfLen[1] = box.mHalfLen[1];
114   mHalfLen[2] = box.mHalfLen[2];
115}
116
117// Accessors
118inline Point3& OOBox::center()
119{
120   return mCenter;
121}
122
123inline const Point3& OOBox::center() const
124{
125   return mCenter;
126}
127
128inline Vec3& OOBox::axis (int i)
129{
130   return mAxis[i];
131}
132
133inline const Vec3& OOBox::axis (int i) const
134{
135   return mAxis[i];
136}
137
138inline Vec3* OOBox::axes ()
139{
140   return mAxis;
141}
142
143inline const Vec3* OOBox::axes () const
144{
145   return mAxis;
146}
147
148inline float& OOBox::halfLen(int i)
149{
150   return mHalfLen[i];
151}
152
153inline const float& OOBox::halfLen(int i) const
154{
155   return mHalfLen[i];
156}
157
158inline float* OOBox::halfLens()
159{
160   return mHalfLen;
161}
162
163inline const float* OOBox::halfLens() const
164{
165   return mHalfLen;
166}
167
168// Assignment
169inline OOBox& OOBox::operator=(const OOBox& box)
170{
171   mCenter = box.mCenter;
172   mAxis[0] = box.mAxis[0];
173   mAxis[1] = box.mAxis[1];
174   mAxis[2] = box.mAxis[2];
175   mHalfLen[0] = box.mHalfLen[0];
176   mHalfLen[1] = box.mHalfLen[1];
177   mHalfLen[2] = box.mHalfLen[2];
178   return *this;
179}
180
181// Comparison
182inline bool OOBox::operator==(const OOBox& box) const
183{
184   return ((mCenter == box.mCenter) &&
185           (mAxis[0] == box.mAxis[0]) &&
186           (mAxis[1] == box.mAxis[1]) &&
187           (mAxis[2] == box.mAxis[2]) &&
188           (mHalfLen[0] == box.mHalfLen[0]) &&
189           (mHalfLen[1] == box.mHalfLen[1]) &&
190           (mHalfLen[2] == box.mHalfLen[2]));
191}
192
193inline void OOBox::getVerts(Point3 verts[8]) const
194{
195   Vec3 x_half_axis = mAxis[0]*mHalfLen[0];
196   Vec3 y_half_axis = mAxis[1]*mHalfLen[1];
197   Vec3 z_half_axis = mAxis[2]*mHalfLen[2];
198
199   verts[0] = mCenter - x_half_axis - y_half_axis - z_half_axis;
200   verts[1] = mCenter + x_half_axis - y_half_axis - z_half_axis;
201   verts[2] = mCenter + x_half_axis + y_half_axis - z_half_axis;
202   verts[3] = mCenter - x_half_axis + y_half_axis - z_half_axis;
203   verts[4] = mCenter - x_half_axis - y_half_axis + z_half_axis;
204   verts[5] = mCenter + x_half_axis - y_half_axis + z_half_axis;
205   verts[6] = mCenter + x_half_axis + y_half_axis + z_half_axis;
206   verts[7] = mCenter - x_half_axis + y_half_axis + z_half_axis;
207}
208
209};
210
211#endif
Note: See TracBrowser for help on using the repository browser.