Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
csBox3 Class Reference

#include <opbox.h>

Classes

struct  bEdge
 

Public Member Functions

float MinX () const
 Get the minimum X value of the box. More...
 
float MinY () const
 Get the minimum Y value of the box. More...
 
float MinZ () const
 Get the minimum Z value of the box. More...
 
float MaxX () const
 Get the maximum X value of the box. More...
 
float MaxY () const
 Get the maximum Y value of the box. More...
 
float MaxZ () const
 Get the maximum Z value of the box. More...
 
float Min (int idx) const
 Get Min component for 0 (x), 1 (y), or 2 (z). More...
 
float Max (int idx) const
 Get Max component for 0 (x), 1 (y), or 2 (z). More...
 
const csVector3Min () const
 Get the 3d vector of minimum (x, y, z) values. More...
 
const csVector3Max () const
 Get the 3d vector of maximum (x, y, z) values. More...
 
csVector3 GetCorner (int corner) const
 
void GetEdgeInfo (int edge, int &v1, int &v2, int &fleft, int &fright) const
 
uint8GetFaceEdges (int face) const
 
csVector3 GetCenter () const
 
void SetCenter (const csVector3 &c)
 
void SetSize (const csVector3 &s)
 
int GetVisibleSides (const csVector3 &pos, int *visible_sides) const
 
bool In (float x, float y, float z) const
 Test if the given coordinate is in this box. More...
 
bool In (const csVector3 &v) const
 Test if the given coordinate is in this box. More...
 
bool Overlap (const csBox3 &box) const
 Test if this box overlaps with the given box. More...
 
bool Contains (const csBox3 &box) const
 Test if this box contains the other box. More...
 
bool Empty () const
 Test if this box is empty. More...
 
void StartBoundingBox ()
 Initialize this box to empty. More...
 
void StartBoundingBox (const csVector3 &v)
 Initialize this box to one vertex. More...
 
void AddBoundingVertex (float x, float y, float z)
 Add a new vertex and recalculate the bounding box. More...
 
void AddBoundingVertex (const csVector3 &v)
 Add a new vertex and recalculate the bounding box. More...
 
void AddBoundingVertexSmart (float x, float y, float z)
 
void AddBoundingVertexSmart (const csVector3 &v)
 
 csBox3 ()
 Initialize this box to empty. More...
 
 csBox3 (const csVector3 &v)
 Initialize this box with one point. More...
 
 csBox3 (const csVector3 &v1, const csVector3 &v2)
 Initialize this box with two points. More...
 
 csBox3 (float x1, float y1, float z1, float x2, float y2, float z2)
 Initialize this box with the given values. More...
 
void Set (const csVector3 &bmin, const csVector3 &bmax)
 Sets the bounds of the box with the given values. More...
 
void Set (float x1, float y1, float z1, float x2, float y2, float z2)
 Sets the bounds of the box with the given values. More...
 
bool AdjacentX (const csBox3 &other) const
 
bool AdjacentY (const csBox3 &other) const
 
bool AdjacentZ (const csBox3 &other) const
 
int Adjacent (const csBox3 &other) const
 
void GetConvexOutline (const csVector3 &pos, csVector3 *array, int &num_array, bool bVisible=false) const
 
bool Between (const csBox3 &box1, const csBox3 &box2) const
 
void ManhattanDistance (const csBox3 &other, csVector3 &dist) const
 
float SquaredOriginDist () const
 
float SquaredOriginMaxDist () const
 
csBox3operator+= (const csBox3 &box)
 Compute the union of two bounding boxes. More...
 
csBox3operator+= (const csVector3 &point)
 Compute the union of a point with this bounding box. More...
 
csBox3operator*= (const csBox3 &box)
 Compute the intersection of two bounding boxes. More...
 

Static Public Member Functions

static int OtherSide (int side)
 

Protected Types

typedef uint8 bFace [4]
 

Protected Attributes

csVector3 minbox
 The top-left of this bounding box. More...
 
csVector3 maxbox
 The bottom-right. More...
 

Static Protected Attributes

static bEdge edges [24]
 
static bFace faces [6]
 

Friends

csBox3 operator+ (const csBox3 &box1, const csBox3 &box2)
 Compute the union of two bounding boxes. More...
 
csBox3 operator+ (const csBox3 &box, const csVector3 &point)
 Compute the union of a bounding box and a point. More...
 
csBox3 operator* (const csBox3 &box1, const csBox3 &box2)
 Compute the intersection of two bounding boxes. More...
 
bool operator== (const csBox3 &box1, const csBox3 &box2)
 Tests if two bounding boxes are equal. More...
 
bool operator!= (const csBox3 &box1, const csBox3 &box2)
 Tests if two bounding boxes are unequal. More...
 
bool operator< (const csBox3 &box1, const csBox3 &box2)
 Tests if box1 is a subset of box2. More...
 
