physinttest.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. ** Command & Conquer Renegade(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 : WWPhys *
  23. * *
  24. * $Archive:: /Commando/Code/wwphys/physinttest.h $*
  25. * *
  26. * Original Author:: Greg Hjelstrom *
  27. * *
  28. * $Author:: Greg_h $*
  29. * *
  30. * $Modtime:: 11/14/01 1:40p $*
  31. * *
  32. * $Revision:: 5 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #if defined(_MSC_VER)
  38. #pragma once
  39. #endif
  40. #ifndef PHYSINTTEST_H
  41. #define PHYSINTTEST_H
  42. #include "inttest.h"
  43. #include "mesh.h"
  44. #include "physlist.h"
  45. //
  46. // Derived versions of the Intersection Test Classes which contain
  47. // a list of intersected PhysObj's and the collision group.
  48. //
  49. ///////////////////////////////////////////////////////////////////////////
  50. //
  51. // PhysAABoxIntersectionTestClass
  52. // Axis-Aligned box intersections. Derived from the W3D class for the
  53. // same thing. Adds the collision group and intersected objects list.
  54. //
  55. ///////////////////////////////////////////////////////////////////////////
  56. class PhysAABoxIntersectionTestClass : public AABoxIntersectionTestClass
  57. {
  58. public:
  59. PhysAABoxIntersectionTestClass(const AABoxClass & box,int col_group,int col_type,NonRefPhysListClass * result_list = NULL) :
  60. AABoxIntersectionTestClass(box,col_type),
  61. CollisionGroup(col_group),
  62. IntersectedObjects(result_list),
  63. CheckStaticObjs(true),
  64. CheckDynamicObjs(true)
  65. {
  66. }
  67. void Add_Intersected_Object(PhysClass * obj) { if (IntersectedObjects) IntersectedObjects->Add(obj); }
  68. public:
  69. int CollisionGroup;
  70. bool CheckStaticObjs;
  71. bool CheckDynamicObjs;
  72. private:
  73. NonRefPhysListClass * IntersectedObjects;
  74. // not implemented:
  75. PhysAABoxIntersectionTestClass(const PhysAABoxIntersectionTestClass & );
  76. PhysAABoxIntersectionTestClass & operator = (const PhysAABoxIntersectionTestClass & );
  77. };
  78. ///////////////////////////////////////////////////////////////////////////
  79. //
  80. // PhysOBBoxIntersectionTestClass
  81. // Oriented box intersections. Derived from the W3D class for the
  82. // same thing. Adds the collision group and intersected objects list.
  83. //
  84. ///////////////////////////////////////////////////////////////////////////
  85. class PhysOBBoxIntersectionTestClass : public OBBoxIntersectionTestClass
  86. {
  87. public:
  88. PhysOBBoxIntersectionTestClass(const OBBoxClass & box,int col_group,int col_type,NonRefPhysListClass * result_list = NULL) :
  89. OBBoxIntersectionTestClass(box,col_type),
  90. CollisionGroup(col_group),
  91. IntersectedObjects(result_list),
  92. CheckStaticObjs(true),
  93. CheckDynamicObjs(true)
  94. {
  95. }
  96. void Add_Intersected_Object(PhysClass * obj) { if (IntersectedObjects) IntersectedObjects->Add(obj); }
  97. public:
  98. int CollisionGroup;
  99. bool CheckStaticObjs;
  100. bool CheckDynamicObjs;
  101. private:
  102. NonRefPhysListClass * IntersectedObjects;
  103. // not implemented:
  104. PhysOBBoxIntersectionTestClass(const PhysOBBoxIntersectionTestClass & );
  105. PhysOBBoxIntersectionTestClass & operator = (const PhysOBBoxIntersectionTestClass & );
  106. };
  107. ///////////////////////////////////////////////////////////////////////////
  108. //
  109. // PhysMeshIntersectionTestClass
  110. // Mesh intersections. Currently there is no W3D equivalent.
  111. //
  112. ///////////////////////////////////////////////////////////////////////////
  113. class PhysMeshIntersectionTestClass : public IntersectionTestClass
  114. {
  115. public:
  116. PhysMeshIntersectionTestClass::PhysMeshIntersectionTestClass(MeshClass * mesh,int col_group,int col_type,NonRefPhysListClass * result_list) :
  117. IntersectionTestClass(col_type),
  118. Mesh(NULL),
  119. CollisionGroup(col_group),
  120. IntersectedObjects(result_list),
  121. CheckStaticObjs(true),
  122. CheckDynamicObjs(true)
  123. {
  124. WWASSERT(mesh != NULL);
  125. REF_PTR_SET(Mesh,mesh);
  126. BoundingBox = Mesh->Get_Bounding_Box();
  127. }
  128. ~PhysMeshIntersectionTestClass(void)
  129. {
  130. REF_PTR_RELEASE(Mesh);
  131. }
  132. bool Cull(const Vector3 & min,const Vector3 & max);
  133. bool Cull(const AABoxClass & box);
  134. void Add_Intersected_Object(PhysClass * obj) { if (IntersectedObjects) IntersectedObjects->Add(obj); }
  135. public:
  136. MeshClass * Mesh;
  137. AABoxClass BoundingBox;
  138. int CollisionGroup;
  139. bool CheckStaticObjs;
  140. bool CheckDynamicObjs;
  141. private:
  142. NonRefPhysListClass * IntersectedObjects;
  143. private:
  144. // not implemented:
  145. PhysMeshIntersectionTestClass(const PhysMeshIntersectionTestClass & );
  146. PhysMeshIntersectionTestClass & operator = (const PhysMeshIntersectionTestClass & );
  147. };
  148. inline bool PhysMeshIntersectionTestClass::Cull(const Vector3 & cull_min,const Vector3 & cull_max)
  149. {
  150. Vector3 box_min;
  151. Vector3::Subtract(BoundingBox.Center,BoundingBox.Extent,&box_min);
  152. Vector3 box_max;
  153. Vector3::Add(BoundingBox.Center,BoundingBox.Extent,&box_max);
  154. if ((box_min.X > cull_max.X) || (box_max.X < cull_min.X)) return true;
  155. if ((box_min.Y > cull_max.Y) || (box_max.Y < cull_min.Y)) return true;
  156. if ((box_min.Z > cull_max.Z) || (box_max.Z < cull_min.Z)) return true;
  157. return false;
  158. }
  159. inline bool PhysMeshIntersectionTestClass::Cull(const AABoxClass & cull_box)
  160. {
  161. Vector3 dc;
  162. Vector3 r;
  163. Vector3::Subtract(cull_box.Center,BoundingBox.Center,&dc);
  164. Vector3::Add(cull_box.Extent,BoundingBox.Extent,&r);
  165. if (WWMath::Fabs(dc.X) > r.X) return true;
  166. if (WWMath::Fabs(dc.Y) > r.Y) return true;
  167. if (WWMath::Fabs(dc.Z) > r.Z) return true;
  168. return false;
  169. }
  170. #endif