colmathaabox.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WWMath *
  23. * *
  24. * $Archive:: /Commando/Code/wwmath/colmathaabox.h $*
  25. * *
  26. * Original Author:: Greg Hjelstrom *
  27. * *
  28. * $Author:: Jani_p $*
  29. * *
  30. * $Modtime:: 5/08/01 5:01p $*
  31. * *
  32. * $Revision:: 8 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * CollisionMath::Overlap_Test -- test overlap between an AABox and a point *
  37. * CollisionMath::Overlap_Test -- Tests overlap between two AABoxes *
  38. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  39. #if defined(_MSC_VER)
  40. #pragma once
  41. #endif
  42. #ifndef COLMATHAABOX_H
  43. #define COLMATHAABOX_H
  44. #include "always.h"
  45. #include "aabox.h"
  46. #include "vector3.h"
  47. #include "lineseg.h"
  48. /***********************************************************************************************
  49. * CollisionMath::Overlap_Test -- test overlap between an AABox and a point *
  50. * *
  51. * INPUT: *
  52. * *
  53. * OUTPUT: *
  54. * *
  55. * WARNINGS: *
  56. * *
  57. * HISTORY: *
  58. * 3/14/2000 gth : Created. *
  59. *=============================================================================================*/
  60. WWINLINE CollisionMath::OverlapType CollisionMath::Overlap_Test(const AABoxClass & box,const Vector3 & point)
  61. {
  62. if (WWMath::Fabs(point.X - box.Center.X) > box.Extent.X) return POS;
  63. if (WWMath::Fabs(point.Y - box.Center.Y) > box.Extent.Y) return POS;
  64. if (WWMath::Fabs(point.Z - box.Center.Z) > box.Extent.Z) return POS;
  65. return NEG;
  66. }
  67. /***********************************************************************************************
  68. * CollisionMath::Overlap_Test -- Tests overlap between two AABoxes *
  69. * *
  70. * INPUT: *
  71. * *
  72. * OUTPUT: *
  73. * *
  74. * WARNINGS: *
  75. * *
  76. * HISTORY: *
  77. * 11/19/99 gth : Created. *
  78. *=============================================================================================*/
  79. WWINLINE CollisionMath::OverlapType CollisionMath::Overlap_Test(const AABoxClass & box,const AABoxClass & box2)
  80. {
  81. Vector3 dc;
  82. Vector3::Subtract(box2.Center,box.Center,&dc);
  83. if (box.Extent.X + box2.Extent.X < WWMath::Fabs(dc.X)) return POS;
  84. if (box.Extent.Y + box2.Extent.Y < WWMath::Fabs(dc.Y)) return POS;
  85. if (box.Extent.Z + box2.Extent.Z < WWMath::Fabs(dc.Z)) return POS;
  86. if ( (dc.X + box2.Extent.X <= box.Extent.X) &&
  87. (dc.Y + box2.Extent.Y <= box.Extent.Y) &&
  88. (dc.Z + box2.Extent.Z <= box.Extent.Z) &&
  89. (dc.X - box2.Extent.X >= -box.Extent.X) &&
  90. (dc.Y - box2.Extent.Y >= -box.Extent.Y) &&
  91. (dc.Z - box2.Extent.Z >= -box.Extent.Z))
  92. {
  93. return NEG; // inside;
  94. }
  95. return BOTH;
  96. }
  97. #endif