bool operator> (const csBox3 &box1, const csBox3 &box2)
 Tests if box1 is a superset of box2. More...
 
bool operator< (const csVector3 &point, const csBox3 &box)
 Tests if a point is contained in a box. More...
 

Detailed Description

A bounding box in 3D space. In order to operate correctly, this bounding box assumes that all values entered or compared against lie within the range (-CS_BOUNDINGBOX_MAXVALUE, CS_BOUNDINGBOX_MAXVALUE). It is not recommended to use points outside of this range.

Definition at line 97 of file opbox.h.

Member Typedef Documentation

typedef uint8 csBox3::bFace[4]
protected

Definition at line 110 of file opbox.h.

Constructor & Destructor Documentation

csBox3::csBox3 ( )
inline

Initialize this box to empty.

Definition at line 340 of file opbox.h.

csBox3::csBox3 ( const csVector3 v)
inline

Initialize this box with one point.

Definition at line 349 of file opbox.h.

349 : minbox (v), maxbox (v) { }
csBox3::csBox3 ( const csVector3 v1,
const csVector3 v2 
)
inline

Initialize this box with two points.

Definition at line 352 of file opbox.h.

References Empty(), and StartBoundingBox().

352  :
353  minbox (v1), maxbox (v2)
354  { if (Empty ()) StartBoundingBox (); }
csBox3::csBox3 ( float  x1,
float  y1,
float  z1,
float  x2,
float  y2,
float  z2 
)
inline

Initialize this box with the given values.

Definition at line 357 of file opbox.h.

References Empty(), and StartBoundingBox().

357  :
358  minbox (x1, y1, z1), maxbox (x2, y2, z2)
359  { if (Empty ()) StartBoundingBox (); }

Member Function Documentation

void csBox3::AddBoundingVertex ( float  x,
float  y,
float  z 
)
inline

Add a new vertex and recalculate the bounding box.

Definition at line 290 of file opbox.h.

References maxbox, minbox, csVector3::x, x, csVector3::y, y, and csVector3::z.

Referenced by AddBoundingVertex().

291  {
292  if (x < minbox.x) minbox.x = x; if (x > maxbox.x) maxbox.x = x;
293  if (y < minbox.y) minbox.y = y; if (y > maxbox.y) maxbox.y = y;
294  if (z < minbox.z) minbox.z = z; if (z > maxbox.z) maxbox.z = z;
295  }
void csBox3::AddBoundingVertex ( const csVector3 v)
inline

Add a new vertex and recalculate the bounding box.

Definition at line 298 of file opbox.h.

References AddBoundingVertex(), csVector3::x, csVector3::y, and csVector3::z.

299  {
300  AddBoundingVertex (v.x, v.y, v.z);
301  }
void csBox3::AddBoundingVertexSmart ( float  x,
float  y,
float  z 
)
inline

Add a new vertex and recalculate the bounding box. This version is a little more optimal. It assumes however that at least one point has been added to the bounding box.

Definition at line 308 of file opbox.h.

References maxbox, minbox, csVector3::x, x, csVector3::y, y, and csVector3::z.

Referenced by AddBoundingVertexSmart().

309  {
310  if (x < minbox.x) minbox.x = x; else if (x > maxbox.x) maxbox.x = x;
311  if (y < minbox.y) minbox.y = y; else if (y > maxbox.y) maxbox.y = y;
312  if (z < minbox.z) minbox.z = z; else if (z > maxbox.z) maxbox.z = z;
313  }
void csBox3::AddBoundingVertexSmart ( const csVector3 v)
inline

Add a new vertex and recalculate the bounding box. This version is a little more optimal. It assumes however that at least one point has been added to the bounding box.

Definition at line 320 of file opbox.h.

References AddBoundingVertexSmart(), csVector3::x, csVector3::y, and csVector3::z.

321  {
322  AddBoundingVertexSmart (v.x, v.y, v.z);
323  }
int csBox3::Adjacent ( const csBox3 other) const

Test if this box is adjacent to the other one. Return -1 if not adjacent or else any of the BOX_SIDE_??? flags to indicate the side of this box that the other box is adjacent with.

Definition at line 191 of file opbox.cpp.

References AdjacentX(), AdjacentY(), AdjacentZ(), BOX_SIDE_x, BOX_SIDE_X, BOX_SIDE_y, BOX_SIDE_Y, BOX_SIDE_z, BOX_SIDE_Z, MaxX(), MaxY(), and MaxZ().

192 {
193  if (AdjacentX (other))
194  {
195  if (other.MaxX () > MaxX ()) return BOX_SIDE_X;
196  else return BOX_SIDE_x;
197  }
198  if (AdjacentY (other))
199  {
200  if (other.MaxY () > MaxY ()) return BOX_SIDE_Y;
201  else return BOX_SIDE_y;
202  }
203  if (AdjacentZ (other))
204  {
205  if (other.MaxZ () > MaxZ ()) return BOX_SIDE_Z;
206  else return BOX_SIDE_z;
207  }
208  return -1;
209 }
bool csBox3::AdjacentX ( const csBox3 other) const

