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/math.h" 00035 #include "csgeom/matrix4.h" 00036 #include "csgeom/vector2.h" 00037 #include "csgeom/vector3.h" 00038 #include "csgeom/segment.h" 00039 00040 #include "csutil/array.h" 00041 00042 class csPoly2D; 00043 class csString; 00044 class csTransform; 00045 00050 #define CS_BOUNDINGBOX_MAXVALUE 1000000000. 00051 00055 enum 00056 { 00058 CS_BOX_CORNER_xy = 0, 00060 CS_BOX_CORNER_xY = 1, 00062 CS_BOX_CORNER_Xy = 2, 00064 CS_BOX_CORNER_XY = 3, 00066 CS_BOX_CENTER2 = 4 00067 }; 00074 enum 00075 { 00077 CS_BOX_EDGE_xy_Xy = 0, 00079 CS_BOX_EDGE_Xy_xy = 1, 00081 CS_BOX_EDGE_Xy_XY = 2, 00083 CS_BOX_EDGE_XY_Xy = 3, 00085 CS_BOX_EDGE_XY_xY = 4, 00087 CS_BOX_EDGE_xY_XY = 5, 00089 CS_BOX_EDGE_xY_xy = 6, 00091 CS_BOX_EDGE_xy_xY = 7 00092 }; 00102 class CS_CRYSTALSPACE_EXPORT csBox2 00103 { 00104 private: 00105 struct bEdge 00106 { 00107 uint8 v1, v2; // Indices of vertex in bounding box (CS_BOX_CORNER_...) 00108 }; 00109 // Index by edge number. Edge e and e+1 with e even are opposite edges. 00110 // (CS_BOX_EDGE_...) 00111 static const bEdge edges[8]; 00112 00113 protected: 00115 csVector2 minbox; 00117 csVector2 maxbox; 00118 00119 public: 00121 inline float MinX () const { return minbox.x; } 00123 inline float MinY () const { return minbox.y; } 00125 inline float MaxX () const { return maxbox.x; } 00127 inline float MaxY () const { return maxbox.y; } 00129 inline float Min (int idx) const { return idx ? minbox.y : minbox.x; } 00131 inline float Max (int idx) const { return idx ? maxbox.y : maxbox.x; } 00133 inline const csVector2& Min () const { return minbox; } 00135 inline const csVector2& Max () const { return maxbox; } 00137 inline float Area () const { return (MaxX()-MinX())*(MaxY()-MinY()); } 00138 00147 csVector2 GetCorner (int corner) const; 00148 00152 inline csVector2 GetCenter () const { return (minbox+maxbox)/2; } 00153 00158 void SetCenter (const csVector2& c); 00159 00163 void SetSize (const csVector2& s); 00164 00169 inline void GetEdgeInfo (int edge, int& v1, int& v2) const 00170 { 00171 v1 = edges[edge].v1; 00172 v2 = edges[edge].v2; 00173 } 00174 00179 inline csSegment2 GetEdge (int edge) const 00180 { 00181 return csSegment2 (GetCorner (edges[edge].v1), GetCorner (edges[edge].v2)); 00182 } 00183 00188 inline void GetEdge (int edge, csSegment2& e) const 00189 { 00190 e.SetStart (GetCorner (edges[edge].v1)); 00191 e.SetEnd (GetCorner (edges[edge].v2)); 00192 } 00193 00200 static bool Intersect (float minx, float miny, float maxx, float maxy, 00201 csVector2* poly, int num_poly); 00202 00209 static inline bool Intersect (const csVector2& minbox, const csVector2& maxbox, 00210 csVector2* poly, int num_poly) 00211 { 00212 return Intersect (minbox.x, minbox.y, maxbox.x, maxbox.y, poly, num_poly); 00213 } 00214 00221 inline bool Intersect (csVector2* poly, int num_poly) const 00222 { 00223 return Intersect (minbox, maxbox, poly, num_poly); 00224 } 00225 00227 inline bool In (float x, float y) const 00228 { 00229 if (x < minbox.x || x > maxbox.x) return false; 00230 if (y < minbox.y || y > maxbox.y) return false; 00231 return true; 00232 } 00233 00235 inline bool In (const csVector2& v) const 00236 { 00237 return In (v.x, v.y); 00238 } 00239 00241 inline bool Overlap (const csBox2& box) const 00242 { 00243 if (maxbox.x < box.minbox.x || minbox.x > box.maxbox.x) return false; 00244 if (maxbox.y < box.minbox.y || minbox.y > box.maxbox.y) return false; 00245 return true; 00246 } 00247 00249 inline bool Contains (const csBox2& box) const 00250 { 00251 return (box.minbox.x >= minbox.x && box.maxbox.x <= maxbox.x) && 00252 (box.minbox.y >= minbox.y && box.maxbox.y <= maxbox.y); 00253 } 00254 00256 inline bool Empty () const 00257 { 00258 if (minbox.x > maxbox.x) return true; 00259 if (minbox.y > maxbox.y) return true; 00260 return false; 00261 } 00262 00268 float SquaredOriginDist () const; 00269 00275 float SquaredOriginMaxDist () const; 00276 00282 float SquaredPosDist (const csVector2& pos) const; 00283 00289 float SquaredPosMaxDist (const csVector2& pos) const; 00290 00292 inline void StartBoundingBox () 00293 { 00294 minbox.x = CS_BOUNDINGBOX_MAXVALUE; minbox.y = CS_BOUNDINGBOX_MAXVALUE; 00295 maxbox.x = -CS_BOUNDINGBOX_MAXVALUE; maxbox.y = -CS_BOUNDINGBOX_MAXVALUE; 00296 } 00297 00299 inline void StartBoundingBox (const csVector2& v) 00300 { 00301 minbox = v; 00302 maxbox = v; 00303 } 00304 00306 inline void StartBoundingBox (float x, float y) 00307 { 00308 minbox.x = maxbox.x = x; 00309 minbox.y = maxbox.y = y; 00310 } 00311 00313 inline void AddBoundingVertex (float x, float y) 00314 { 00315 if (x < minbox.x) minbox.x = x; if (x > maxbox.x) maxbox.x = x; 00316 if (y < minbox.y) minbox.y = y; if (y > maxbox.y) maxbox.y = y; 00317 } 00318 00320 inline void AddBoundingVertex (const csVector2& v) 00321 { 00322 AddBoundingVertex (v.x, v.y); 00323 } 00324 00330 inline void AddBoundingVertexSmart (float x, float y) 00331 { 00332 if (x < minbox.x) minbox.x = x; else if (x > maxbox.x) maxbox.x = x; 00333 if (y < minbox.y) minbox.y = y; else if (y > maxbox.y) maxbox.y = y; 00334 } 00335 00341 inline void AddBoundingVertexSmart (const csVector2& v) 00342 { 00343 AddBoundingVertexSmart (v.x, v.y); 00344 } 00345 00350 inline bool AddBoundingVertexTest (float x, float y) 00351 { 00352 bool rc = false; 00353 if (x < minbox.x) { minbox.x = x; rc = true; } 00354 if (x > maxbox.x) { maxbox.x = x; rc = true; } 00355 if (y < minbox.y) { minbox.y = y; rc = true; } 00356 if (y > maxbox.y) { maxbox.y = y; rc = true; } 00357 return rc; 00358 } 00359 00364 inline bool AddBoundingVertexTest (const csVector2& v) 00365 { 00366 return AddBoundingVertexTest (v.x, v.y); 00367 } 00368 00375 inline bool AddBoundingVertexSmartTest (float x, float y) 00376 { 00377 bool rc = false; 00378 if (x < minbox.x) { minbox.x = x; rc = true; } 00379 else if (x > maxbox.x) { maxbox.x = x; rc = true; } 00380 if (y < minbox.y) { minbox.y = y; rc = true; } 00381 else if (y > maxbox.y) { maxbox.y = y; rc = true; } 00382 return rc; 00383 } 00384 00391 inline bool AddBoundingVertexSmartTest (const csVector2& v) 00392 { 00393 return AddBoundingVertexSmartTest (v.x, v.y); 00394 } 00395 00397 csBox2 () : minbox (CS_BOUNDINGBOX_MAXVALUE, CS_BOUNDINGBOX_MAXVALUE), 00398 maxbox (-CS_BOUNDINGBOX_MAXVALUE, -CS_BOUNDINGBOX_MAXVALUE) 00399 {} 00400 00402 csBox2 (const csVector2& v) : minbox (v.x, v.y), maxbox (v.x, v.y) 00403 {} 00404 00406 csBox2 (float x1, float y1, float x2, float y2) : 00407 minbox (x1, y1), maxbox (x2, y2) 00408 { if (Empty ()) StartBoundingBox (); } 00409 00411 csBox2 (const csRect& r) : minbox (r.xmin, r.ymin), maxbox (r.xmax, r.ymax) 00412 { } 00413 00415 inline void Set (const csVector2& bmin, const csVector2& bmax) 00416 { 00417 minbox = bmin; 00418 maxbox = bmax; 00419 } 00420 00422 inline void Set (float x1, float y1, float x2, float y2) 00423 { 00424 if (x1>x2 || y1>y2) StartBoundingBox(); 00425 else { minbox.x = x1; minbox.y = y1; maxbox.x = x2; maxbox.y = y2; } 00426 } 00427 00429 inline void SetMin (int idx, float val) 00430 { 00431 if (idx == 1) minbox.y = val; 00432 else minbox.x = val; 00433 } 00434 00436 inline void SetMax (int idx, float val) 00437 { 00438 if (idx == 1) maxbox.y = val; 00439 else maxbox.x = val; 00440 } 00441 00446 csString Description() const; 00447 00449 csBox2& operator+= (const csBox2& box); 00451 csBox2& operator+= (const csVector2& point); 00453 csBox2& operator*= (const csBox2& box); 00455 bool TestIntersect (const csBox2& box) const; 00456 00458 friend CS_CRYSTALSPACE_EXPORT csBox2 operator+ (const csBox2& box1, 00459 const csBox2& box2); 00461 friend CS_CRYSTALSPACE_EXPORT csBox2 operator+ (const csBox2& box, 00462 const csVector2& point); 00464 friend CS_CRYSTALSPACE_EXPORT csBox2 operator* (const csBox2& box1, 00465 const csBox2& box2); 00466 00468 friend CS_CRYSTALSPACE_EXPORT bool operator== (const csBox2& box1, 00469 const csBox2& box2); 00471 friend CS_CRYSTALSPACE_EXPORT bool operator!= (const csBox2& box1, 00472 const csBox2& box2); 00474 friend CS_CRYSTALSPACE_EXPORT bool operator< (const csBox2& box1, 00475 const csBox2& box2); 00477 friend CS_CRYSTALSPACE_EXPORT bool operator> (const csBox2& box1, 00478 const csBox2& box2); 00480 friend CS_CRYSTALSPACE_EXPORT bool operator< (const csVector2& point, 00481 const csBox2& box); 00482 }; 00483 00488 enum 00489 { 00491 CS_BOX_CORNER_xyz = 0, 00493 CS_BOX_CORNER_xyZ = 1, 00495 CS_BOX_CORNER_xYz = 2, 00497 CS_BOX_CORNER_xYZ = 3, 00499 CS_BOX_CORNER_Xyz = 4, 00501 CS_BOX_CORNER_XyZ = 5, 00503 CS_BOX_CORNER_XYz = 6, 00505 CS_BOX_CORNER_XYZ = 7, 00507 CS_BOX_CENTER3 = 8 00508 }; 00515 enum 00516 { 00518 CS_BOX_SIDE_x = 0, 00520 CS_BOX_SIDE_X = 1, 00522 CS_BOX_SIDE_y = 2, 00524 CS_BOX_SIDE_Y = 3, 00526 CS_BOX_SIDE_z = 4, 00528 CS_BOX_SIDE_Z = 5, 00530 CS_BOX_INSIDE = 6 00531 }; 00538 enum 00539 { 00541 CS_BOX_EDGE_Xyz_xyz = 0, 00543 CS_BOX_EDGE_xyz_Xyz = 1, 00545 CS_BOX_EDGE_xyz_xYz = 2, 00547 CS_BOX_EDGE_xYz_xyz = 3, 00549 CS_BOX_EDGE_xYz_XYz = 4, 00551 CS_BOX_EDGE_XYz_xYz = 5, 00553 CS_BOX_EDGE_XYz_Xyz = 6, 00555 CS_BOX_EDGE_Xyz_XYz = 7, 00557 CS_BOX_EDGE_Xyz_XyZ = 8, 00559 CS_BOX_EDGE_XyZ_Xyz = 9, 00561 CS_BOX_EDGE_XyZ_XYZ = 10, 00563 CS_BOX_EDGE_XYZ_XyZ = 11, 00565 CS_BOX_EDGE_XYZ_XYz = 12, 00567 CS_BOX_EDGE_XYz_XYZ = 13, 00569 CS_BOX_EDGE_XYZ_xYZ = 14, 00571 CS_BOX_EDGE_xYZ_XYZ = 15, 00573 CS_BOX_EDGE_xYZ_xYz = 16, 00575 CS_BOX_EDGE_xYz_xYZ = 17, 00577 CS_BOX_EDGE_xYZ_xyZ = 18, 00579 CS_BOX_EDGE_xyZ_xYZ = 19, 00581 CS_BOX_EDGE_xyZ_xyz = 20, 00583 CS_BOX_EDGE_xyz_xyZ = 21, 00585 CS_BOX_EDGE_xyZ_XyZ = 22, 00587 CS_BOX_EDGE_XyZ_xyZ = 23 00588 }; 00598 class CS_CRYSTALSPACE_EXPORT csBox3 00599 { 00600 protected: 00602 csVector3 minbox; 00604 csVector3 maxbox; 00608 struct bEdge 00609 { 00610 uint8 v1, v2; // Indices of vertex in bounding box (CS_BOX_CORNER_...) 00611 uint8 fl, fr; // Indices of left/right faces sharing edge (CS_BOX_SIDE_...) 00612 }; 00614 typedef uint8 bFace[4]; 00619 static const bEdge edges[24]; 00621 static const bFace faces[6]; 00623 struct Outline 00624 { 00625 int num; 00626 int vertices[8]; 00627 int num_sides; 00628 int sides[3]; 00629 }; 00631 static const Outline outlines[27]; 00632 public: 00634 inline float MinX () const { return minbox.x; } 00636 inline float MinY () const { return minbox.y; } 00638 inline float MinZ () const { return minbox.z; } 00640 inline float MaxX () const { return maxbox.x; } 00642 inline float MaxY () const { return maxbox.y; } 00644 inline float MaxZ () const { return maxbox.z; } 00646 inline float Min (size_t idx) const 00647 { return minbox[idx]; } 00649 inline float Max (size_t idx) const 00650 { return maxbox[idx]; } 00652 inline const csVector3& Min () const { return minbox; } 00654 inline const csVector3& Max () const { return maxbox; } 00656 inline float Volume () const 00657 { return (MaxX()-MinX())*(MaxY()-MinY())*(MaxZ()-MinZ()); } 00659 inline float Area () const 00660 { 00661 float x = MaxX()-MinX(); 00662 float y = MaxY()-MinY(); 00663 float z = MaxZ()-MinZ(); 00664 return 2.0f*(x*y + x*z + y*z); 00665 } 00666 00670 bool IsNaN () const 00671 { 00672 if (CS::IsNaN (minbox.x)) return true; 00673 if (CS::IsNaN (minbox.y)) return true; 00674 if (CS::IsNaN (minbox.z)) return true; 00675 if (CS::IsNaN (maxbox.x)) return true; 00676 if (CS::IsNaN (maxbox.y)) return true; 00677 if (CS::IsNaN (maxbox.z)) return true; 00678 return false; 00679 } 00680 00690 csVector3 GetCorner (int corner) const; 00691 00697 inline void GetEdgeInfo (int edge, int& v1, int& v2, int& fleft, int& fright) const 00698 { 00699 v1 = edges[edge].v1; 00700 v2 = edges[edge].v2; 00701 fleft = edges[edge].fl; 00702 fright = edges[edge].fr; 00703 } 00704 00709 inline const uint8* GetFaceEdges (int face) const 00710 { 00711 return faces[face]; 00712 } 00713 00717 inline csVector3 GetCenter () const { return (minbox+maxbox)/2; } 00718 00723 void SetCenter (const csVector3& c); 00724 00728 void SetSize (const csVector3& s); 00729 00733 inline csVector3 GetSize () const { return (maxbox-minbox); } 00734 00739 csBox2 GetSide (int side) const; 00740 00746 void GetAxisPlane (int side, int& axis, float& where) const; 00747 00754 int GetVisibleSides (const csVector3& pos, int* visible_sides) const; 00755 00760 static inline int OtherSide (int side) 00761 { 00762 return side ^ 1; 00763 } 00764 00770 inline csSegment3 GetEdge (int edge) const 00771 { 00772 return csSegment3 (GetCorner (edges[edge].v1), GetCorner (edges[edge].v2)); 00773 } 00774 00780 inline void GetEdge (int edge, csSegment3& e) const 00781 { 00782 e.SetStart (GetCorner (edges[edge].v1)); 00783 e.SetEnd (GetCorner (edges[edge].v2)); 00784 } 00785 00787 inline bool In (float x, float y, float z) const 00788 { 00789 if (x < minbox.x || x > maxbox.x) return false; 00790 if (y < minbox.y || y > maxbox.y) return false; 00791 if (z < minbox.z || z > maxbox.z) return false; 00792 return true; 00793 } 00794 00796 inline bool In (const csVector3& v) const 00797 { 00798 return In (v.x, v.y, v.z); 00799 } 00800 00802 inline bool Overlap (const csBox3& box) const 00803 { 00804 if (maxbox.x < box.minbox.x || minbox.x > box.maxbox.x) return false; 00805 if (maxbox.y < box.minbox.y || minbox.y > box.maxbox.y) return false; 00806 if (maxbox.z < box.minbox.z || minbox.z > box.maxbox.z) return false; 00807 return true; 00808 } 00809 00811 inline bool Contains (const csBox3& box) const 00812 { 00813 return (box.minbox.x >= minbox.x && box.maxbox.x <= maxbox.x) && 00814 (box.minbox.y >= minbox.y && box.maxbox.y <= maxbox.y) && 00815 (box.minbox.z >= minbox.z && box.maxbox.z <= maxbox.z); 00816 } 00817 00819 inline bool Empty () const 00820 { 00821 if (minbox.x > maxbox.x) return true; 00822 if (minbox.y > maxbox.y) return true; 00823 if (minbox.z > maxbox.z) return true; 00824 return false; 00825 } 00826 00828 inline void StartBoundingBox () 00829 { 00830 minbox.x = CS_BOUNDINGBOX_MAXVALUE; 00831 minbox.y = CS_BOUNDINGBOX_MAXVALUE; 00832 minbox.z = CS_BOUNDINGBOX_MAXVALUE; 00833 maxbox.x = -CS_BOUNDINGBOX_MAXVALUE; 00834 maxbox.y = -CS_BOUNDINGBOX_MAXVALUE; 00835 maxbox.z = -CS_BOUNDINGBOX_MAXVALUE; 00836 } 00837 00839 inline void StartBoundingBox (const csVector3& v) 00840 { 00841 minbox = v; maxbox = v; 00842 } 00843 00845 inline void AddBoundingVertex (float x, float y, float z) 00846 { 00847 if (x < minbox.x) minbox.x = x; if (x > maxbox.x) maxbox.x = x; 00848 if (y < minbox.y) minbox.y = y; if (y > maxbox.y) maxbox.y = y; 00849 if (z < minbox.z) minbox.z = z; if (z > maxbox.z) maxbox.z = z; 00850 } 00851 00853 inline void AddBoundingVertex (const csVector3& v) 00854 { 00855 AddBoundingVertex (v.x, v.y, v.z); 00856 } 00857 00863 inline void AddBoundingVertexSmart (float x, float y, float z) 00864 { 00865 if (x < minbox.x) minbox.x = x; else if (x > maxbox.x) maxbox.x = x; 00866 if (y < minbox.y) minbox.y = y; else if (y > maxbox.y) maxbox.y = y; 00867 if (z < minbox.z) minbox.z = z; else if (z > maxbox.z) maxbox.z = z; 00868 } 00869 00875 inline void AddBoundingVertexSmart (const csVector3& v) 00876 { 00877 AddBoundingVertexSmart (v.x, v.y, v.z); 00878 } 00879 00884 inline bool AddBoundingVertexTest (float x, float y, float z) 00885 { 00886 bool rc = false; 00887 if (x < minbox.x) { minbox.x = x; rc = true; } 00888 if (x > maxbox.x) { maxbox.x = x; rc = true; } 00889 if (y < minbox.y) { minbox.y = y; rc = true; } 00890 if (y > maxbox.y) { maxbox.y = y; rc = true; } 00891 if (z < minbox.z) { minbox.z = z; rc = true; } 00892 if (z > maxbox.z) { maxbox.z = z; rc = true; } 00893 return rc; 00894 } 00895 00900 inline bool AddBoundingVertexTest (const csVector3& v) 00901 { 00902 return AddBoundingVertexTest (v.x, v.y, v.z); 00903 } 00904 00911 inline bool AddBoundingVertexSmartTest (float x, float y, float z) 00912 { 00913 bool rc = false; 00914 if (x < minbox.x) { minbox.x = x; rc = true; } 00915 else if (x > maxbox.x) { maxbox.x = x; rc = true; } 00916 if (y < minbox.y) { minbox.y = y; rc = true; } 00917 else if (y > maxbox.y) { maxbox.y = y; rc = true; } 00918 if (z < minbox.z) { minbox.z = z; rc = true; } 00919 else if (z > maxbox.z) { maxbox.z = z; rc = true; } 00920 return rc; 00921 } 00922 00929 inline bool AddBoundingVertexSmartTest (const csVector3& v) 00930 { 00931 return AddBoundingVertexSmartTest (v.x, v.y, v.z); 00932 } 00933 00937 inline void AddBoundingBox (const csBox3& box) 00938 { 00939 minbox.x = csMin(minbox.x, box.minbox.x); 00940 minbox.y = csMin(minbox.y, box.minbox.y); 00941 minbox.z = csMin(minbox.z, box.minbox.z); 00942 00943 maxbox.x = csMax(maxbox.x, box.maxbox.x); 00944 maxbox.y = csMax(maxbox.y, box.maxbox.y); 00945 maxbox.z = csMax(maxbox.z, box.maxbox.z); 00946 } 00947 00949 csBox3 () : 00950 minbox ( CS_BOUNDINGBOX_MAXVALUE, 00951 CS_BOUNDINGBOX_MAXVALUE, 00952 CS_BOUNDINGBOX_MAXVALUE), 00953 maxbox (-CS_BOUNDINGBOX_MAXVALUE, 00954 -CS_BOUNDINGBOX_MAXVALUE, 00955 -CS_BOUNDINGBOX_MAXVALUE) {} 00956 00958 csBox3 (const csVector3& v) : minbox (v), maxbox (v) 00959 { } 00960 00962 csBox3 (const csVector3& v1, const csVector3& v2) : 00963 minbox (v1), maxbox (v2) 00964 { if (Empty ()) StartBoundingBox (); } 00965 00967 csBox3 (float x1, float y1, float z1, float x2, float y2, float z2) : 00968 minbox (x1, y1, z1), maxbox (x2, y2, z2) 00969 { if (Empty ()) StartBoundingBox (); } 00970 00972 inline void Set (const csVector3& bmin, const csVector3& bmax) 00973 { 00974 minbox = bmin; 00975 maxbox = bmax; 00976 } 00977 00979 inline void Set (float x1, float y1, float z1, float x2, float y2, float z2) 00980 { 00981 if (x1>x2 || y1>y2 || z1>z2) StartBoundingBox(); 00982 else 00983 { 00984 minbox.x = x1; minbox.y = y1; minbox.z = z1; 00985 maxbox.x = x2; maxbox.y = y2; maxbox.z = z2; 00986 } 00987 } 00988 00990 inline void SetMin (size_t idx, float val) 00991 { 00992 minbox[idx] = val; 00993 } 00994 00996 inline void SetMax (size_t idx, float val) 00997 { 00998 maxbox[idx] = val; 00999 } 01000 01002 inline float GetMin (size_t idx) 01003 { 01004 return minbox[idx]; 01005 } 01006 01008 inline float GetMax (size_t idx) 01009 { 01010 return maxbox[idx]; 01011 } 01012 01017 csString Description() const; 01018 01022 inline void Split (int axis, float where, csBox3& bl, csBox3& br) const 01023 { 01024 switch (axis) 01025 { 01026 case CS_AXIS_X: 01027 bl.Set (minbox.x, minbox.y, minbox.z, 01028 where, maxbox.y, maxbox.z); 01029 br.Set (where, minbox.y, minbox.z, 01030 maxbox.x, maxbox.y, maxbox.z); 01031 break; 01032 case CS_AXIS_Y: 01033 bl.Set (minbox.x, minbox.y, minbox.z, 01034 maxbox.x, where, maxbox.z); 01035 br.Set (minbox.x, where, minbox.z, 01036 maxbox.x, maxbox.y, maxbox.z); 01037 break; 01038 case CS_AXIS_Z: 01039 bl.Set (minbox.x, minbox.y, minbox.z, 01040 maxbox.x, maxbox.y, where); 01041 br.Set (minbox.x, minbox.y, where, 01042 maxbox.x, maxbox.y, maxbox.z); 01043 break; 01044 } 01045 } 01046 01053 inline int TestSplit (int axis, float where) const 01054 { 01055 if (maxbox[axis] < where) return -1; 01056 if (minbox[axis] > where) return 1; 01057 return 0; 01058 } 01059 01063 bool AdjacentX (const csBox3& other, float epsilon = SMALL_EPSILON) const; 01064 01068 bool AdjacentY (const csBox3& other, float epsilon = SMALL_EPSILON) const; 01069 01073 bool AdjacentZ (const csBox3& other, float epsilon = SMALL_EPSILON) const; 01074 01082 int Adjacent (const csBox3& other, float epsilon = SMALL_EPSILON) const; 01083 01090 int CalculatePointSegment (const csVector3& pos) const; 01091 01100 void GetConvexOutline (const csVector3& pos, 01101 csVector3* array, int& num_array, bool bVisible=false) const; 01102 01106 bool Between (const csBox3& box1, const csBox3& box2) const; 01107 01112 void ManhattanDistance (const csBox3& other, csVector3& dist) const; 01113 01118 float SquaredOriginDist () const; 01119 01125 float SquaredOriginMaxDist () const; 01126 01131 float SquaredPosDist (const csVector3& pos) const; 01132 01138 float SquaredPosMaxDist (const csVector3& pos) const; 01139 01151 bool ProjectBox (const csTransform& trans, float fov, float sx, float sy, 01152 csBox2& sbox, float& min_z, float& max_z) const; 01153 01165 bool ProjectBox (const csTransform& trans, const CS::Math::Matrix4& proj, 01166 csBox2& sbox, float& min_z, float& max_z, int screenWidth, 01167 int screenHeight) const; 01168 01178 bool ProjectOutline (const csTransform& trans, float fov, float sx, float sy, 01179 csPoly2D& poly, float& min_z, float& max_z) const; 01180 01188 bool ProjectOutline (const csVector3& origin, 01189 int axis, float where, csArray<csVector2>& poly) const; 01190 01196 bool ProjectOutline (const csVector3& origin, 01197 int axis, float where, csPoly2D& poly) const; 01198 01211 bool ProjectBoxAndOutline (const csTransform& trans, float fov, 01212 float sx, float sy, csBox2& sbox, csPoly2D& poly, 01213 float& min_z, float& max_z) const; 01214 01216 csBox3& operator+= (const csBox3& box); 01218 csBox3& operator+= (const csVector3& point); 01220 csBox3& operator*= (const csBox3& box); 01222 bool TestIntersect (const csBox3& box) const; 01223 01225 friend CS_CRYSTALSPACE_EXPORT csBox3 operator+ (const csBox3& box1, 01226 const csBox3& box2); 01228 friend CS_CRYSTALSPACE_EXPORT csBox3 operator+ (const csBox3& box, 01229 const csVector3& point); 01231 friend CS_CRYSTALSPACE_EXPORT csBox3 operator* (const csBox3& box1, 01232 const csBox3& box2); 01233 01235 friend CS_CRYSTALSPACE_EXPORT bool operator== (const csBox3& box1, 01236 const csBox3& box2); 01238 friend CS_CRYSTALSPACE_EXPORT bool operator!= (const csBox3& box1, 01239 const csBox3& box2); 01241 friend CS_CRYSTALSPACE_EXPORT bool operator< (const csBox3& box1, 01242 const csBox3& box2); 01244 friend CS_CRYSTALSPACE_EXPORT bool operator> (const csBox3& box1, 01245 const csBox3& box2); 01247 friend CS_CRYSTALSPACE_EXPORT bool operator< (const csVector3& point, 01248 const csBox3& box); 01249 }; 01250 01253 #endif // __CS_BOX_H__
Generated for Crystal Space 2.0 by doxygen 1.6.1