CmBox.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #pragma once
  2. #include "CmPrerequisitesUtil.h"
  3. namespace CamelotFramework
  4. {
  5. /** Structure used to define a box in a 3-D integer space.
  6. Note that the left, top, and front edges are included but the right,
  7. bottom and back ones are not.
  8. */
  9. struct CM_UTILITY_EXPORT Box
  10. {
  11. UINT32 left, top, right, bottom, front, back;
  12. /// Parameterless constructor for setting the members manually
  13. Box()
  14. : left(0), top(0), right(1), bottom(1), front(0), back(1)
  15. {
  16. }
  17. /** Define a box from left, top, right and bottom coordinates
  18. This box will have depth one (front=0 and back=1).
  19. @param l x value of left edge
  20. @param t y value of top edge
  21. @param r x value of right edge
  22. @param b y value of bottom edge
  23. @note Note that the left, top, and front edges are included
  24. but the right, bottom and back ones are not.
  25. */
  26. Box( UINT32 l, UINT32 t, UINT32 r, UINT32 b ):
  27. left(l),
  28. top(t),
  29. right(r),
  30. bottom(b),
  31. front(0),
  32. back(1)
  33. {
  34. assert(right >= left && bottom >= top && back >= front);
  35. }
  36. /** Define a box from left, top, front, right, bottom and back
  37. coordinates.
  38. @param l x value of left edge
  39. @param t y value of top edge
  40. @param ff z value of front edge
  41. @param r x value of right edge
  42. @param b y value of bottom edge
  43. @param bb z value of back edge
  44. @note Note that the left, top, and front edges are included
  45. but the right, bottom and back ones are not.
  46. */
  47. Box( UINT32 l, UINT32 t, UINT32 ff, UINT32 r, UINT32 b, UINT32 bb ):
  48. left(l),
  49. top(t),
  50. right(r),
  51. bottom(b),
  52. front(ff),
  53. back(bb)
  54. {
  55. assert(right >= left && bottom >= top && back >= front);
  56. }
  57. /// Return true if the other box is a part of this one
  58. bool contains(const Box &def) const
  59. {
  60. return (def.left >= left && def.top >= top && def.front >= front &&
  61. def.right <= right && def.bottom <= bottom && def.back <= back);
  62. }
  63. /// Get the width of this box
  64. UINT32 getWidth() const { return right-left; }
  65. /// Get the height of this box
  66. UINT32 getHeight() const { return bottom-top; }
  67. /// Get the depth of this box
  68. UINT32 getDepth() const { return back-front; }
  69. };
  70. }