## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# csgeom/box.h

Go to the documentation of this file.

    00001 /*
    00002     Copyright (C) 1998-2002 by Jorrit Tyberghein
    00003     Largely rewritten by Ivan Avramovic <ivan@avramovic.com>
    00004
    00005     This library is free software; you can redistribute it and/or
    00006     modify it under the terms of the GNU Library General Public
    00007     License as published by the Free Software Foundation; either
    00008     version 2 of the License, or (at your option) any later version.
    00009
    00010     This library is distributed in the hope that it will be useful,
    00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013     Library General Public License for more details.
    00014
    00015     You should have received a copy of the GNU Library General Public
    00016     License along with this library; if not, write to the Free
    00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00018 */
    00019
    00020 #ifndef __CS_BOX_H__
    00021 #define __CS_BOX_H__
    00022
    00030 #include "csextern.h"
    00031 #include "cstypes.h"    // for bool
    00032
    00033 #include "csgeom/csrect.h"
    00034 #include "csgeom/vector2.h"
    00035 #include "csgeom/vector3.h"
    00036 #include "csgeom/segment.h"
    00037
    00038 #include "csutil/array.h"
    00039
    00040 class csPoly2D;
    00041 class csString;
    00042 class csTransform;
    00043
    00048 #define CS_BOUNDINGBOX_MAXVALUE 1000000000.
    00049
    00053 enum
    00054 {
    00056   CS_BOX_CORNER_xy = 0,
    00058   CS_BOX_CORNER_xY = 1,
    00060   CS_BOX_CORNER_Xy = 2,
    00062   CS_BOX_CORNER_XY = 3,
    00064   CS_BOX_CENTER2 = 4
    00065 };
    00072 enum
    00073 {
    00075   CS_BOX_EDGE_xy_Xy = 0,
    00077   CS_BOX_EDGE_Xy_xy = 1,
    00079   CS_BOX_EDGE_Xy_XY = 2,
    00081   CS_BOX_EDGE_XY_Xy = 3,
    00083   CS_BOX_EDGE_XY_xY = 4,
    00085   CS_BOX_EDGE_xY_XY = 5,
    00087   CS_BOX_EDGE_xY_xy = 6,
    00089   CS_BOX_EDGE_xy_xY = 7
    00090 };
    00100 class CS_CRYSTALSPACE_EXPORT csBox2
    00101 {
    00102 private:
    00103   struct bEdge
    00104   {
    00105     uint8 v1, v2; // Indices of vertex in bounding box (CS_BOX_CORNER_...)
    00106   };
    00107   // Index by edge number. Edge e and e+1 with e even are opposite edges.
    00108   // (CS_BOX_EDGE_...)
    00109   static bEdge edges[8];
    00110
    00111 protected:
    00113   csVector2 minbox;
    00115   csVector2 maxbox;
    00116
    00117 public:
    00119   inline float MinX () const { return minbox.x; }
    00121   inline float MinY () const { return minbox.y; }
    00123   inline float MaxX () const { return maxbox.x; }
    00125   inline float MaxY () const { return maxbox.y; }
    00127   inline float Min (int idx) const { return idx ? minbox.y : minbox.x; }
    00129   inline float Max (int idx) const { return idx ? maxbox.y : maxbox.x; }
    00131   inline const csVector2& Min () const { return minbox; }
    00133   inline const csVector2& Max () const { return maxbox; }
    00135   inline float Area () const { return (MaxX()-MinX())*(MaxY()-MinY()); }
    00136
    00145   csVector2 GetCorner (int corner) const;
    00146
    00150   inline csVector2 GetCenter () const { return (minbox+maxbox)/2; }
    00151
    00156   void SetCenter (const csVector2& c);
    00157
    00161   void SetSize (const csVector2& s);
    00162
    00167   inline void GetEdgeInfo (int edge, int& v1, int& v2) const
    00168   {
    00169     v1 = edges[edge].v1;
    00170     v2 = edges[edge].v2;
    00171   }
    00172
    00177   inline csSegment2 GetEdge (int edge) const
    00178   {
    00179     return csSegment2 (GetCorner (edges[edge].v1), GetCorner (edges[edge].v2));
    00180   }
    00181
    00186   inline void GetEdge (int edge, csSegment2& e) const
    00187   {
    00188     e.SetStart (GetCorner (edges[edge].v1));
    00189     e.SetEnd (GetCorner (edges[edge].v2));
    00190   }
    00191
    00198   static bool Intersect (float minx, float miny, float maxx, float maxy,
    00199     csVector2* poly, int num_poly);
    00200
    00207   static inline bool Intersect (const csVector2& minbox, const csVector2& maxbox,
    00208     csVector2* poly, int num_poly)
    00209   {
    00210     return Intersect (minbox.x, minbox.y, maxbox.x, maxbox.y, poly, num_poly);
    00211   }
    00212
    00219   inline bool Intersect (csVector2* poly, int num_poly) const
    00220   {
    00221     return Intersect (minbox, maxbox, poly, num_poly);
    00222   }
    00223
    00225   inline bool In (float x, float y) const
    00226   {
    00227     if (x < minbox.x || x > maxbox.x) return false;
    00228     if (y < minbox.y || y > maxbox.y) return false;
    00229     return true;
    00230   }
    00231
    00233   inline bool In (const csVector2& v) const
    00234   {
    00235     return In (v.x, v.y);
    00236   }
    00237
    00239   inline bool Overlap (const csBox2& box) const
    00240   {
    00241     if (maxbox.x < box.minbox.x || minbox.x > box.maxbox.x) return false;
    00242     if (maxbox.y < box.minbox.y || minbox.y > box.maxbox.y) return false;
    00243     return true;
    00244   }
    00245
    00247   inline bool Contains (const csBox2& box) const
    00248   {
    00249     return (box.minbox.x >= minbox.x && box.maxbox.x <= maxbox.x) &&
    00250            (box.minbox.y >= minbox.y && box.maxbox.y <= maxbox.y);
    00251   }
    00252
    00254   inline bool Empty () const
    00255   {
    00256     if (minbox.x > maxbox.x) return true;
    00257     if (minbox.y > maxbox.y) return true;
    00258     return false;
    00259   }
    00260
    00265   float SquaredOriginDist () const;
    00266
    00272   float SquaredOriginMaxDist () const;
    00273
    00278   float SquaredPosDist (const csVector2& pos) const;
    00279
    00285   float SquaredPosMaxDist (const csVector2& pos) const;
    00286
    00288   inline void StartBoundingBox ()
    00289   {
    00290     minbox.x =  CS_BOUNDINGBOX_MAXVALUE;  minbox.y =  CS_BOUNDINGBOX_MAXVALUE;
    00291     maxbox.x = -CS_BOUNDINGBOX_MAXVALUE;  maxbox.y = -CS_BOUNDINGBOX_MAXVALUE;
    00292   }
    00293
    00295   inline void StartBoundingBox (const csVector2& v)
    00296   {
    00297     minbox = v;
    00298     maxbox = v;
    00299   }
    00300
    00302   inline void StartBoundingBox (float x, float y)
    00303   {
    00304     minbox.x = maxbox.x = x;
    00305     minbox.y = maxbox.y = y;
    00306   }
    00307
    00309   inline void AddBoundingVertex (float x, float y)
    00310   {
    00311     if (x < minbox.x) minbox.x = x;  if (x > maxbox.x) maxbox.x = x;
    00312     if (y < minbox.y) minbox.y = y;  if (y > maxbox.y) maxbox.y = y;
    00313   }
    00314
    00316   inline void AddBoundingVertex (const csVector2& v)
    00317   {
    00318     AddBoundingVertex (v.x, v.y);
    00319   }
    00320
    00326   inline void AddBoundingVertexSmart (float x, float y)
    00327   {
    00328     if (x < minbox.x) minbox.x = x; else if (x > maxbox.x) maxbox.x = x;
    00329     if (y < minbox.y) minbox.y = y; else if (y > maxbox.y) maxbox.y = y;
    00330   }
    00331
    00337   inline void AddBoundingVertexSmart (const csVector2& v)
    00338   {
    00339     AddBoundingVertexSmart (v.x, v.y);
    00340   }
    00341
    00346   inline bool AddBoundingVertexTest (float x, float y)
    00347   {
    00348     bool rc = false;
    00349     if (x < minbox.x) { minbox.x = x; rc = true; }
    00350     if (x > maxbox.x) { maxbox.x = x; rc = true; }
    00351     if (y < minbox.y) { minbox.y = y; rc = true; }
    00352     if (y > maxbox.y) { maxbox.y = y; rc = true; }
    00353     return rc;
    00354   }
    00355
    00360   inline bool AddBoundingVertexTest (const csVector2& v)
    00361   {
    00362     return AddBoundingVertexTest (v.x, v.y);
    00363   }
    00364
    00371   inline bool AddBoundingVertexSmartTest (float x, float y)
    00372   {
    00373     bool rc = false;
    00374     if (x < minbox.x) { minbox.x = x; rc = true; }
    00375     else if (x > maxbox.x) { maxbox.x = x; rc = true; }
    00376     if (y < minbox.y) { minbox.y = y; rc = true; }
    00377     else if (y > maxbox.y) { maxbox.y = y; rc = true; }
    00378     return rc;
    00379   }
    00380
    00387   inline bool AddBoundingVertexSmartTest (const csVector2& v)
    00388   {
    00389     return AddBoundingVertexSmartTest (v.x, v.y);
    00390   }
    00391
    00393   csBox2 () : minbox (CS_BOUNDINGBOX_MAXVALUE, CS_BOUNDINGBOX_MAXVALUE),
    00394              maxbox (-CS_BOUNDINGBOX_MAXVALUE, -CS_BOUNDINGBOX_MAXVALUE)
    00395   {}
    00396
    00398   csBox2 (const csVector2& v) : minbox (v.x, v.y), maxbox (v.x, v.y)
    00399   {}
    00400
    00402   csBox2 (float x1, float y1, float x2, float y2) :
    00403     minbox (x1, y1), maxbox (x2, y2)
    00404   { if (Empty ()) StartBoundingBox (); }
    00405
    00407   csBox2 (const csRect& r) : minbox (r.xmin, r.ymin), maxbox (r.xmax, r.ymax)
    00408   { }
    00409
    00411   inline void Set (const csVector2& bmin, const csVector2& bmax)
    00412   {
    00413     minbox = bmin;
    00414     maxbox = bmax;
    00415   }
    00416
    00418   inline void Set (float x1, float y1, float x2, float y2)
    00419   {
    00420     if (x1>x2 || y1>y2) StartBoundingBox();
    00421     else { minbox.x = x1;  minbox.y = y1;  maxbox.x = x2;  maxbox.y = y2; }
    00422   }
    00423
    00425   inline void SetMin (int idx, float val)
    00426   {
    00427     if (idx == 1) minbox.y = val;
    00428     else minbox.x = val;
    00429   }
    00430
    00432   inline void SetMax (int idx, float val)
    00433   {
    00434     if (idx == 1) maxbox.y = val;
    00435     else maxbox.x = val;
    00436   }
    00437
    00442   csString Description() const;
    00443
    00445   csBox2& operator+= (const csBox2& box);
    00447   csBox2& operator+= (const csVector2& point);
    00449   csBox2& operator*= (const csBox2& box);
    00451   bool TestIntersect (const csBox2& box) const;
    00452
    00454   friend CS_CRYSTALSPACE_EXPORT csBox2 operator+ (const csBox2& box1,
    00455     const csBox2& box2);
    00457   friend CS_CRYSTALSPACE_EXPORT csBox2 operator+ (const csBox2& box,
    00458     const csVector2& point);
    00460   friend CS_CRYSTALSPACE_EXPORT csBox2 operator* (const csBox2& box1,
    00461     const csBox2& box2);
    00462
    00464   friend CS_CRYSTALSPACE_EXPORT bool operator== (const csBox2& box1,
    00465     const csBox2& box2);
    00467   friend CS_CRYSTALSPACE_EXPORT bool operator!= (const csBox2& box1,
    00468     const csBox2& box2);
    00470   friend CS_CRYSTALSPACE_EXPORT bool operator< (const csBox2& box1,
    00471     const csBox2& box2);
    00473   friend CS_CRYSTALSPACE_EXPORT bool operator> (const csBox2& box1,
    00474     const csBox2& box2);
    00476   friend CS_CRYSTALSPACE_EXPORT bool operator< (const csVector2& point,
    00477     const csBox2& box);
    00478 };
    00479
    00484 enum
    00485 {
    00487   CS_BOX_CORNER_xyz = 0,
    00489   CS_BOX_CORNER_xyZ = 1,
    00491   CS_BOX_CORNER_xYz = 2,
    00493   CS_BOX_CORNER_xYZ = 3,
    00495   CS_BOX_CORNER_Xyz = 4,
    00497   CS_BOX_CORNER_XyZ = 5,
    00499   CS_BOX_CORNER_XYz = 6,
    00501   CS_BOX_CORNER_XYZ = 7,
    00503   CS_BOX_CENTER3 = 8
    00504 };
    00511 enum
    00512 {
    00514   CS_BOX_SIDE_x = 0,
    00516   CS_BOX_SIDE_X = 1,
    00518   CS_BOX_SIDE_y = 2,
    00520   CS_BOX_SIDE_Y = 3,
    00522   CS_BOX_SIDE_z = 4,
    00524   CS_BOX_SIDE_Z = 5,
    00526   CS_BOX_INSIDE = 6
    00527 };
    00534 enum
    00535 {
    00537   CS_BOX_EDGE_Xyz_xyz = 0,
    00539   CS_BOX_EDGE_xyz_Xyz = 1,
    00541   CS_BOX_EDGE_xyz_xYz = 2,
    00543   CS_BOX_EDGE_xYz_xyz = 3,
    00545   CS_BOX_EDGE_xYz_XYz = 4,
    00547   CS_BOX_EDGE_XYz_xYz = 5,
    00549   CS_BOX_EDGE_XYz_Xyz = 6,
    00551   CS_BOX_EDGE_Xyz_XYz = 7,
    00553   CS_BOX_EDGE_Xyz_XyZ = 8,
    00555   CS_BOX_EDGE_XyZ_Xyz = 9,
    00557   CS_BOX_EDGE_XyZ_XYZ = 10,
    00559   CS_BOX_EDGE_XYZ_XyZ = 11,
    00561   CS_BOX_EDGE_XYZ_XYz = 12,
    00563   CS_BOX_EDGE_XYz_XYZ = 13,
    00565   CS_BOX_EDGE_XYZ_xYZ = 14,
    00567   CS_BOX_EDGE_xYZ_XYZ = 15,
    00569   CS_BOX_EDGE_xYZ_xYz = 16,
    00571   CS_BOX_EDGE_xYz_xYZ = 17,
    00573   CS_BOX_EDGE_xYZ_xyZ = 18,
    00575   CS_BOX_EDGE_xyZ_xYZ = 19,
    00577   CS_BOX_EDGE_xyZ_xyz = 20,
    00579   CS_BOX_EDGE_xyz_xyZ = 21,
    00581   CS_BOX_EDGE_xyZ_XyZ = 22,
    00583   CS_BOX_EDGE_XyZ_xyZ = 23
    00584 };
    00594 class CS_CRYSTALSPACE_EXPORT csBox3
    00595 {
    00596 protected:
    00598   csVector3 minbox;
    00600   csVector3 maxbox;
    00604   struct bEdge
    00605   {
    00606     uint8 v1, v2; // Indices of vertex in bounding box (CS_BOX_CORNER_...)
    00607     uint8 fl, fr; // Indices of left/right faces sharing edge (CS_BOX_SIDE_...)
    00608   };
    00610   typedef uint8 bFace[4];
    00615   static bEdge edges[24];
    00617   static bFace faces[6];
    00618 public:
    00620   inline float MinX () const { return minbox.x; }
    00622   inline float MinY () const { return minbox.y; }
    00624   inline float MinZ () const { return minbox.z; }
    00626   inline float MaxX () const { return maxbox.x; }
    00628   inline float MaxY () const { return maxbox.y; }
    00630   inline float MaxZ () const { return maxbox.z; }
    00632   inline float Min (int idx) const
    00633   { return minbox[idx]; }
    00635   inline float Max (int idx) const
    00636   { return maxbox[idx]; }
    00638   inline const csVector3& Min () const { return minbox; }
    00640   inline const csVector3& Max () const { return maxbox; }
    00642   inline float Volume () const
    00643   { return (MaxX()-MinX())*(MaxY()-MinY())*(MaxZ()-MinZ()); }
    00644
    00654   csVector3 GetCorner (int corner) const;
    00655
    00661   inline void GetEdgeInfo (int edge, int& v1, int& v2, int& fleft, int& fright) const
    00662   {
    00663     v1 = edges[edge].v1;
    00664     v2 = edges[edge].v2;
    00665     fleft = edges[edge].fl;
    00666     fright = edges[edge].fr;
    00667   }
    00668
    00673   inline uint8* GetFaceEdges (int face) const
    00674   {
    00675     return faces[face];
    00676   }
    00677
    00681   inline csVector3 GetCenter () const { return (minbox+maxbox)/2; }
    00682
    00687   void SetCenter (const csVector3& c);
    00688
    00692   void SetSize (const csVector3& s);
    00693
    00697   inline csVector3 GetSize () const { return (maxbox-minbox); }
    00698
    00703   csBox2 GetSide (int side) const;
    00704
    00710   void GetAxisPlane (int side, int& axis, float& where) const;
    00711
    00718   int GetVisibleSides (const csVector3& pos, int* visible_sides) const;
    00719
    00724   static inline int OtherSide (int side)
    00725   {
    00726     return side ^ 1;
    00727   }
    00728
    00734   inline csSegment3 GetEdge (int edge) const
    00735   {
    00736     return csSegment3 (GetCorner (edges[edge].v1), GetCorner (edges[edge].v2));
    00737   }
    00738
    00744   inline void GetEdge (int edge, csSegment3& e) const
    00745   {
    00746     e.SetStart (GetCorner (edges[edge].v1));
    00747     e.SetEnd (GetCorner (edges[edge].v2));
    00748   }
    00749
    00751   inline bool In (float x, float y, float z) const
    00752   {
    00753     if (x < minbox.x || x > maxbox.x) return false;
    00754     if (y < minbox.y || y > maxbox.y) return false;
    00755     if (z < minbox.z || z > maxbox.z) return false;
    00756     return true;
    00757   }
    00758
    00760   inline bool In (const csVector3& v) const
    00761   {
    00762     return In (v.x, v.y, v.z);
    00763   }
    00764
    00766   inline bool Overlap (const csBox3& box) const
    00767   {
    00768     if (maxbox.x < box.minbox.x || minbox.x > box.maxbox.x) return false;
    00769     if (maxbox.y < box.minbox.y || minbox.y > box.maxbox.y) return false;
    00770     if (maxbox.z < box.minbox.z || minbox.z > box.maxbox.z) return false;
    00771     return true;
    00772   }
    00773
    00775   inline bool Contains (const csBox3& box) const
    00776   {
    00777     return (box.minbox.x >= minbox.x && box.maxbox.x <= maxbox.x) &&
    00778            (box.minbox.y >= minbox.y && box.maxbox.y <= maxbox.y) &&
    00779            (box.minbox.z >= minbox.z && box.maxbox.z <= maxbox.z);
    00780   }
    00781
    00783   inline bool Empty () const
    00784   {
    00785     if (minbox.x > maxbox.x) return true;
    00786     if (minbox.y > maxbox.y) return true;
    00787     if (minbox.z > maxbox.z) return true;
    00788     return false;
    00789   }
    00790
    00792   inline void StartBoundingBox ()
    00793   {
    00794     minbox.x =  CS_BOUNDINGBOX_MAXVALUE;
    00795     minbox.y =  CS_BOUNDINGBOX_MAXVALUE;
    00796     minbox.z =  CS_BOUNDINGBOX_MAXVALUE;
    00797     maxbox.x = -CS_BOUNDINGBOX_MAXVALUE;
    00798     maxbox.y = -CS_BOUNDINGBOX_MAXVALUE;
    00799     maxbox.z = -CS_BOUNDINGBOX_MAXVALUE;
    00800   }
    00801
    00803   inline void StartBoundingBox (const csVector3& v)
    00804   {
    00805     minbox = v; maxbox = v;
    00806   }
    00807
    00809   inline void AddBoundingVertex (float x, float y, float z)
    00810   {
    00811     if (x < minbox.x) minbox.x = x; if (x > maxbox.x) maxbox.x = x;
    00812     if (y < minbox.y) minbox.y = y; if (y > maxbox.y) maxbox.y = y;
    00813     if (z < minbox.z) minbox.z = z; if (z > maxbox.z) maxbox.z = z;
    00814   }
    00815
    00817   inline void AddBoundingVertex (const csVector3& v)
    00818   {
    00819     AddBoundingVertex (v.x, v.y, v.z);
    00820   }
    00821
    00827   inline void AddBoundingVertexSmart (float x, float y, float z)
    00828   {
    00829     if (x < minbox.x) minbox.x = x; else if (x > maxbox.x) maxbox.x = x;
    00830     if (y < minbox.y) minbox.y = y; else if (y > maxbox.y) maxbox.y = y;
    00831     if (z < minbox.z) minbox.z = z; else if (z > maxbox.z) maxbox.z = z;
    00832   }
    00833
    00839   inline void AddBoundingVertexSmart (const csVector3& v)
    00840   {
    00841     AddBoundingVertexSmart (v.x, v.y, v.z);
    00842   }
    00843
    00848   inline bool AddBoundingVertexTest (float x, float y, float z)
    00849   {
    00850     bool rc = false;
    00851     if (x < minbox.x) { minbox.x = x; rc = true; }
    00852     if (x > maxbox.x) { maxbox.x = x; rc = true; }
    00853     if (y < minbox.y) { minbox.y = y; rc = true; }
    00854     if (y > maxbox.y) { maxbox.y = y; rc = true; }
    00855     if (z < minbox.z) { minbox.z = z; rc = true; }
    00856     if (z > maxbox.z) { maxbox.z = z; rc = true; }
    00857     return rc;
    00858   }
    00859
    00864   inline bool AddBoundingVertexTest (const csVector3& v)
    00865   {
    00866     return AddBoundingVertexTest (v.x, v.y, v.z);
    00867   }
    00868
    00875   inline bool AddBoundingVertexSmartTest (float x, float y, float z)
    00876   {
    00877     bool rc = false;
    00878     if (x < minbox.x) { minbox.x = x; rc = true; }
    00879     else if (x > maxbox.x) { maxbox.x = x; rc = true; }
    00880     if (y < minbox.y) { minbox.y = y; rc = true; }
    00881     else if (y > maxbox.y) { maxbox.y = y; rc = true; }
    00882     if (z < minbox.z) { minbox.z = z; rc = true; }
    00883     else if (z > maxbox.z) { maxbox.z = z; rc = true; }
    00884     return rc;
    00885   }
    00886
    00893   inline bool AddBoundingVertexSmartTest (const csVector3& v)
    00894   {
    00895     return AddBoundingVertexSmartTest (v.x, v.y, v.z);
    00896   }
    00897
    00899   csBox3 () :
    00900     minbox ( CS_BOUNDINGBOX_MAXVALUE,
    00901              CS_BOUNDINGBOX_MAXVALUE,
    00902              CS_BOUNDINGBOX_MAXVALUE),
    00903     maxbox (-CS_BOUNDINGBOX_MAXVALUE,
    00904             -CS_BOUNDINGBOX_MAXVALUE,
    00905             -CS_BOUNDINGBOX_MAXVALUE) {}
    00906
    00908   csBox3 (const csVector3& v) : minbox (v), maxbox (v)
    00909   { }
    00910
    00912   csBox3 (const csVector3& v1, const csVector3& v2) :
    00913         minbox (v1), maxbox (v2)
    00914   { if (Empty ()) StartBoundingBox (); }
    00915
    00917   csBox3 (float x1, float y1, float z1, float x2, float y2, float z2) :
    00918     minbox (x1, y1, z1), maxbox (x2, y2, z2)
    00919   { if (Empty ()) StartBoundingBox (); }
    00920
    00922   inline void Set (const csVector3& bmin, const csVector3& bmax)
    00923   {
    00924     minbox = bmin;
    00925     maxbox = bmax;
    00926   }
    00927
    00929   inline void Set (float x1, float y1, float z1, float x2, float y2, float z2)
    00930   {
    00931     if (x1>x2 || y1>y2 || z1>z2) StartBoundingBox();
    00932     else
    00933     {
    00934       minbox.x = x1; minbox.y = y1; minbox.z = z1;
    00935       maxbox.x = x2; maxbox.y = y2; maxbox.z = z2;
    00936     }
    00937   }
    00938
    00940   inline void SetMin (int idx, float val)
    00941   {
    00942     if (idx == 1) minbox.y = val;
    00943     else if (idx == 0) minbox.x = val;
    00944     else minbox.z = val;
    00945   }
    00946
    00948   inline void SetMax (int idx, float val)
    00949   {
    00950     if (idx == 1) maxbox.y = val;
    00951     else if (idx == 0) maxbox.x = val;
    00952     else maxbox.z = val;
    00953   }
    00954
    00959   csString Description() const;
    00960
    00964   inline void Split (int axis, float where, csBox3& bl, csBox3& br) const
    00965   {
    00966     switch (axis)
    00967     {
    00968       case CS_AXIS_X:
    00969         bl.Set (minbox.x, minbox.y, minbox.z,
    00970                 where,    maxbox.y, maxbox.z);
    00971         br.Set (where,    minbox.y, minbox.z,
    00972                 maxbox.x, maxbox.y, maxbox.z);
    00973         break;
    00974       case CS_AXIS_Y:
    00975         bl.Set (minbox.x, minbox.y, minbox.z,
    00976                 maxbox.x, where,    maxbox.z);
    00977         br.Set (minbox.x, where,    minbox.z,
    00978                 maxbox.x, maxbox.y, maxbox.z);
    00979         break;
    00980       case CS_AXIS_Z:
    00981         bl.Set (minbox.x, minbox.y, minbox.z,
    00982                 maxbox.x, maxbox.y, where);
    00983         br.Set (minbox.x, minbox.y, where,
    00984                 maxbox.x, maxbox.y, maxbox.z);
    00985         break;
    00986     }
    00987   }
    00988
    00995   inline int TestSplit (int axis, float where) const
    00996   {
    00997     if (maxbox[axis] < where) return -1;
    00998     if (minbox[axis] > where) return 1;
    00999     return 0;
    01000   }
    01001
    01005   bool AdjacentX (const csBox3& other, float epsilon = SMALL_EPSILON) const;
    01006
    01010   bool AdjacentY (const csBox3& other, float epsilon = SMALL_EPSILON) const;
    01011
    01015   bool AdjacentZ (const csBox3& other, float epsilon = SMALL_EPSILON) const;
    01016
    01024   int Adjacent (const csBox3& other, float epsilon = SMALL_EPSILON) const;
    01025
    01032   int CalculatePointSegment (const csVector3& pos) const;
    01033
    01042   void GetConvexOutline (const csVector3& pos,
    01043         csVector3* array, int& num_array, bool bVisible=false) const;
    01044
    01048   bool Between (const csBox3& box1, const csBox3& box2) const;
    01049
    01054   void ManhattanDistance (const csBox3& other, csVector3& dist) const;
    01055
    01060   float SquaredOriginDist () const;
    01061
    01067   float SquaredOriginMaxDist () const;
    01068
    01073   float SquaredPosDist (const csVector3& pos) const;
    01074
    01080   float SquaredPosMaxDist (const csVector3& pos) const;
    01081
    01093   bool ProjectBox (const csTransform& trans, float fov, float sx, float sy,
    01094         csBox2& sbox, float& min_z, float& max_z) const;
    01095
    01105   bool ProjectOutline (const csTransform& trans, float fov, float sx, float sy,
    01106         csPoly2D& poly, float& min_z, float& max_z) const;
    01107
    01115   bool ProjectOutline (const csVector3& origin,
    01116         int axis, float where, csArray<csVector2>& poly) const;
    01117
    01123   bool ProjectOutline (const csVector3& origin,
    01124         int axis, float where, csPoly2D& poly) const;
    01125
    01138   bool ProjectBoxAndOutline (const csTransform& trans, float fov,
    01139         float sx, float sy, csBox2& sbox, csPoly2D& poly,
    01140         float& min_z, float& max_z) const;
    01141
    01143   csBox3& operator+= (const csBox3& box);
    01145   csBox3& operator+= (const csVector3& point);
    01147   csBox3& operator*= (const csBox3& box);
    01149   bool TestIntersect (const csBox3& box) const;
    01150
    01152   friend CS_CRYSTALSPACE_EXPORT csBox3 operator+ (const csBox3& box1,
    01153     const csBox3& box2);
    01155   friend CS_CRYSTALSPACE_EXPORT csBox3 operator+ (const csBox3& box,
    01156     const csVector3& point);
    01158   friend CS_CRYSTALSPACE_EXPORT csBox3 operator* (const csBox3& box1,
    01159     const csBox3& box2);
    01160
    01162   friend CS_CRYSTALSPACE_EXPORT bool operator== (const csBox3& box1,
    01163     const csBox3& box2);
    01165   friend CS_CRYSTALSPACE_EXPORT bool operator!= (const csBox3& box1,
    01166     const csBox3& box2);
    01168   friend CS_CRYSTALSPACE_EXPORT bool operator< (const csBox3& box1,
    01169     const csBox3& box2);
    01171   friend CS_CRYSTALSPACE_EXPORT bool operator> (const csBox3& box1,
    01172     const csBox3& box2);
    01174   friend CS_CRYSTALSPACE_EXPORT bool operator< (const csVector3& point,
    01175     const csBox3& box);
    01176 };
    01177
    01180 #endif // __CS_BOX_H__