box3.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**********************************************************************
  2. *<
  3. FILE: box3.h
  4. DESCRIPTION: 3D Box class
  5. CREATED BY: Dan Silva
  6. HISTORY:
  7. *> Copyright (c) 1994, All Rights Reserved.
  8. **********************************************************************/
  9. #ifndef _BOX3_H
  10. #define _BOX3_H
  11. #include "point3.h"
  12. #include "matrix3.h"
  13. class Box3 {
  14. public:
  15. Point3 pmin,pmax;
  16. DllExport Box3();
  17. Box3(const Point3& p, const Point3& q) { pmin = p; pmax = q;}
  18. DllExport void Init();
  19. DllExport void MakeCube(const Point3& p, float side);
  20. // Access
  21. Point3 Min() const { return pmin; }
  22. Point3 Max() const { return pmax; }
  23. Point3 Center() const { return(pmin+pmax)/(float)2.0; }
  24. Point3 Width() const { return(pmax-pmin); }
  25. /* operator[] returns ith corner point: (i == (0..7) )
  26. Mapping:
  27. X Y Z
  28. [0] : (min,min,min)
  29. [1] : (max,min,min)
  30. [2] : (min,max,min)
  31. [3] : (max,max,min)
  32. [4] : (min,min,max)
  33. [5] : (max,min,max)
  34. [6] : (min,max,max)
  35. [7] : (max,max,max)
  36. */
  37. DllExport Point3 operator[](int i) const;
  38. // Modifiers
  39. DllExport Box3& operator+=(const Point3& p); // expand this box to include Point3
  40. DllExport Box3& operator+=(const Box3& b); // expand this box to include Box3
  41. DllExport void Scale(float s); // scale box about center
  42. DllExport void Translate(const Point3 &p); // translate box
  43. DllExport void EnlargeBy(float s); // enlarge by this amount on all sides
  44. // Returns a box that bounds the 8 transformed corners of the input box.
  45. DllExport Box3 operator*(const Matrix3& tm) const;
  46. // Tests
  47. DllExport int IsEmpty() const; // is this box empty?
  48. DllExport int Contains(const Point3& p) const; // is point in this box?
  49. DllExport int Contains(const Box3& b) const; // is box b totally in this box?
  50. };
  51. #endif