AABox.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System.Runtime.InteropServices;
  2. namespace BansheeEngine
  3. {
  4. /// <summary>
  5. /// Axis aligned box represented by minimum and maximum point.
  6. /// </summary>
  7. [StructLayout(LayoutKind.Sequential), SerializeObject]
  8. public struct AABox // Note: Must match C++ class AABox
  9. {
  10. private Vector3 _minimum;
  11. private Vector3 _maximum;
  12. /// <summary>
  13. /// Corner of the box with minimum values (opposite to maximum corner).
  14. /// </summary>
  15. public Vector3 Minimum
  16. {
  17. get { return _minimum; }
  18. set { _minimum = value; }
  19. }
  20. /// <summary>
  21. /// Corner of the box with maximum values (opposite to minimum corner).
  22. /// </summary>
  23. public Vector3 Maximum
  24. {
  25. get { return _maximum; }
  26. set { _maximum = value; }
  27. }
  28. /// <summary>
  29. /// Returns the center of the box.
  30. /// </summary>
  31. public Vector3 Center
  32. {
  33. get
  34. {
  35. return new Vector3((_maximum.x + _minimum.x) * 0.5f,
  36. (_maximum.y + _minimum.y) * 0.5f,
  37. (_maximum.z + _minimum.z) * 0.5f);
  38. }
  39. }
  40. /// <summary>
  41. /// Returns the width, height and depth of the box.
  42. /// </summary>
  43. public Vector3 Size
  44. {
  45. get
  46. {
  47. return _maximum - _minimum;
  48. }
  49. }
  50. /// <summary>
  51. /// Creates a new axis aligned box.
  52. /// </summary>
  53. /// <param name="min">Corner of the box with minimum values.</param>
  54. /// <param name="max">Corner of the box with maximum values.</param>
  55. public AABox(Vector3 min, Vector3 max)
  56. {
  57. _minimum = min;
  58. _maximum = max;
  59. }
  60. };
  61. }