boxrobj.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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 : WW3D *
  23. * *
  24. * $Archive:: /Commando/Code/ww3d2/boxrobj.h $*
  25. * *
  26. * Author:: Greg Hjelstrom *
  27. * *
  28. * $Modtime:: 10/11/01 2:24p $*
  29. * *
  30. * $Revision:: 6 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef BOXROBJ_H
  39. #define BOXROBJ_H
  40. #include "always.h"
  41. #include "rendobj.h"
  42. #include "w3d_file.h"
  43. #include "shader.h"
  44. #include "proto.h"
  45. #include "obbox.h"
  46. class VertexMaterialClass;
  47. /**
  48. ** BoxRenderObjClass: base class for AABox and OBBox collision boxes
  49. **
  50. ** NOTE: these render objects were designed from the start to be used for
  51. ** collision boxes. They are designed to normally never render unless you
  52. ** set the display mask and then, all boxes of that type will render.
  53. ** The display mask is 'AND'ed with the collision bits in the base render
  54. ** object class to determine if the box should be rendered. WW3D provides
  55. ** an interface for setting this mask in your app.
  56. **
  57. ** NOTE2: AABoxRenderObjClass is an axis-aligned box which will be positioned
  58. ** at a world-space offset (its local center) from the origin of the transform.
  59. ** This is done because AABoxes are used for rotationally invariant collision
  60. ** detection so we don't want the boxes to move around as the object rotates.
  61. ** For this reason, any AABoxes you use in a hierarchical model should be attached
  62. ** to the root and be constructed symmetrically...
  63. **
  64. ** NOTE3: OBBoxRenderObjClass is an oriented box which is aligned with its transform
  65. ** but can have a center point that is offest from the transform's origin.
  66. **
  67. */
  68. class BoxRenderObjClass : public RenderObjClass
  69. {
  70. public:
  71. BoxRenderObjClass(void);
  72. BoxRenderObjClass(const W3dBoxStruct & def);
  73. BoxRenderObjClass(const BoxRenderObjClass & src);
  74. BoxRenderObjClass & operator = (const BoxRenderObjClass &);
  75. virtual int Get_Num_Polys(void) const;
  76. virtual const char * Get_Name(void) const;
  77. virtual void Set_Name(const char * name);
  78. void Set_Color(const Vector3 & color);
  79. void Set_Opacity(float opacity) { Opacity = opacity; }
  80. static void Init(void);
  81. static void Shutdown(void);
  82. static void Set_Box_Display_Mask(int mask);
  83. static int Get_Box_Display_Mask(void);
  84. void Set_Local_Center_Extent(const Vector3 & center,const Vector3 & extent);
  85. void Set_Local_Min_Max(const Vector3 & min,const Vector3 & max);
  86. const Vector3 & Get_Local_Center(void) { return ObjSpaceCenter; }
  87. const Vector3 & Get_Local_Extent(void) { return ObjSpaceExtent; }
  88. protected:
  89. virtual void update_cached_box(void) = 0;
  90. void render_box(RenderInfoClass & rinfo,const Vector3 & center,const Vector3 & extent);
  91. void vis_render_box(SpecialRenderInfoClass & rinfo,const Vector3 & center,const Vector3 & extent);
  92. char Name[2*W3D_NAME_LEN];
  93. Vector3 Color;
  94. Vector3 ObjSpaceCenter;
  95. Vector3 ObjSpaceExtent;
  96. float Opacity;
  97. static bool IsInitted;
  98. static int DisplayMask;
  99. };
  100. inline void BoxRenderObjClass::Set_Local_Center_Extent(const Vector3 & center,const Vector3 & extent)
  101. {
  102. ObjSpaceCenter = center;
  103. ObjSpaceExtent = extent;
  104. update_cached_box();
  105. }
  106. inline void BoxRenderObjClass::Set_Local_Min_Max(const Vector3 & min,const Vector3 & max)
  107. {
  108. ObjSpaceCenter = (max + min) / 2.0f;
  109. ObjSpaceExtent = (max - min) / 2.0f;
  110. update_cached_box();
  111. }
  112. /*
  113. ** AABoxRenderObjClass -- RenderObject for axis-aligned collision boxes.
  114. */
  115. class AABoxRenderObjClass : public BoxRenderObjClass
  116. {
  117. public:
  118. AABoxRenderObjClass(void);
  119. AABoxRenderObjClass(const W3dBoxStruct & def);
  120. AABoxRenderObjClass(const AABoxRenderObjClass & src);
  121. AABoxRenderObjClass(const AABoxClass & box);
  122. AABoxRenderObjClass & operator = (const AABoxRenderObjClass &);
  123. /////////////////////////////////////////////////////////////////////////////
  124. // Render Object Interface
  125. /////////////////////////////////////////////////////////////////////////////
  126. virtual RenderObjClass * Clone(void) const;
  127. virtual int Class_ID(void) const;
  128. virtual void Render(RenderInfoClass & rinfo);
  129. virtual void Special_Render(SpecialRenderInfoClass & rinfo);
  130. virtual void Set_Transform(const Matrix3D &m);
  131. virtual void Set_Position(const Vector3 &v);
  132. virtual bool Cast_Ray(RayCollisionTestClass & raytest);
  133. virtual bool Cast_AABox(AABoxCollisionTestClass & boxtest);
  134. virtual bool Cast_OBBox(OBBoxCollisionTestClass & boxtest);
  135. virtual bool Intersect_AABox(AABoxIntersectionTestClass & boxtest);
  136. virtual bool Intersect_OBBox(OBBoxIntersectionTestClass & boxtest);
  137. virtual void Get_Obj_Space_Bounding_Sphere(SphereClass & sphere) const;
  138. virtual void Get_Obj_Space_Bounding_Box(AABoxClass & box) const;
  139. /////////////////////////////////////////////////////////////////////////////
  140. // AABoxRenderObjClass Interface
  141. /////////////////////////////////////////////////////////////////////////////
  142. const AABoxClass & Get_Box(void);
  143. protected:
  144. virtual void update_cached_box(void);
  145. AABoxClass CachedBox;
  146. };
  147. inline const AABoxClass & AABoxRenderObjClass::Get_Box(void)
  148. {
  149. Validate_Transform();
  150. update_cached_box();
  151. return CachedBox;
  152. }
  153. /*
  154. ** OBBoxRenderObjClass - render object for oriented collision boxes
  155. */
  156. class OBBoxRenderObjClass : public BoxRenderObjClass
  157. {
  158. public:
  159. OBBoxRenderObjClass(void);
  160. OBBoxRenderObjClass(const W3dBoxStruct & def);
  161. OBBoxRenderObjClass(const OBBoxRenderObjClass & src);
  162. OBBoxRenderObjClass(const OBBoxClass & box);
  163. OBBoxRenderObjClass & operator = (const OBBoxRenderObjClass &);
  164. /////////////////////////////////////////////////////////////////////////////
  165. // Render Object Interface
  166. /////////////////////////////////////////////////////////////////////////////
  167. virtual RenderObjClass * Clone(void) const;
  168. virtual int Class_ID(void) const;
  169. virtual void Render(RenderInfoClass & rinfo);
  170. virtual void Special_Render(SpecialRenderInfoClass & rinfo);
  171. virtual void Set_Transform(const Matrix3D &m);
  172. virtual void Set_Position(const Vector3 &v);
  173. virtual bool Cast_Ray(RayCollisionTestClass & raytest);
  174. virtual bool Cast_AABox(AABoxCollisionTestClass & boxtest);
  175. virtual bool Cast_OBBox(OBBoxCollisionTestClass & boxtest);
  176. virtual bool Intersect_AABox(AABoxIntersectionTestClass & boxtest);
  177. virtual bool Intersect_OBBox(OBBoxIntersectionTestClass & boxtest);
  178. virtual void Get_Obj_Space_Bounding_Sphere(SphereClass & sphere) const;
  179. virtual void Get_Obj_Space_Bounding_Box(AABoxClass & box) const;
  180. /////////////////////////////////////////////////////////////////////////////
  181. // OBBoxRenderObjClass Interface
  182. /////////////////////////////////////////////////////////////////////////////
  183. OBBoxClass & Get_Box(void);
  184. protected:
  185. virtual void update_cached_box(void);
  186. OBBoxClass CachedBox;
  187. };
  188. /*
  189. ** Loader for boxes
  190. */
  191. class BoxLoaderClass : public PrototypeLoaderClass
  192. {
  193. public:
  194. virtual int Chunk_Type (void) { return W3D_CHUNK_BOX; }
  195. virtual PrototypeClass * Load_W3D(ChunkLoadClass & cload);
  196. };
  197. /*
  198. ** Prototype for Box objects
  199. */
  200. class BoxPrototypeClass : public PrototypeClass
  201. {
  202. public:
  203. BoxPrototypeClass(W3dBoxStruct box);
  204. virtual const char * Get_Name(void) const;
  205. virtual int Get_Class_ID(void) const;
  206. virtual RenderObjClass * Create(void);
  207. private:
  208. W3dBoxStruct Definition;
  209. };
  210. /*
  211. ** Instance of the loader which the asset manager installs
  212. */
  213. extern BoxLoaderClass _BoxLoader;
  214. #endif