CrystalSpace

Public API Reference

Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

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 
00275   inline void StartBoundingBox ()
00276   {
00277     minbox.x =  CS_BOUNDINGBOX_MAXVALUE;  minbox.y =  CS_BOUNDINGBOX_MAXVALUE;
00278     maxbox.x = -CS_BOUNDINGBOX_MAXVALUE;  maxbox.y = -CS_BOUNDINGBOX_MAXVALUE;
00279   }
00280 
00282   inline void StartBoundingBox (const csVector2& v)
00283   {
00284     minbox = v;
00285     maxbox = v;
00286   }
00287 
00289   inline void StartBoundingBox (float x, float y)
00290   {
00291     minbox.x = maxbox.x = x;
00292     minbox.y = maxbox.y = y;
00293   }
00294 
00296   inline void AddBoundingVertex (float x, float y)
00297   {
00298     if (x < minbox.x) minbox.x = x;  if (x > maxbox.x) maxbox.x = x;
00299     if (y < minbox.y) minbox.y = y;  if (y > maxbox.y) maxbox.y = y;
00300   }
00301 
00303   inline void AddBoundingVertex (const csVector2& v)
00304   {
00305     AddBoundingVertex (v.x, v.y);
00306   }
00307 
00313   inline void AddBoundingVertexSmart (float x, float y)
00314   {
00315     if (x < minbox.x) minbox.x = x; else if (x > maxbox.x) maxbox.x = x;
00316     if (y < minbox.y) minbox.y = y; else if (y > maxbox.y) maxbox.y = y;
00317   }
00318 
00324   inline void AddBoundingVertexSmart (const csVector2& v)
00325   {
00326     AddBoundingVertexSmart (v.x, v.y);
00327   }
00328 
00333   inline bool AddBoundingVertexTest (float x, float y)
00334   {
00335     bool rc = false;
00336     if (x < minbox.x) { minbox.x = x; rc = true; }
00337     if (x > maxbox.x) { maxbox.x = x; rc = true; }
00338     if (y < minbox.y) { minbox.y = y; rc = true; }
00339     if (y > maxbox.y) { maxbox.y = y; rc = true; }
00340     return rc;
00341   }
00342 
00347   inline bool AddBoundingVertexTest (const csVector2& v)
00348   {
00349     return AddBoundingVertexTest (v.x, v.y);
00350   }
00351 
00358   inline bool AddBoundingVertexSmartTest (float x, float y)
00359   {
00360     bool rc = false;
00361     if (x < minbox.x) { minbox.x = x; rc = true; }
00362     else if (x > maxbox.x) { maxbox.x = x; rc = true; }
00363     if (y < minbox.y) { minbox.y = y; rc = true; }
00364     else if (y > maxbox.y) { maxbox.y = y; rc = true; }
00365     return rc;
00366   }
00367 
00374   inline bool AddBoundingVertexSmartTest (const csVector2& v)
00375   {
00376     return AddBoundingVertexSmartTest (v.x, v.y);
00377   }
00378 
00380   csBox2 () : minbox (CS_BOUNDINGBOX_MAXVALUE, CS_BOUNDINGBOX_MAXVALUE),
00381              maxbox (-CS_BOUNDINGBOX_MAXVALUE, -CS_BOUNDINGBOX_MAXVALUE) 
00382   {}
00383 
00385   csBox2 (const csVector2& v) : minbox (v.x, v.y), maxbox (v.x, v.y) 
00386   {}
00387 
00389   csBox2 (float x1, float y1, float x2, float y2) :
00390     minbox (x1, y1), maxbox (x2, y2)
00391   { if (Empty ()) StartBoundingBox (); }
00392 
00394   csBox2 (const csRect& r) : minbox (r.xmin, r.ymin), maxbox (r.xmax, r.ymax)
00395   { }
00396   
00398   inline void Set (const csVector2& bmin, const csVector2& bmax)
00399   {
00400     minbox = bmin;
00401     maxbox = bmax;
00402   }
00403 
00405   inline void Set (float x1, float y1, float x2, float y2)
00406   {
00407     if (x1>x2 || y1>y2) StartBoundingBox();
00408     else { minbox.x = x1;  minbox.y = y1;  maxbox.x = x2;  maxbox.y = y2; }
00409   }
00410 
00412   inline void SetMin (int idx, float val)
00413   {
00414     if (idx == 1) minbox.y = val;
00415     else minbox.x = val;
00416   }
00417 
00419   inline void SetMax (int idx, float val)
00420   {
00421     if (idx == 1) maxbox.y = val;
00422     else maxbox.x = val;
00423   }
00424 
00429   csString Description() const;
00430 
00432   csBox2& operator+= (const csBox2& box);
00434   csBox2& operator+= (const csVector2& point);
00436   csBox2& operator*= (const csBox2& box);
00438   bool TestIntersect (const csBox2& box) const;
00439 
00441   friend CS_CRYSTALSPACE_EXPORT csBox2 operator+ (const csBox2& box1, 
00442     const csBox2& box2);
00444   friend CS_CRYSTALSPACE_EXPORT csBox2 operator+ (const csBox2& box, 
00445     const csVector2& point);
00447   friend CS_CRYSTALSPACE_EXPORT csBox2 operator* (const csBox2& box1, 
00448     const csBox2& box2);
00449 
00451   friend CS_CRYSTALSPACE_EXPORT bool operator== (const csBox2& box1, 
00452     const csBox2& box2);
00454   friend CS_CRYSTALSPACE_EXPORT bool operator!= (const csBox2& box1, 
00455     const csBox2& box2);
00457   friend CS_CRYSTALSPACE_EXPORT bool operator< (const csBox2& box1, 
00458     const csBox2& box2);
00460   friend CS_CRYSTALSPACE_EXPORT bool operator> (const csBox2& box1, 
00461     const csBox2& box2);
00463   friend CS_CRYSTALSPACE_EXPORT bool operator< (const csVector2& point, 
00464     const csBox2& box);
00465 };
00466 
00471 enum
00472 {
00474   CS_BOX_CORNER_xyz = 0,
00476   CS_BOX_CORNER_xyZ = 1,
00478   CS_BOX_CORNER_xYz = 2,
00480   CS_BOX_CORNER_xYZ = 3,
00482   CS_BOX_CORNER_Xyz = 4,
00484   CS_BOX_CORNER_XyZ = 5,
00486   CS_BOX_CORNER_XYz = 6,
00488   CS_BOX_CORNER_XYZ = 7,
00490   CS_BOX_CENTER3 = 8
00491 };
00498 enum
00499 {
00501   CS_BOX_SIDE_x = 0,
00503   CS_BOX_SIDE_X = 1,
00505   CS_BOX_SIDE_y = 2,
00507   CS_BOX_SIDE_Y = 3,
00509   CS_BOX_SIDE_z = 4,
00511   CS_BOX_SIDE_Z = 5,
00513   CS_BOX_INSIDE = 6
00514 };
00521 enum
00522 {
00524   CS_BOX_EDGE_Xyz_xyz = 0,
00526   CS_BOX_EDGE_xyz_Xyz = 1,
00528   CS_BOX_EDGE_xyz_xYz = 2,
00530   CS_BOX_EDGE_xYz_xyz = 3,
00532   CS_BOX_EDGE_xYz_XYz = 4,
00534   CS_BOX_EDGE_XYz_xYz = 5,
00536   CS_BOX_EDGE_XYz_Xyz = 6,
00538   CS_BOX_EDGE_Xyz_XYz = 7,
00540   CS_BOX_EDGE_Xyz_XyZ = 8,
00542   CS_BOX_EDGE_XyZ_Xyz = 9,
00544   CS_BOX_EDGE_XyZ_XYZ = 10,
00546   CS_BOX_EDGE_XYZ_XyZ = 11,
00548   CS_BOX_EDGE_XYZ_XYz = 12,
00550   CS_BOX_EDGE_XYz_XYZ = 13,
00552   CS_BOX_EDGE_XYZ_xYZ = 14,
00554   CS_BOX_EDGE_xYZ_XYZ = 15,
00556   CS_BOX_EDGE_xYZ_xYz = 16,
00558   CS_BOX_EDGE_xYz_xYZ = 17,
00560   CS_BOX_EDGE_xYZ_xyZ = 18,
00562   CS_BOX_EDGE_xyZ_xYZ = 19,
00564   CS_BOX_EDGE_xyZ_xyz = 20,
00566   CS_BOX_EDGE_xyz_xyZ = 21,
00568   CS_BOX_EDGE_xyZ_XyZ = 22,
00570   CS_BOX_EDGE_XyZ_xyZ = 23
00571 };
00581 class CS_CRYSTALSPACE_EXPORT csBox3
00582 {
00583 protected:
00585   csVector3 minbox;
00587   csVector3 maxbox;
00591   struct bEdge
00592   {
00593     uint8 v1, v2; // Indices of vertex in bounding box (CS_BOX_CORNER_...)
00594     uint8 fl, fr; // Indices of left/right faces sharing edge (CS_BOX_SIDE_...)
00595   };
00597   typedef uint8 bFace[4];       
00602   static bEdge edges[24];
00604   static bFace faces[6];
00605 public:
00607   inline float MinX () const { return minbox.x; }
00609   inline float MinY () const { return minbox.y; }
00611   inline float MinZ () const { return minbox.z; }
00613   inline float MaxX () const { return maxbox.x; }
00615   inline float MaxY () const { return maxbox.y; }
00617   inline float MaxZ () const { return maxbox.z; }
00619   inline float Min (int idx) const
00620   { return minbox[idx]; }
00622   inline float Max (int idx) const
00623   { return maxbox[idx]; }
00625   inline const csVector3& Min () const { return minbox; }
00627   inline const csVector3& Max () const { return maxbox; }
00629   inline float Volume () const
00630   { return (MaxX()-MinX())*(MaxY()-MinY())*(MaxZ()-MinZ()); }
00631 
00641   csVector3 GetCorner (int corner) const;
00642 
00648   inline void GetEdgeInfo (int edge, int& v1, int& v2, int& fleft, int& fright) const
00649   {
00650     v1 = edges[edge].v1;
00651     v2 = edges[edge].v2;
00652     fleft = edges[edge].fl;
00653     fright = edges[edge].fr;
00654   }
00655 
00660   inline uint8* GetFaceEdges (int face) const
00661   {
00662     return faces[face];
00663   }
00664 
00668   inline csVector3 GetCenter () const { return (minbox+maxbox)/2; }
00669 
00674   void SetCenter (const csVector3& c);
00675 
00679   void SetSize (const csVector3& s);
00680 
00684   inline csVector3 GetSize () const { return (maxbox-minbox); }
00685 
00690   csBox2 GetSide (int side) const;
00691 
00697   void GetAxisPlane (int side, int& axis, float& where) const;
00698 
00705   int GetVisibleSides (const csVector3& pos, int* visible_sides) const;
00706 
00711   static inline int OtherSide (int side)
00712   {
00713     return side ^ 1;
00714   }
00715 
00721   inline csSegment3 GetEdge (int edge) const
00722   {
00723     return csSegment3 (GetCorner (edges[edge].v1), GetCorner (edges[edge].v2));
00724   }
00725 
00731   inline void GetEdge (int edge, csSegment3& e) const
00732   {
00733     e.SetStart (GetCorner (edges[edge].v1));
00734     e.SetEnd (GetCorner (edges[edge].v2));
00735   }
00736 
00738   inline bool In (float x, float y, float z) const
00739   {
00740     if (x < minbox.x || x > maxbox.x) return false;
00741     if (y < minbox.y || y > maxbox.y) return false;
00742     if (z < minbox.z || z > maxbox.z) return false;
00743     return true;
00744   }
00745 
00747   inline bool In (const csVector3& v) const
00748   {
00749     return In (v.x, v.y, v.z);
00750   }
00751 
00753   inline bool Overlap (const csBox3& box) const
00754   {
00755     if (maxbox.x < box.minbox.x || minbox.x > box.maxbox.x) return false;
00756     if (maxbox.y < box.minbox.y || minbox.y > box.maxbox.y) return false;
00757     if (maxbox.z < box.minbox.z || minbox.z > box.maxbox.z) return false;
00758     return true;
00759   }
00760 
00762   inline bool Contains (const csBox3& box) const
00763   {
00764     return (box.minbox.x >= minbox.x && box.maxbox.x <= maxbox.x) &&
00765            (box.minbox.y >= minbox.y && box.maxbox.y <= maxbox.y) &&
00766            (box.minbox.z >= minbox.z && box.maxbox.z <= maxbox.z);
00767   }
00768 
00770   inline bool Empty () const
00771   {
00772     if (minbox.x > maxbox.x) return true;
00773     if (minbox.y > maxbox.y) return true;
00774     if (minbox.z > maxbox.z) return true;
00775     return false;
00776   }
00777 
00779   inline void StartBoundingBox ()
00780   {
00781     minbox.x =  CS_BOUNDINGBOX_MAXVALUE;
00782     minbox.y =  CS_BOUNDINGBOX_MAXVALUE;
00783     minbox.z =  CS_BOUNDINGBOX_MAXVALUE;
00784     maxbox.x = -CS_BOUNDINGBOX_MAXVALUE;
00785     maxbox.y = -CS_BOUNDINGBOX_MAXVALUE;
00786     maxbox.z = -CS_BOUNDINGBOX_MAXVALUE;
00787   }
00788 
00790   inline void StartBoundingBox (const csVector3& v)
00791   {
00792     minbox = v; maxbox = v;
00793   }
00794 
00796   inline void AddBoundingVertex (float x, float y, float z)
00797   {
00798     if (x < minbox.x) minbox.x = x; if (x > maxbox.x) maxbox.x = x;
00799     if (y < minbox.y) minbox.y = y; if (y > maxbox.y) maxbox.y = y;
00800     if (z < minbox.z) minbox.z = z; if (z > maxbox.z) maxbox.z = z;
00801   }
00802 
00804   inline void AddBoundingVertex (const csVector3& v)
00805   {
00806     AddBoundingVertex (v.x, v.y, v.z);
00807   }
00808 
00814   inline void AddBoundingVertexSmart (float x, float y, float z)
00815   {
00816     if (x < minbox.x) minbox.x = x; else if (x > maxbox.x) maxbox.x = x;
00817     if (y < minbox.y) minbox.y = y; else if (y > maxbox.y) maxbox.y = y;
00818     if (z < minbox.z) minbox.z = z; else if (z > maxbox.z) maxbox.z = z;
00819   }
00820 
00826   inline void AddBoundingVertexSmart (const csVector3& v)
00827   {
00828     AddBoundingVertexSmart (v.x, v.y, v.z);
00829   }
00830 
00835   inline bool AddBoundingVertexTest (float x, float y, float z)
00836   {
00837     bool rc = false;
00838     if (x < minbox.x) { minbox.x = x; rc = true; }
00839     if (x > maxbox.x) { maxbox.x = x; rc = true; }
00840     if (y < minbox.y) { minbox.y = y; rc = true; }
00841     if (y > maxbox.y) { maxbox.y = y; rc = true; }
00842     if (z < minbox.z) { minbox.z = z; rc = true; }
00843     if (z > maxbox.z) { maxbox.z = z; rc = true; }
00844     return rc;
00845   }
00846 
00851   inline bool AddBoundingVertexTest (const csVector3& v)
00852   {
00853     return AddBoundingVertexTest (v.x, v.y, v.z);
00854   }
00855 
00862   inline bool AddBoundingVertexSmartTest (float x, float y, float z)
00863   {
00864     bool rc = false;
00865     if (x < minbox.x) { minbox.x = x; rc = true; }
00866     else if (x > maxbox.x) { maxbox.x = x; rc = true; }
00867     if (y < minbox.y) { minbox.y = y; rc = true; }
00868     else if (y > maxbox.y) { maxbox.y = y; rc = true; }
00869     if (z < minbox.z) { minbox.z = z; rc = true; }
00870     else if (z > maxbox.z) { maxbox.z = z; rc = true; }
00871     return rc;
00872   }
00873 
00880   inline bool AddBoundingVertexSmartTest (const csVector3& v)
00881   {
00882     return AddBoundingVertexSmartTest (v.x, v.y, v.z);
00883   }
00884 
00886   csBox3 () :
00887     minbox ( CS_BOUNDINGBOX_MAXVALUE,
00888              CS_BOUNDINGBOX_MAXVALUE,
00889              CS_BOUNDINGBOX_MAXVALUE),
00890     maxbox (-CS_BOUNDINGBOX_MAXVALUE,
00891             -CS_BOUNDINGBOX_MAXVALUE,
00892             -CS_BOUNDINGBOX_MAXVALUE) {}
00893 
00895   csBox3 (const csVector3& v) : minbox (v), maxbox (v) 
00896   { }
00897 
00899   csBox3 (const csVector3& v1, const csVector3& v2) :
00900         minbox (v1), maxbox (v2)
00901   { if (Empty ()) StartBoundingBox (); }
00902 
00904   csBox3 (float x1, float y1, float z1, float x2, float y2, float z2) :
00905     minbox (x1, y1, z1), maxbox (x2, y2, z2)
00906   { if (Empty ()) StartBoundingBox (); }
00907 
00909   inline void Set (const csVector3& bmin, const csVector3& bmax)
00910   {
00911     minbox = bmin;
00912     maxbox = bmax;
00913   }
00914 
00916   inline void Set (float x1, float y1, float z1, float x2, float y2, float z2)
00917   {
00918     if (x1>x2 || y1>y2 || z1>z2) StartBoundingBox();
00919     else
00920     {
00921       minbox.x = x1; minbox.y = y1; minbox.z = z1;
00922       maxbox.x = x2; maxbox.y = y2; maxbox.z = z2;
00923     }
00924   }
00925 
00927   inline void SetMin (int idx, float val)
00928   {
00929     if (idx == 1) minbox.y = val;
00930     else if (idx == 0) minbox.x = val;
00931     else minbox.z = val;
00932   }
00933 
00935   inline void SetMax (int idx, float val)
00936   {
00937     if (idx == 1) maxbox.y = val;
00938     else if (idx == 0) maxbox.x = val;
00939     else maxbox.z = val;
00940   }
00941 
00946   csString Description() const;
00947 
00951   inline void Split (int axis, float where, csBox3& bl, csBox3& br) const
00952   {
00953     switch (axis)
00954     {
00955       case CS_AXIS_X:
00956         bl.Set (minbox.x, minbox.y, minbox.z,
00957                 where,    maxbox.y, maxbox.z);
00958         br.Set (where,    minbox.y, minbox.z,
00959                 maxbox.x, maxbox.y, maxbox.z);
00960         break;
00961       case CS_AXIS_Y:
00962         bl.Set (minbox.x, minbox.y, minbox.z,
00963                 maxbox.x, where,    maxbox.z);
00964         br.Set (minbox.x, where,    minbox.z,
00965                 maxbox.x, maxbox.y, maxbox.z);
00966         break;
00967       case CS_AXIS_Z:
00968         bl.Set (minbox.x, minbox.y, minbox.z,
00969                 maxbox.x, maxbox.y, where);
00970         br.Set (minbox.x, minbox.y, where,
00971                 maxbox.x, maxbox.y, maxbox.z);
00972         break;
00973     }
00974   }
00975 
00982   inline int TestSplit (int axis, float where) const
00983   {
00984     if (maxbox[axis] < where) return -1;
00985     if (minbox[axis] > where) return 1;
00986     return 0;
00987   }
00988 
00992   bool AdjacentX (const csBox3& other, float epsilon = SMALL_EPSILON) const;
00993 
00997   bool AdjacentY (const csBox3& other, float epsilon = SMALL_EPSILON) const;
00998 
01002   bool AdjacentZ (const csBox3& other, float epsilon = SMALL_EPSILON) const;
01003 
01011   int Adjacent (const csBox3& other, float epsilon = SMALL_EPSILON) const;
01012 
01019   int CalculatePointSegment (const csVector3& pos) const;
01020 
01029   void GetConvexOutline (const csVector3& pos,
01030         csVector3* array, int& num_array, bool bVisible=false) const;
01031 
01035   bool Between (const csBox3& box1, const csBox3& box2) const;
01036 
01041   void ManhattanDistance (const csBox3& other, csVector3& dist) const;
01042 
01047   float SquaredOriginDist () const;
01048 
01054   float SquaredOriginMaxDist () const;
01055 
01067   bool ProjectBox (const csTransform& trans, float fov, float sx, float sy,
01068         csBox2& sbox, float& min_z, float& max_z) const;
01069 
01079   bool ProjectOutline (const csTransform& trans, float fov, float sx, float sy,
01080         csPoly2D& poly, float& min_z, float& max_z) const;
01081 
01089   bool ProjectOutline (const csVector3& origin,
01090         int axis, float where, csArray<csVector2>& poly) const;
01091 
01097   bool ProjectOutline (const csVector3& origin,
01098         int axis, float where, csPoly2D& poly) const;
01099 
01112   bool ProjectBoxAndOutline (const csTransform& trans, float fov,
01113         float sx, float sy, csBox2& sbox, csPoly2D& poly,
01114         float& min_z, float& max_z) const;
01115 
01117   csBox3& operator+= (const csBox3& box);
01119   csBox3& operator+= (const csVector3& point);
01121   csBox3& operator*= (const csBox3& box);
01123   bool TestIntersect (const csBox3& box) const;
01124 
01126   friend CS_CRYSTALSPACE_EXPORT csBox3 operator+ (const csBox3& box1, 
01127     const csBox3& box2);
01129   friend CS_CRYSTALSPACE_EXPORT csBox3 operator+ (const csBox3& box, 
01130     const csVector3& point);
01132   friend CS_CRYSTALSPACE_EXPORT csBox3 operator* (const csBox3& box1, 
01133     const csBox3& box2);
01134 
01136   friend CS_CRYSTALSPACE_EXPORT bool operator== (const csBox3& box1, 
01137     const csBox3& box2);
01139   friend CS_CRYSTALSPACE_EXPORT bool operator!= (const csBox3& box1, 
01140     const csBox3& box2);
01142   friend CS_CRYSTALSPACE_EXPORT bool operator< (const csBox3& box1, 
01143     const csBox3& box2);
01145   friend CS_CRYSTALSPACE_EXPORT bool operator> (const csBox3& box1, 
01146     const csBox3& box2);
01148   friend CS_CRYSTALSPACE_EXPORT bool operator< (const csVector3& point, 
01149     const csBox3& box);
01150 };
01151 
01154 #endif // __CS_BOX_H__

Generated for Crystal Space by doxygen 1.4.4