Test if this box is adjacent to the other on the X side.

Definition at line 155 of file opbox.cpp.

References ABS, MaxX(), MaxY(), MaxZ(), MinX(), MinY(), MinZ(), and SMALL_EPSILON.

Referenced by Adjacent().

156 {
157  if (ABS (other.MinX () - MaxX ()) < SMALL_EPSILON ||
158  ABS (other.MaxX () - MinX ()) < SMALL_EPSILON)
159  {
160  if (MaxY () < other.MinY () || MinY () > other.MaxY ()) return false;
161  if (MaxZ () < other.MinZ () || MinZ () > other.MaxZ ()) return false;
162  return true;
163  }
164  return false;
165 }
bool csBox3::AdjacentY ( const csBox3 other) const

Test if this box is adjacent to the other on the Y side.

Definition at line 167 of file opbox.cpp.

References ABS, MaxX(), MaxY(), MaxZ(), MinX(), MinY(), MinZ(), and SMALL_EPSILON.

Referenced by Adjacent().

168 {
169  if (ABS (other.MinY () - MaxY ()) < SMALL_EPSILON ||
170  ABS (other.MaxY () - MinY ()) < SMALL_EPSILON)
171  {
172  if (MaxX () < other.MinX () || MinX () > other.MaxX ()) return false;
173  if (MaxZ () < other.MinZ () || MinZ () > other.MaxZ ()) return false;
174  return true;
175  }
176  return false;
177 }
bool csBox3::AdjacentZ ( const csBox3 other) const

Test if this box is adjacent to the other on the Z side.

Definition at line 179 of file opbox.cpp.

References ABS, MaxX(), MaxY(), MaxZ(), MinX(), MinY(), MinZ(), and SMALL_EPSILON.

Referenced by Adjacent().

180 {
181  if (ABS (other.MinZ () - MaxZ ()) < SMALL_EPSILON ||
182  ABS (other.MaxZ () - MinZ ()) < SMALL_EPSILON)
183  {
184  if (MaxX () < other.MinX () || MinX () > other.MaxX ()) return false;
185  if (MaxY () < other.MinY () || MinY () > other.MaxY ()) return false;
186  return true;
187  }
188  return false;
189 }
bool csBox3::Between ( const csBox3 box1,
const csBox3 box2 
) const

Test if this box is between two others.

Definition at line 274 of file opbox.cpp.

References maxbox, minbox, csVector3::x, csVector3::y, and csVector3::z.

275 {
276  // First the trival test to see if the coordinates are
277  // at least within the right intervals.
278  if (((maxbox.x >= box1.minbox.x && minbox.x <= box2.maxbox.x) ||
279  (maxbox.x >= box2.minbox.x && minbox.x <= box1.maxbox.x)) &&
280  ((maxbox.y >= box1.minbox.y && minbox.y <= box2.maxbox.y) ||
281  (maxbox.y >= box2.minbox.y && minbox.y <= box1.maxbox.y)) &&
282  ((maxbox.z >= box1.minbox.z && minbox.z <= box2.maxbox.z) ||
283  (maxbox.z >= box2.minbox.z && minbox.z <= box1.maxbox.z)))
284  {
285  // @@@ Ok, let's just return true here. Maybe this test is already
286  // enough? We could have used the planes as well.
287  return true;
288  }
289  return false;
290 }
bool csBox3::Contains ( const csBox3 box) const
inline

Test if this box contains the other box.

Definition at line 256 of file opbox.h.

References maxbox, minbox, csVector3::x, csVector3::y, and csVector3::z.

257  {
258  return (box.minbox.x >= minbox.x && box.maxbox.x <= maxbox.x) &&
259  (box.minbox.y >= minbox.y && box.maxbox.y <= maxbox.y) &&
260  (box.minbox.z >= minbox.z && box.maxbox.z <= maxbox.z);
261  }
bool csBox3::Empty ( ) const
inline

Test if this box is empty.

Definition at line 264 of file opbox.h.

References maxbox, minbox, csVector3::x, csVector3::y, and csVector3::z.

Referenced by csBox3().

265  {
266  if (minbox.x > maxbox.x) return true;
267  if (minbox.y > maxbox.y) return true;
268  if (minbox.z > maxbox.z) return true;
269  return false;
270  }
csVector3 csBox3::GetCenter ( ) const
inline

Get the center of this box.

Definition at line 174 of file opbox.h.

References maxbox, minbox, csVector3::x, csVector3::y, and csVector3::z.

Referenced by SetCenter(), and SetSize().

