ringobj.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. /*
  2. ** Command & Conquer Generals(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/ringobj.h $*
  25. * *
  26. * Author:: Jason Andersen *
  27. * *
  28. * $Modtime:: 3/23/01 7:02p $*
  29. * *
  30. * $Revision:: 5 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef RINGOBJ_H
  39. #define RINGOBJ_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. #include "quat.h"
  47. #include "vector3.h"
  48. #include "vector2.h"
  49. #include "prim_anim.h"
  50. class VertexMaterialClass;
  51. typedef LERPAnimationChannelClass<Vector3> RingColorChannelClass;
  52. typedef LERPAnimationChannelClass<float> RingAlphaChannelClass;
  53. typedef LERPAnimationChannelClass<Vector2> RingScaleChannelClass;
  54. /**
  55. ** W3dRingStruct
  56. ** This structure is used to define a ring object in the W3D file format.
  57. */
  58. struct W3dRingStruct
  59. {
  60. uint32 Version; // file format version
  61. uint32 Attributes; // box attributes (above #define's)
  62. char Name[2*W3D_NAME_LEN]; // name is in the form <containername>.<boxname>
  63. W3dVectorStruct Center; // center of the box
  64. W3dVectorStruct Extent; // extent of the box
  65. float AnimDuration; // Animation time (in seconds)
  66. W3dVectorStruct DefaultColor;
  67. float DefaultAlpha;
  68. Vector2 DefaultInnerScale;
  69. Vector2 DefaultOuterScale;
  70. Vector2 InnerExtent;
  71. Vector2 OuterExtent;
  72. char TextureName[2*W3D_NAME_LEN];
  73. W3dShaderStruct Shader;
  74. int TextureTileCount;
  75. //
  76. // Note this structure is followed by a series of
  77. // W3dRingKeyArrayStruct structures which define the
  78. // variable set of keyframes for each channel
  79. };
  80. /*
  81. ** RingRenderObjClass: Procedurally generated render rings
  82. **
  83. */
  84. class RingRenderObjClass : public RenderObjClass
  85. {
  86. public:
  87. // These are bit masks, so they should enum 1,2,4,8,10,20,40 etc...
  88. enum RingFlags {
  89. USE_CAMERA_ALIGN = 0x00000001,
  90. USE_ANIMATION_LOOP= 0x00000002,
  91. };
  92. RingRenderObjClass(void);
  93. RingRenderObjClass(const W3dRingStruct & def);
  94. RingRenderObjClass(const RingRenderObjClass & src);
  95. RingRenderObjClass & operator = (const RingRenderObjClass &);
  96. ~RingRenderObjClass(void);
  97. /////////////////////////////////////////////////////////////////////////////
  98. // Render Object Interface
  99. /////////////////////////////////////////////////////////////////////////////
  100. virtual RenderObjClass * Clone(void) const;
  101. virtual int Class_ID(void) const;
  102. virtual void Render(RenderInfoClass & rinfo);
  103. virtual void Special_Render(SpecialRenderInfoClass & rinfo);
  104. virtual void Set_Transform(const Matrix3D &m);
  105. virtual void Set_Position(const Vector3 &v);
  106. virtual void Get_Obj_Space_Bounding_Sphere(SphereClass & sphere) const;
  107. virtual void Get_Obj_Space_Bounding_Box(AABoxClass & box) const;
  108. virtual void Set_Hidden(int onoff) { RenderObjClass::Set_Hidden (onoff); Update_On_Visibilty (); }
  109. virtual void Set_Visible(int onoff) { RenderObjClass::Set_Visible (onoff); Update_On_Visibilty (); }
  110. virtual void Set_Animation_Hidden(int onoff) { RenderObjClass::Set_Animation_Hidden (onoff); Update_On_Visibilty (); }
  111. virtual void Set_Force_Visible(int onoff) { RenderObjClass::Set_Force_Visible (onoff); Update_On_Visibilty (); }
  112. const AABoxClass & Get_Box(void);
  113. virtual int Get_Num_Polys(void) const;
  114. virtual const char *Get_Name(void) const;
  115. virtual void Set_Name(const char * name);
  116. unsigned int Get_Flags(void) {return Flags;}
  117. void Set_Flags(unsigned int flags) { Flags = flags; }
  118. void Set_Flag(unsigned int flag, bool onoff) { Flags &= (~flag); if (onoff) Flags |= flag; }
  119. // Animation access
  120. bool Is_Animating (void) { return IsAnimating; }
  121. void Start_Animating (void) { IsAnimating = true; anim_time = 0; }
  122. void Stop_Animating (void) { IsAnimating = false; anim_time = 0; }
  123. // Texture tiling access
  124. int Get_Texture_Tiling (void) const { return TextureTileCount; }
  125. void Set_Texture_Tiling (int count) { TextureTileCount = count; }
  126. // Current state access
  127. void Set_Color(const Vector3 & color) { Color = color; }
  128. void Set_Alpha(float alpha) { Alpha = alpha; }
  129. void Set_Inner_Scale(const Vector2 & scale) { InnerScale = scale; }
  130. void Set_Outer_Scale(const Vector2 & scale) { OuterScale = scale; }
  131. const Vector3 & Get_Color(void) const { return Color; }
  132. float Get_Alpha(void) const { return Alpha; }
  133. const Vector2 & Get_Inner_Scale(void) const { return InnerScale; }
  134. const Vector2 & Get_Outer_Scale(void) const { return OuterScale; }
  135. Vector3 Get_Default_Color(void) const;
  136. float Get_Default_Alpha(void) const;
  137. Vector2 Get_Default_Inner_Scale(void) const;
  138. Vector2 Get_Default_Outer_Scale(void) const;
  139. // Size/position methods
  140. const Vector2 & Get_Inner_Extent (void) const { return InnerExtent; }
  141. const Vector2 & Get_Outer_Extent (void) const { return OuterExtent; }
  142. void Set_Inner_Extent (const Vector2 &extent);
  143. void Set_Outer_Extent (const Vector2 &extent);
  144. void Set_Local_Center_Extent(const Vector3 & center,const Vector3 & extent);
  145. void Set_Local_Min_Max(const Vector3 & min,const Vector3 & max);
  146. // Texture access
  147. void Set_Texture(TextureClass *tf);
  148. TextureClass * Peek_Texture(void) { return RingTexture; }
  149. ShaderClass & Get_Shader(void) { return RingShader; }
  150. void Set_Shader(ShaderClass &shader) { RingShader = shader; }
  151. // Animation Control
  152. float Get_Animation_Duration(void) const { return AnimDuration; }
  153. void Set_Animation_Duration(float time) { AnimDuration = time; Restart_Animation(); }
  154. void Restart_Animation (void) { anim_time = 0; }
  155. // Animatable channel access
  156. RingColorChannelClass & Get_Color_Channel (void) { return ColorChannel; }
  157. const RingColorChannelClass & Peek_Color_Channel (void) { return ColorChannel; }
  158. RingAlphaChannelClass & Get_Alpha_Channel (void) { return AlphaChannel; }
  159. const RingAlphaChannelClass & Peek_Alpha_Channel (void) { return AlphaChannel; }
  160. RingScaleChannelClass & Get_Inner_Scale_Channel (void) { return InnerScaleChannel; }
  161. const RingScaleChannelClass & Peek_Inner_Scale_Channel (void) { return InnerScaleChannel; }
  162. RingScaleChannelClass & Get_Outer_Scale_Channel (void) { return OuterScaleChannel; }
  163. const RingScaleChannelClass & Peek_Outer_Scale_Channel (void) { return OuterScaleChannel; }
  164. void Set_Color_Channel (const RingColorChannelClass &data) { ColorChannel = data; }
  165. void Set_Alpha_Channel (const RingAlphaChannelClass &data) { AlphaChannel = data; }
  166. void Set_Inner_Scale_Channel (const RingScaleChannelClass &data) { InnerScaleChannel = data; }
  167. void Set_Outer_Scale_Channel (const RingScaleChannelClass &data) { OuterScaleChannel = data; }
  168. protected:
  169. virtual void update_cached_box(void);
  170. void Update_On_Visibilty(void);
  171. // Initialization stuff
  172. void Init_Material (void);
  173. static void Generate_Shared_Mesh_Arrays (void);
  174. // Animation Stuff
  175. void animate(void); // animation update function
  176. float anim_time; // what time in seconds are we in the animation
  177. float AnimDuration;
  178. bool IsAnimating;
  179. RingColorChannelClass ColorChannel;
  180. RingAlphaChannelClass AlphaChannel;
  181. RingScaleChannelClass InnerScaleChannel;
  182. RingScaleChannelClass OuterScaleChannel;
  183. void update_mesh_data(const Vector3 & center,const Vector3 & extent);
  184. void render_ring(RenderInfoClass & rinfo,const Vector3 & center,const Vector3 & extent);
  185. void vis_render_ring(SpecialRenderInfoClass & rinfo,const Vector3 & center,const Vector3 & extent);
  186. char Name[2*W3D_NAME_LEN];
  187. Vector3 ObjSpaceCenter;
  188. Vector3 ObjSpaceExtent;
  189. Vector2 InnerExtent;
  190. Vector2 OuterExtent;
  191. int CurrentLOD;
  192. int TextureTileCount;
  193. // Current State
  194. Vector3 Color;
  195. float Alpha;
  196. Vector2 InnerScale;
  197. Vector2 OuterScale;
  198. // Flags
  199. unsigned int Flags;
  200. VertexMaterialClass *RingMaterial;
  201. ShaderClass RingShader;
  202. TextureClass *RingTexture;
  203. AABoxClass CachedBox;
  204. // Friend classes
  205. friend class RingPrototypeClass;
  206. };
  207. inline void RingRenderObjClass::Set_Inner_Extent (const Vector2 &extent)
  208. {
  209. InnerExtent = extent;
  210. }
  211. inline void RingRenderObjClass::Set_Outer_Extent (const Vector2 &extent)
  212. {
  213. OuterExtent = extent;
  214. ObjSpaceExtent.X = extent.X;
  215. ObjSpaceExtent.Y = extent.Y;
  216. ObjSpaceExtent.Z = 0;
  217. update_cached_box();
  218. }
  219. inline void RingRenderObjClass::Set_Local_Center_Extent(const Vector3 & center,const Vector3 & extent)
  220. {
  221. ObjSpaceCenter = center;
  222. ObjSpaceExtent = extent;
  223. update_cached_box();
  224. }
  225. inline void RingRenderObjClass::Set_Local_Min_Max(const Vector3 & min,const Vector3 & max)
  226. {
  227. ObjSpaceCenter = (max + min) / 2.0f;
  228. ObjSpaceExtent = (max - min) / 2.0f;
  229. update_cached_box();
  230. }
  231. inline const AABoxClass & RingRenderObjClass::Get_Box(void)
  232. {
  233. Validate_Transform();
  234. update_cached_box();
  235. return CachedBox;
  236. }
  237. /*
  238. ** Loader for rings
  239. */
  240. class RingLoaderClass : public PrototypeLoaderClass
  241. {
  242. public:
  243. virtual int Chunk_Type (void) { return W3D_CHUNK_RING; }
  244. virtual PrototypeClass * Load_W3D(ChunkLoadClass & cload);
  245. };
  246. /*
  247. ** Prototype for Ring objects
  248. */
  249. class RingPrototypeClass : public W3DMPO, public PrototypeClass
  250. {
  251. W3DMPO_GLUE(RingPrototypeClass)
  252. public:
  253. RingPrototypeClass (void);
  254. RingPrototypeClass (RingRenderObjClass *ring);
  255. virtual const char * Get_Name(void) const;
  256. virtual int Get_Class_ID(void) const;
  257. virtual RenderObjClass * Create(void);
  258. virtual void DeleteSelf() { delete this; }
  259. bool Load (ChunkLoadClass &cload);
  260. bool Save (ChunkSaveClass &csave);
  261. protected:
  262. ~RingPrototypeClass (void);
  263. private:
  264. W3dRingStruct Definition;
  265. RingColorChannelClass ColorChannel;
  266. RingAlphaChannelClass AlphaChannel;
  267. RingScaleChannelClass InnerScaleChannel;
  268. RingScaleChannelClass OuterScaleChannel;
  269. };
  270. /*
  271. ** Instance of the loader which the asset manager installs
  272. */
  273. extern RingLoaderClass _RingLoader;
  274. #endif // RINGOBJ_H
  275. // EOF - ringobj,h