174 { return csVector3((minbox.x+maxbox.x)/2, (minbox.y+maxbox.y)/2, (minbox.z+maxbox.z)/2); }
void csBox3::GetConvexOutline ( const csVector3 pos,
csVector3 array,
int num_array,
bool  bVisible = false 
) const

Get a convex outline (not a polygon unless projected to 2D) for for this box as seen from the given position. The coordinates returned are world space coordinates. Note that you need place for at least six vectors in the array. If you set bVisible true, you will get all visible corners - this could be up to 7.

Definition at line 236 of file opbox.cpp.

References i, Max(), MIN, Min(), Outline::num, Outline::vertices, csVector3::x, csVector3::y, and csVector3::z.

238 {
239  const csVector3& bmin = Min ();
240  const csVector3& bmax = Max ();
241  int idx;
242  // First select x part of coordinate.
243  if (pos.x < bmin.x) idx = 0*9;
244  else if (pos.x > bmax.x) idx = 2*9;
245  else idx = 1*9;
246  // Then y part.
247  if (pos.y < bmin.y) idx += 0*3;
248  else if (pos.y > bmax.y) idx += 2*3;
249  else idx += 1*3;
250  // Then z part.
251  if (pos.z < bmin.z) idx += 0;
252  else if (pos.z > bmax.z) idx += 2;
253  else idx += 1;
254 
255  const Outline& ol = outlines[idx];
256  num_array = (bVisible ? ol.num : MIN (ol.num, 6));
257  int i;
258  for (i = 0 ; i < num_array ; i++)
259  {
260  switch (ol.vertices[i])
261  {
262  case 0: ar[i].x = bmin.x; ar[i].y = bmin.y; ar[i].z = bmin.z; break;
263  case 1: ar[i].x = bmin.x; ar[i].y = bmin.y; ar[i].z = bmax.z; break;
264  case 2: ar[i].x = bmin.x; ar[i].y = bmax.y; ar[i].z = bmin.z; break;
265  case 3: ar[i].x = bmin.x; ar[i].y = bmax.y; ar[i].z = bmax.z; break;
266  case 4: ar[i].x = bmax.x; ar[i].y = bmin.y; ar[i].z = bmin.z; break;
267  case 5: ar[i].x = bmax.x; ar[i].y = bmin.y; ar[i].z = bmax.z; break;
268  case 6: ar[i].x = bmax.x; ar[i].y = bmax.y; ar[i].z = bmin.z; break;
269  case 7: ar[i].x = bmax.x; ar[i].y = bmax.y; ar[i].z = bmax.z; break;
270  }
271  }
272 }
csVector3 csBox3::GetCorner ( int  corner) const

Return every corner of this bounding box from 0 to 7. This contrasts with Min() and Max() because those are only the min and max corners. Corner 0 = xyz, 1 = xyZ, 2 = xYz, 3 = xYZ, 4 = Xyz, 5 = XyZ, 6 = XYz, 7 = XYZ. Use BOX_CORNER_??? defines.

Definition at line 124 of file opbox.cpp.

References BOX_CORNER_xyz, BOX_CORNER_xyZ, BOX_CORNER_xYz, BOX_CORNER_xYZ, BOX_CORNER_Xyz, BOX_CORNER_XyZ, BOX_CORNER_XYz, BOX_CORNER_XYZ, Max(), MaxX(), MaxY(), MaxZ(), Min(), MinX(), MinY(), and MinZ().

125 {
126  switch (corner)
127  {
128  case BOX_CORNER_xyz: return Min ();
129  case BOX_CORNER_xyZ: return csVector3 (MinX (), MinY (), MaxZ ());
130  case BOX_CORNER_xYz: return csVector3 (MinX (), MaxY (), MinZ ());
131  case BOX_CORNER_xYZ: return csVector3 (MinX (), MaxY (), MaxZ ());
132  case BOX_CORNER_Xyz: return csVector3 (MaxX (), MinY (), MinZ ());
133  case BOX_CORNER_XyZ: return csVector3 (MaxX (), MinY (), MaxZ ());
134  case BOX_CORNER_XYz: return csVector3 (MaxX (), MaxY (), MinZ ());
135  case BOX_CORNER_XYZ: return Max ();
136  }
137  return csVector3 (0, 0, 0);
138 }
void csBox3::GetEdgeInfo ( int  edge,
int v1,
int v2,
int fleft,
int fright 
) const
inline

Given an edge index (BOX_EDGE_???) return the two vertices (index BOX_CORNER_???) and left/right faces (BOX_SIDE_???).

Definition at line 154 of file opbox.h.

References edges, csBox3::bEdge::fl, csBox3::bEdge::fr, csBox3::bEdge::v1, and csBox3::bEdge::v2.

155  {
156  v1 = edges[edge].v1;
157  v2 = edges[edge].v2;
158  fleft = edges[edge].fl;
159  fright = edges[edge].fr;
160  }
uint8* csBox3::GetFaceEdges ( int  face) const
inline

Given a face index (BOX_SIDE_???) return the four edges oriented clockwise around this face (BOX_EDGE_???).

Definition at line 166 of file opbox.h.

References faces.

167  {
168  return faces[face];
169  }
int csBox3::GetVisibleSides ( const csVector3 pos,
int visible_sides 
) const

Get a side of this box as a 2D box. Use BOX_SIDE_??? defines.

csBox2 GetSide (int side) const; Fill the array (which should be three long at least) with all visible sides (BOX_SIDE_??? defines) as seen from the given point. Returns the number of visible sides.

Definition at line 211 of file opbox.cpp.

References i, Max(), Min(), Outline::num_sides, Outline::sides, csVector3::x, csVector3::y, and csVector3::z.

212 {
213  const csVector3& bmin = Min ();
214  const csVector3& bmax = Max ();
215  int idx;
216  // First select x part of coordinate.
217  if (pos.x < bmin.x) idx = 0*9;
218  else if (pos.x > bmax.x) idx = 2*9;
219  else idx = 1*9;
220  // Then y part.
221  if (pos.y < bmin.y) idx += 0*3;
222  else if (pos.y > bmax.y) idx += 2*3;
223  else idx += 1*3;
224  // Then z part.
225  if (pos.z < bmin.z) idx += 0;
226  else if (pos.z > bmax.z) idx += 2;
227  else idx += 1;
228  const Outline& ol = outlines[idx];
229  int num_array = ol.num_sides;
230  int i;
231  for (i = 0 ; i < num_array ; i++)
232  visible_sides[i] = ol.sides[i];
233  return num_array;
234 }
bool csBox3::In ( float  x,
float  y,
float  z 
) const
inline

Test if the given coordinate is in this box.

Return every edge (segment) of this bounding box from 0 to 23 (use one of the BOX_EDGE_??? indices). The returned edge is undefined for any other index.

csSegment3 GetEdge (int edge) const { return csSegment3 (GetCorner (edges[edge].v1), GetCorner (edges[edge].v2)); } Return every edge (segment) of this bounding box from 0 to 23 (use one of the BOX_EDGE_??? indices). The returned edge is undefined for any other index.

void GetEdge (int edge, csSegment3& e) const { e.SetStart (GetCorner (edges[edge].v1)); e.SetEnd (GetCorner (edges[edge].v2)); }

Definition at line 232 of file opbox.h.

Referenced by In().

233  {
234  if (x < minbox.x || x > maxbox.x) return false;
235  if (y < minbox.y || y > maxbox.y) return false;
236  if (z < minbox.z || z > maxbox.z) return false;
237  return true;
238  }
bool csBox3::In ( const csVector3 v) const
inline

Test if the given coordinate is in this box.

Definition at line 241 of file opbox.h.

References In(), csVector3::x, csVector3::y, and csVector3::z.

242  {
243  return In (v.x, v.y, v.z);
244  }
void csBox3::ManhattanDistance ( const csBox3 other,
csVector3 dist 
) const

Calculate the minimum manhattan distance between this box and another one.

Definition at line 292 of file opbox.cpp.

References MaxX(), MaxY(), MaxZ(), MinX(), MinY(), MinZ(), csVector3::x, csVector3::y, and csVector3::z.

293 {
294  if (other.MinX () >= MaxX ()) dist.x = other.MinX () - MaxX ();
295  else if (MinX () >= other.MaxX ()) dist.x = MinX () - other.MaxX ();
296  else dist.x = 0;
297  if (other.MinY () >= MaxY ()) dist.y = other.MinY () - MaxY ();
298  else if (MinY () >= other.MaxY ()) dist.y = MinY () - other.MaxY ();
299  else dist.y = 0;
300  if (other.MinZ () >= MaxZ ()) dist.z = other.MinZ () - MaxZ ();
301  else if (MinZ () >= other.MaxZ ()) dist.z = MinZ () - other.MaxZ ();
302  else dist.z = 0;
303 }
float csBox3::Max ( int  idx) const
inline

Get Max component for 0 (x), 1 (y), or 2 (z).

Definition at line 133 of file opbox.h.

References maxbox, csVector3::x, csVector3::y, and csVector3::z.

134  { return idx == 1 ? maxbox.y : idx == 0 ? maxbox.x : maxbox.z; }
const csVector3& csBox3::Max ( ) const
inline

Get the 3d vector of maximum (x, y, z) values.

Definition at line 138 of file opbox.h.

References maxbox.

Referenced by GetConvexOutline(), GetCorner(), and GetVisibleSides().

138 { return maxbox; }
float csBox3::MaxX ( ) const
inline

Get the maximum X value of the box.

Definition at line 124 of file opbox.h.

References maxbox, and csVector3::x.

Referenced by Adjacent(), AdjacentX(), AdjacentY(), AdjacentZ(), GetCorner(), and ManhattanDistance().

124 { return maxbox.x; }
float csBox3::MaxY ( ) const
inline

Get the maximum Y value of the box.

Definition at line 126 of file opbox.h.

References maxbox, and csVector3::y.

Referenced by Adjacent(), AdjacentX(), AdjacentY(), AdjacentZ(), GetCorner(), and ManhattanDistance().

126 { return maxbox.y; }
float csBox3::MaxZ ( ) const
inline

Get the maximum Z value of the box.

Definition at line 128 of file opbox.h.

References maxbox, and csVector3::z.

Referenced by Adjacent(), AdjacentX(), AdjacentY(), AdjacentZ(), GetCorner(), and ManhattanDistance().

128 { return maxbox.z; }
float csBox3::Min ( int  idx) const
inline

Get Min component for 0 (x), 1 (y), or 2 (z).

Definition at line 130 of file opbox.h.

References minbox, csVector3::x, csVector3::y, and csVector3::z.

131  { return idx == 1 ? minbox.y : idx == 0 ? minbox.x : minbox.z; }
const csVector3& csBox3::Min ( ) const
inline

Get the 3d vector of minimum (x, y, z) values.

Definition at line 136 of file opbox.h.

References minbox.

Referenced by GetConvexOutline(), GetCorner(), and GetVisibleSides().

136 { return minbox; }
float csBox3::MinX ( ) const
inline

Get the minimum X value of the box.

Definition at line 118 of file opbox.h.

References minbox, and csVector3::x.

Referenced by AdjacentX(), AdjacentY(), AdjacentZ(), GetCorner(), and ManhattanDistance().

118 { return minbox.x; }
float csBox3::MinY ( ) const
inline

Get the minimum Y value of the box.

Definition at line 120 of file opbox.h.

References minbox, and csVector3::y.

Referenced by AdjacentX(), AdjacentY(), AdjacentZ(), GetCorner(), and ManhattanDistance().

120 { return minbox.y; }
float csBox3::MinZ ( ) const
inline

Get the minimum Z value of the box.

Definition at line 122 of file opbox.h.

References minbox, and csVector3::z.

Referenced by AdjacentX(), AdjacentY(), AdjacentZ(), GetCorner(), and ManhattanDistance().

122 { return minbox.z; }
csBox3 & csBox3::operator*= ( const csBox3 box)

Compute the intersection of two bounding boxes.

Definition at line 360 of file opbox.cpp.

References maxbox, minbox, csVector3::x, csVector3::y, and csVector3::z.

361 {
362  if (box.minbox.x > minbox.x) minbox.x = box.minbox.x;
363  if (box.minbox.y > minbox.y) minbox.y = box.minbox.y;
364  if (box.minbox.z > minbox.z) minbox.z = box.minbox.z;
365  if (box.maxbox.x < maxbox.x) maxbox.x = box.maxbox.x;
366  if (box.maxbox.y < maxbox.y) maxbox.y = box.maxbox.y;
367  if (box.maxbox.z < maxbox.z) maxbox.z = box.maxbox.z;
368  return *this;
369 }
csBox3 & csBox3::operator+= ( const csBox3 box)

Compute the union of two bounding boxes.

Definition at line 338 of file opbox.cpp.

References maxbox, minbox, csVector3::x, csVector3::y, and csVector3::z.

339 {
340  if (box.minbox.x < minbox.x) minbox.x = box.minbox.x;
341  if (box.minbox.y < minbox.y) minbox.y = box.minbox.y;
342  if (box.minbox.z < minbox.z) minbox.z = box.minbox.z;
343  if (box.maxbox.x > maxbox.x) maxbox.x = box.maxbox.x;
344  if (box.maxbox.y > maxbox.y) maxbox.y = box.maxbox.y;
345  if (box.maxbox.z > maxbox.z) maxbox.z = box.maxbox.z;
346  return *this;
347 }
csBox3 & csBox3::operator+= ( const csVector3 point)

Compute the union of a point with this bounding box.

Definition at line 349 of file opbox.cpp.

References maxbox, minbox, csVector3::x, csVector3::y, and csVector3::z.

350 {
351  if (point.x < minbox.x) minbox.x = point.x;
352  if (point.x > maxbox.x) maxbox.x = point.x;
353  if (point.y < minbox.y) minbox.y = point.y;
354  if (point.y > maxbox.y) maxbox.y = point.y;
355  if (point.z < minbox.z) minbox.z = point.z;
356  if (point.z > maxbox.z) maxbox.z = point.z;
357  return *this;
358 }
static int csBox3::OtherSide ( int  side)
inlinestatic

Static function to get the 'other' side (i.e. BOX_SIDE_X to BOX_SIDE_x, ...).

Definition at line 205 of file opbox.h.

206  {
207  return side ^ 1;
208  }
bool csBox3::Overlap ( const csBox3 box) const
inline

Test if this box overlaps with the given box.

Definition at line 247 of file opbox.h.

References maxbox, minbox, csVector3::x, csVector3::y, and csVector3::z.

248  {
249  if (maxbox.x < box.minbox.x || minbox.x > box.maxbox.x) return false;
250  if (maxbox.y < box.minbox.y || minbox.y > box.maxbox.y) return false;
251  if (maxbox.z < box.minbox.z || minbox.z > box.maxbox.z) return false;
252  return true;
253  }
void csBox3::Set ( const csVector3 bmin,
const csVector3 bmax 
)
inline

Sets the bounds of the box with the given values.

Definition at line 362 of file opbox.h.

References maxbox, and minbox.

363  {
364  minbox = bmin;
365  maxbox = bmax;
366  }
void csBox3::Set ( float  x1,
float  y1,
float  z1,
float  x2,
float  y2,
float  z2 
)
inline

Sets the bounds of the box with the given values.

Definition at line 369 of file opbox.h.

References maxbox, minbox, StartBoundingBox(), csVector3::x, csVector3::y, and csVector3::z.

370  {
371  if (x1>x2 || y1>y2 || z1>z2) StartBoundingBox();
372  else
373  {
374  minbox.x = x1; minbox.y = y1; minbox.z = z1;
375  maxbox.x = x2; maxbox.y = y2; maxbox.z = z2;
376  }
377  }
void csBox3::SetCenter ( const csVector3 c)

Set the center of this box. This will not change the size of the box but just relocate the center.

Definition at line 140 of file opbox.cpp.

References GetCenter(), maxbox, and minbox.

141 {
142  csVector3 move = c-GetCenter ();
143  minbox += move;
144  maxbox += move;
145 }
void csBox3::SetSize ( const csVector3 s)

Set the size of the box but keep the center intact.

Definition at line 147 of file opbox.cpp.

References center, float, GetCenter(), maxbox, and minbox.

148 {
150  minbox = center - s*(float).5;
151  maxbox = center + s*(float).5;
152 }
float csBox3::SquaredOriginDist ( ) const

Calculate the squared distance between (0,0,0) and the box This routine is extremely efficient.

Definition at line 306 of file opbox.cpp.

References maxbox, minbox, csVector3::x, csVector3::y, and csVector3::z.

307 {
308  // Thanks to Ivan Avramovic for the original.
309  // Adapted by Norman Kramer, Jorrit Tyberghein and Wouter Wijngaards.
310  float res = 0;
311  if (minbox.x > 0) res = minbox.x*minbox.x;
312  else if (maxbox.x < 0) res = maxbox.x*maxbox.x;
313  if (minbox.y > 0) res += minbox.y*minbox.y;
314  else if (maxbox.y < 0) res += maxbox.y*maxbox.y;
315  if (minbox.z > 0) res += minbox.z*minbox.z;
316  else if (maxbox.z < 0) res += maxbox.z*maxbox.z;;
317  return res;
318 }
float csBox3::SquaredOriginMaxDist ( ) const

Calculate the squared distance between (0,0,0) and the point on the box which is furthest away from (0,0,0). This routine is extremely efficient.

Definition at line 320 of file opbox.cpp.

References MAX, maxbox, minbox, csVector3::x, csVector3::y, and csVector3::z.

321 {
322  // Thanks to Ivan Avramovic for the original.
323  // Adapted by Norman Kramer, Jorrit Tyberghein and Wouter Wijngaards.
324  float res;
325  if (minbox.x > 0) res = maxbox.x*maxbox.x;
326  else if (maxbox.x < 0) res = minbox.x*minbox.x;
327  else res = MAX (maxbox.x*maxbox.x, minbox.x*minbox.x);
328  if (minbox.y > 0) res += maxbox.y*maxbox.y;
329  else if (maxbox.y < 0) res += minbox.y*minbox.y;
330  else res += MAX (maxbox.y*maxbox.y, minbox.y*minbox.y);
331  if (minbox.z > 0) res += maxbox.z*maxbox.z;
332  else if (maxbox.z < 0) res += minbox.z*minbox.z;
333  else res += MAX (maxbox.z*maxbox.z, minbox.z*minbox.z);
334  return res;
335 }
void csBox3::StartBoundingBox ( )
inline

Initialize this box to empty.

Definition at line 273 of file opbox.h.

References CS_BOUNDINGBOX_MAXVALUE, maxbox, minbox, csVector3::x, csVector3::y, and csVector3::z.

Referenced by csBox3(), and Set().

void csBox3::StartBoundingBox ( const csVector3 v)
inline

Initialize this box to one vertex.

Definition at line 284 of file opbox.h.

References maxbox, minbox, and v.

285  {
286  minbox = v; maxbox = v;
287  }

Friends And Related Function Documentation

bool operator!= ( const csBox3 box1,
const csBox3 box2 
)
friend

Tests if two bounding boxes are unequal.

Definition at line 414 of file opbox.cpp.

415 {
416  return ( (box1.minbox.x != box2.minbox.x)
417  || (box1.minbox.y != box2.minbox.y)
418  || (box1.minbox.z != box2.minbox.z)
419  || (box1.maxbox.x != box2.maxbox.x)
420  || (box1.maxbox.y != box2.maxbox.y)
421  || (box1.maxbox.z != box2.maxbox.z) );
422 }
csBox3 operator* ( const csBox3 box1,
const csBox3 box2 
)
friend

Compute the intersection of two bounding boxes.

Definition at line 393 of file opbox.cpp.

394 {
395  return csBox3(
396  MAX(box1.minbox.x,box2.minbox.x),
397  MAX(box1.minbox.y,box2.minbox.y),
398  MAX(box1.minbox.z,box2.minbox.z),
399  MIN(box1.maxbox.x,box2.maxbox.x),
400  MIN(box1.maxbox.y,box2.maxbox.y),
401  MIN(box1.maxbox.z,box2.maxbox.z));
402 }
csBox3 operator+ ( const csBox3 box1,
const csBox3 box2 
)
friend

Compute the union of two bounding boxes.

Definition at line 371 of file opbox.cpp.

372 {
373  return csBox3(
374  MIN(box1.minbox.x,box2.minbox.x),
375  MIN(box1.minbox.y,box2.minbox.y),
376  MIN(box1.minbox.z,box2.minbox.z),
377  MAX(box1.maxbox.x,box2.maxbox.x),
378  MAX(box1.maxbox.y,box2.maxbox.y),
379  MAX(box1.maxbox.z,box2.maxbox.z) );
380 }
csBox3 operator+ ( const csBox3 box,
const csVector3 point 
)
friend

Compute the union of a bounding box and a point.

Definition at line 382 of file opbox.cpp.

383 {
384  return csBox3(
385  MIN(box.minbox.x,point.x),
386  MIN(box.minbox.y,point.y),
387  MIN(box.minbox.z,point.z),
388  MAX(box.maxbox.x,point.x),
389  MAX(box.maxbox.y,point.y),
390  MAX(box.maxbox.z,point.z) );
391 }
bool operator< ( const csBox3 box1,
const csBox3 box2 
)
friend

Tests if box1 is a subset of box2.

Definition at line 424 of file opbox.cpp.

425 {
426  return ( (box1.minbox.x >= box2.minbox.x)
427  && (box1.minbox.y >= box2.minbox.y)
428  && (box1.minbox.z >= box2.minbox.z)
429  && (box1.maxbox.x <= box2.maxbox.x)
430  && (box1.maxbox.y <= box2.maxbox.y)
431  && (box1.maxbox.z <= box2.maxbox.z) );
432 }
bool operator< ( const csVector3 point,
const csBox3 box 
)
friend

Tests if a point is contained in a box.

Definition at line 444 of file opbox.cpp.

445 {
446  return ( (point.x >= box.minbox.x)
447  && (point.x <= box.maxbox.x)
448  && (point.y >= box.minbox.y)
449  && (point.y <= box.maxbox.y)
450  && (point.z >= box.minbox.z)
451  && (point.z <= box.maxbox.z) );
452 }
bool operator== ( const csBox3 box1,
const csBox3 box2 
)
friend

Tests if two bounding boxes are equal.

Definition at line 404 of file opbox.cpp.

405 {
406  return ( (box1.minbox.x == box2.minbox.x)
407  && (box1.minbox.y == box2.minbox.y)
408  && (box1.minbox.z == box2.minbox.z)
409  && (box1.maxbox.x == box2.maxbox.x)
410  && (box1.maxbox.y == box2.maxbox.y)
411  && (box1.maxbox.z == box2.maxbox.z) );
412 }
bool operator> ( const csBox3 box1,
const csBox3 box2 
)
friend

Tests if box1 is a superset of box2.

Definition at line 434 of file opbox.cpp.

435 {
436  return ( (box2.minbox.x >= box1.minbox.x)
437  && (box2.minbox.y >= box1.minbox.y)
438  && (box2.minbox.z >= box1.minbox.z)
439  && (box2.maxbox.x <= box1.maxbox.x)
440  && (box2.maxbox.y <= box1.maxbox.y)
441  && (box2.maxbox.z <= box1.maxbox.z) );
442 }

Member Data Documentation

csBox3::bEdge csBox3::edges
staticprotected
Initial value:

Definition at line 113 of file opbox.h.

Referenced by GetEdgeInfo().


The documentation for this class was generated from the following files: