rendobj.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  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:: /VSS_Sync/ww3d2/rendobj.h $*
  25. * *
  26. * Author:: Greg Hjelstrom *
  27. * *
  28. * $Modtime:: 8/29/01 7:29p $*
  29. * *
  30. * $Revision:: 14 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef RENDOBJ_H
  39. #define RENDOBJ_H
  40. #include "always.h"
  41. #include "refcount.h"
  42. #include "sphere.h"
  43. #include "coltype.h"
  44. #include "aabox.h"
  45. #include "persist.h"
  46. #include "multilist.h"
  47. #include "robjlist.h"
  48. #include <float.h>
  49. class Vector3;
  50. class Matrix3D;
  51. class MaterialInfoClass;
  52. class TextureClass;
  53. class SceneClass;
  54. class HTreeClass;
  55. class HAnimClass;
  56. class HAnimComboClass;
  57. class HCompressedAnimClass;
  58. class RayCollisionTestClass;
  59. class AABoxCollisionTestClass;
  60. class OBBoxCollisionTestClass;
  61. class AABoxIntersectionTestClass;
  62. class OBBoxIntersectionTestClass;
  63. class CameraClass;
  64. class SphereClass;
  65. class AABoxClass;
  66. class RenderInfoClass;
  67. class SpecialRenderInfoClass;
  68. class IntersectionClass;
  69. class IntersectionResultClass;
  70. class DecalGeneratorClass;
  71. class RenderObjProxyClass;
  72. class StringClass;
  73. template<class T> class DynamicVectorClass;
  74. // "unreferenced formal parameter"
  75. #pragma warning(disable : 4100)
  76. #ifdef DEFINE_W3DANIMMODE_NAMES
  77. static const char* TheAnimModeNames[] =
  78. {
  79. "MANUAL",
  80. "LOOP",
  81. "ONCE",
  82. "LOOP_PINGPONG",
  83. "LOOP_BACKWARDS",
  84. "ONCE_BACKWARDS",
  85. NULL
  86. };
  87. #endif
  88. //////////////////////////////////////////////////////////////////////////////////
  89. // RenderObjClass
  90. // This is the interface for all objects that get rendered by WW3D.
  91. //
  92. // Render object RTTI: If you really need to typecast a render object
  93. // pointer that you got from the asset manager, the class id mechanism
  94. // can be used to check what you really have. User class id's can come
  95. // after CLASSID_LAST.
  96. //
  97. // Cloning: All RenderObj's need to be able to clone themselves. This function
  98. // should create a new and separate RenderObj of the correct type and return a
  99. // RenderObj pointer to it. The implementation of this function will be
  100. // to simply call your copy constructor; its basically a virtual copy constructor.
  101. //
  102. // Rendering: If the render object is in a scene that is rendered and is determined
  103. // to be visible by that scene, it will receive a Render call. The argument
  104. // to the call will contain both the camera being used and the low level rendering
  105. // interface. In addition, the Special_Render function is for all "non-normal"
  106. // types of rendering. Some examples of this are: G-Buffer rendering (rendering
  107. // object ID's), shadow rendering (just use black, etc) and whatever else we
  108. // come up with. Basically it will be a function with a big switch statement
  109. // to handle all of these extra operations. This means the main render code
  110. // path is not cluttered with these checks while not forcing every object to
  111. // implement millions of separate special render functions. (Many objects just
  112. // pass the render calls onto their sub-objects).
  113. //
  114. // VertexProcessors: Vertex processors are classes that are not actually 'rendered'
  115. // They insert into the system an object that performs operations on all of
  116. // the subsequent vertices that are processed. Lights and Fogs are types of
  117. // vertex processors.
  118. //
  119. // "Scene Graph": A scene is organized as a list of render objects. There is no
  120. // implied hierarchical structure to a scene. RenderObjects can contain other
  121. // render objects (they follow the 'Composite' pattern) which is how hierarchical
  122. // objects are built. Hierarchical models are render objects that just
  123. // contain other render objects and apply hierarchical transforms to them.
  124. // Hierarchical Models can be inserted inside of other hierarchical models.
  125. //
  126. // Predictive LOD: The predictive LOD system selects LODs for the visible objects
  127. // so that the various resources (polys, vertices, etc.) do not pass given
  128. // budgets - the goal is to achieve a constant frame rate. This interface
  129. // includes things that are needed for this optimization process. Objects which
  130. // do not support changing their LOD should report that they have 1 LOD and
  131. // should report their cost to the LOD optimization system.
  132. //
  133. // Dependency Generation: Render objects are composed of one or more W3D and
  134. // texture files. This set of interfaces provides access to that dependency list.
  135. //
  136. //////////////////////////////////////////////////////////////////////////////////
  137. class RenderObjClass : public RefCountClass , public PersistClass, public MultiListObjectClass
  138. {
  139. public:
  140. //Integer flag placed at the start of structure pointed to by
  141. //User_Data to signal that it points at custom mesh material settings.
  142. //Added for 'Generals' - MW
  143. enum {USER_DATA_MATERIAL_OVERRIDE = 0x01234567};
  144. //This strucutre is used to pass custom rendering parameters into the W3D
  145. //mesh renderer so it can override settings which are usually shared across
  146. //all instances of a model - typically material settings like alpha, texture
  147. //animation, texture uv scrolling, etc. Added for 'Generals' -MW
  148. struct Material_Override
  149. { Material_Override(void) : Struct_ID(USER_DATA_MATERIAL_OVERRIDE),customUVOffset(0,0) {}
  150. int Struct_ID; //ID used to identify this structure from a pointer to it.
  151. Vector2 customUVOffset;
  152. };
  153. //
  154. // Note: It is very important that these values NEVER CHANGE. That means
  155. // when adding a new class id, it should be added to the end of the enum.
  156. //
  157. enum
  158. {
  159. CLASSID_UNKNOWN = 0xFFFFFFFF,
  160. CLASSID_MESH = 0,
  161. CLASSID_HMODEL,
  162. CLASSID_DISTLOD,
  163. CLASSID_PREDLODGROUP,
  164. CLASSID_TILEMAP,
  165. CLASSID_IMAGE3D, // Obsolete
  166. CLASSID_LINE3D,
  167. CLASSID_BITMAP2D, // Obsolete
  168. CLASSID_CAMERA,
  169. CLASSID_DYNAMESH,
  170. CLASSID_DYNASCREENMESH,
  171. CLASSID_TEXTDRAW,
  172. CLASSID_FOG,
  173. CLASSID_LAYERFOG,
  174. CLASSID_LIGHT,
  175. CLASSID_PARTICLEEMITTER,
  176. CLASSID_PARTICLEBUFFER,
  177. CLASSID_SCREENPOINTGROUP,
  178. CLASSID_VIEWPOINTGROUP,
  179. CLASSID_WORLDPOINTGROUP,
  180. CLASSID_TEXT2D,
  181. CLASSID_TEXT3D,
  182. CLASSID_NULL,
  183. CLASSID_COLLECTION,
  184. CLASSID_FLARE,
  185. CLASSID_HLOD,
  186. CLASSID_AABOX,
  187. CLASSID_OBBOX,
  188. CLASSID_SEGLINE,
  189. CLASSID_SPHERE,
  190. CLASSID_RING,
  191. CLASSID_BOUNDFOG,
  192. CLASSID_DAZZLE,
  193. CLASSID_SOUND,
  194. CLASSID_SEGLINETRAIL,
  195. CLASSID_LAND,
  196. CLASSID_LAST = 0x0000FFFF
  197. };
  198. RenderObjClass(void);
  199. RenderObjClass(const RenderObjClass & src);
  200. RenderObjClass & RenderObjClass::operator = (const RenderObjClass &);
  201. virtual ~RenderObjClass(void) { }
  202. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  203. // Render Object Interface - Cloning and Identification
  204. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  205. virtual RenderObjClass * Clone(void) const = 0;
  206. virtual int Class_ID(void) const { return CLASSID_UNKNOWN; }
  207. virtual const char * Get_Name(void) const { return "UNNAMED"; }
  208. virtual void Set_Name(const char * name) { }
  209. virtual const char * Get_Base_Model_Name (void) const { return NULL; }
  210. virtual void Set_Base_Model_Name (const char *name) { }
  211. virtual int Get_Num_Polys(void) const { return 0; }
  212. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  213. // Render Object Interface - Rendering
  214. //
  215. // Render - this object should render its polygons. Typically called from a SceneClass
  216. // Special_Render - all special-case rendering goes here to avoid polluting the main render pipe (e.g. VIS)
  217. // On_Frame_Update - render objects can register for an On_Frame_Update call; the scene will call this once
  218. // per frame if they do so.
  219. // Restart - This interface is used to facilitate model recycling. If a render object is "Restarted" it should
  220. // put itself back into a state as if it has never been rendered (e.g. particle emitters
  221. // should reset their "emitted particle counts" so they can be re-used.)
  222. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  223. virtual void Render(RenderInfoClass & rinfo) = 0;
  224. virtual void Special_Render(SpecialRenderInfoClass & rinfo) { }
  225. virtual void On_Frame_Update() { }
  226. virtual void Restart(void) { }
  227. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  228. // Render Object Interface - "Scene Graph"
  229. // Some of the functions in this group are non-virtual as they are meant
  230. // to be never overriden or are supposed to be implemented in terms of
  231. // the other virtual functions. We want to keep the virtual interface
  232. // as small as possible
  233. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  234. virtual void Add(SceneClass * scene);
  235. virtual void Remove(void);
  236. virtual SceneClass * Get_Scene(void);
  237. virtual SceneClass * Peek_Scene(void) { return Scene; }
  238. virtual void Set_Container(RenderObjClass * con);
  239. virtual void Validate_Transform(void) const;
  240. #define GET_CONTAINER_INLINE
  241. #ifdef GET_CONTAINER_INLINE
  242. // srj sez: this is called a ton and never overridden, so inline it
  243. inline RenderObjClass * Get_Container(void) const { return Container; }
  244. #else
  245. virtual RenderObjClass * Get_Container(void) const;
  246. #endif
  247. virtual void Set_Transform(const Matrix3D &m);
  248. virtual void Set_Position(const Vector3 &v);
  249. const Matrix3D & Get_Transform(void) const;
  250. const Matrix3D & Get_Transform(bool& is_transform_identity) const;
  251. const Matrix3D & Get_Transform_No_Validity_Check(void) const;
  252. const Matrix3D & Get_Transform_No_Validity_Check(bool& is_transform_identity) const;
  253. bool Is_Transform_Identity() const;
  254. bool Is_Transform_Identity_No_Validity_Check() const;
  255. Vector3 Get_Position(void) const;
  256. virtual void Notify_Added(SceneClass * scene);
  257. virtual void Notify_Removed(SceneClass * scene);
  258. virtual int Get_Num_Sub_Objects(void) const { return 0; }
  259. virtual RenderObjClass * Get_Sub_Object(int index) const { return NULL; }
  260. virtual int Add_Sub_Object(RenderObjClass * subobj) { return 0; }
  261. virtual int Remove_Sub_Object(RenderObjClass * robj) { return 0; }
  262. virtual RenderObjClass * Get_Sub_Object_By_Name(const char * name, int *index=NULL) const;
  263. virtual int Get_Num_Sub_Objects_On_Bone(int boneindex) const { return 0; }
  264. virtual RenderObjClass * Get_Sub_Object_On_Bone(int index,int boneindex) const { return NULL; }
  265. virtual int Get_Sub_Object_Bone_Index(RenderObjClass * subobj) const { return 0; }
  266. virtual int Get_Sub_Object_Bone_Index(int LodIndex, int ModelIndex) const { return 0; }
  267. virtual int Add_Sub_Object_To_Bone(RenderObjClass * subobj,int bone_index) { return 0; }
  268. virtual int Add_Sub_Object_To_Bone(RenderObjClass * subobj,const char * bname);
  269. virtual int Remove_Sub_Objects_From_Bone(const char * bname);
  270. // This is public only so objects can recursively call this on their sub-objects
  271. virtual void Update_Sub_Object_Transforms(void);
  272. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  273. // Render Object Interface - Hierarchical Animation
  274. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  275. enum AnimMode
  276. {
  277. ANIM_MODE_MANUAL = 0,
  278. ANIM_MODE_LOOP,
  279. ANIM_MODE_ONCE,
  280. ANIM_MODE_LOOP_PINGPONG,
  281. ANIM_MODE_LOOP_BACKWARDS, //make sure only backwards playing animations after this one
  282. ANIM_MODE_ONCE_BACKWARDS,
  283. };
  284. virtual void Set_Animation( void ) { }
  285. virtual void Set_Animation( HAnimClass * motion,
  286. float frame, int anim_mode = ANIM_MODE_MANUAL) { }
  287. virtual void Set_Animation( HAnimClass * motion0,
  288. float frame0,
  289. HAnimClass * motion1,
  290. float frame1,
  291. float percentage) { }
  292. virtual void Set_Animation( HAnimComboClass * anim_combo) { }
  293. virtual HAnimClass * Peek_Animation( void ) { return NULL; }
  294. virtual int Get_Num_Bones(void) { return 0; }
  295. virtual const char * Get_Bone_Name(int bone_index) { return NULL; }
  296. virtual int Get_Bone_Index(const char * bonename) { return 0; }
  297. virtual const Matrix3D & Get_Bone_Transform(const char * bonename) { return Get_Transform(); }
  298. virtual const Matrix3D & Get_Bone_Transform(int boneindex) { return Get_Transform(); }
  299. virtual void Capture_Bone(int bindex) { }
  300. virtual void Release_Bone(int bindex) { }
  301. virtual bool Is_Bone_Captured(int bindex) const { return false; }
  302. virtual void Control_Bone(int bindex,const Matrix3D & objtm,bool world_space_translation = false) { }
  303. virtual const HTreeClass * Get_HTree(void) const { return NULL; }
  304. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  305. // Render Object Interface - Collision Detection
  306. // Cast_Ray - intersects a ray with the render object
  307. // Cast_AABox - intersects a swept AABox with the render object
  308. // Cast_OBBox - intersects a swept OBBox with the render object
  309. // Intersect_AABox - boolean test for intersection between an AABox and the renderobj
  310. // Intersect_OBBox - boolean test for intersection between an OBBox and the renderobj
  311. // Intersect - tests a ray for intersection with the render object
  312. // Intersect_Sphere - tests a ray for intersection with the bounding spheres
  313. // Intersect_Sphere_Quick - tests a ray for intersection with bounding spheres
  314. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  315. virtual bool Cast_Ray(RayCollisionTestClass & raytest) { return false; }
  316. virtual bool Cast_AABox(AABoxCollisionTestClass & boxtest) { return false; }
  317. virtual bool Cast_OBBox(OBBoxCollisionTestClass & boxtest) { return false; }
  318. virtual bool Intersect_AABox(AABoxIntersectionTestClass & boxtest) { return false; }
  319. virtual bool Intersect_OBBox(OBBoxIntersectionTestClass & boxtest) { return false; }
  320. virtual bool Intersect(IntersectionClass *Intersection, IntersectionResultClass *Final_Result);
  321. virtual bool Intersect_Sphere(IntersectionClass *Intersection, IntersectionResultClass *Final_Result);
  322. virtual bool Intersect_Sphere_Quick(IntersectionClass *Intersection, IntersectionResultClass *Final_Result);
  323. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  324. // Render Object Interface - Bounding Volumes
  325. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  326. virtual const SphereClass & Get_Bounding_Sphere(void) const;
  327. virtual const AABoxClass & Get_Bounding_Box(void) const;
  328. virtual void Get_Obj_Space_Bounding_Sphere(SphereClass & sphere) const;
  329. virtual void Get_Obj_Space_Bounding_Box(AABoxClass & box) const;
  330. virtual void Update_Obj_Space_Bounding_Volumes(void) { };
  331. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  332. // Render Object Interface - Predictive LOD
  333. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  334. // Two constants for Value queries, which are returned instead of the
  335. // current Value in certain cases. They are usually used as sentinels.
  336. // AT_MIN_LOD is a very large positive number, AT_MAX_LOD is negative.
  337. static const float AT_MIN_LOD;
  338. static const float AT_MAX_LOD;
  339. virtual void Prepare_LOD(CameraClass &camera);
  340. virtual void Recalculate_Static_LOD_Factors(void) { }
  341. virtual void Increment_LOD(void) { }
  342. virtual void Decrement_LOD(void) { }
  343. virtual float Get_Cost(void) const;
  344. virtual float Get_Value(void) const { return AT_MIN_LOD; }
  345. virtual float Get_Post_Increment_Value(void) const { return AT_MAX_LOD; }
  346. virtual void Set_LOD_Level(int lod) { }
  347. virtual int Get_LOD_Level(void) const { return 0; }
  348. virtual int Get_LOD_Count(void) const { return 1; }
  349. virtual void Set_LOD_Bias(float bias) { }
  350. virtual int Calculate_Cost_Value_Arrays(float screen_area, float *values, float *costs) const;
  351. virtual RenderObjClass * Get_Current_LOD(void) { Add_Ref(); return this; }
  352. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  353. // Render Object Interface - Dependency Generation
  354. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  355. //
  356. // Note: The strings contained in these lists need to be freed by the caller.
  357. // They should be freed using the delete operator.
  358. //
  359. // Be aware, these lists WILL contain duplicate entries.
  360. //
  361. virtual bool Build_Dependency_List (DynamicVectorClass<StringClass> &file_list, bool recursive=true);
  362. virtual bool Build_Texture_List (DynamicVectorClass<StringClass> &texture_file_list, bool recursive=true);
  363. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  364. // Render Object Interface - Decals
  365. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  366. virtual void Create_Decal(DecalGeneratorClass * generator) { }
  367. virtual void Delete_Decal(uint32 decal_id) { }
  368. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  369. // Render Object Interface - Attributes, Options, Properties, etc
  370. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  371. virtual MaterialInfoClass * Get_Material_Info(void) { return NULL; }
  372. virtual void Set_User_Data(void *value, bool recursive = false) { User_Data = value; };
  373. virtual void * Get_User_Data() { return User_Data; };
  374. virtual int Get_Num_Snap_Points(void) { return 0; }
  375. virtual void Get_Snap_Point(int index,Vector3 * set) { }
  376. // virtual float Calculate_Texture_Reduction_Factor(float norm_screensize);
  377. // virtual void Set_Texture_Reduction_Factor(float trf);
  378. virtual float Get_Screen_Size(CameraClass &camera);
  379. virtual void Scale(float scale) { };
  380. virtual void Scale(float scalex, float scaley, float scalez) { };
  381. virtual void Set_ObjectScale(float scale) { ObjectScale=scale;} //set's a scale factor that's factored into transform matrix.
  382. const float Get_ObjectScale( void ) const { return ObjectScale; };
  383. void Set_ObjectColor(unsigned int color) { ObjectColor=color;} //the color that was used to modify the asset for player team color (for Generals). -MW
  384. const unsigned int Get_ObjectColor( void ) const { return ObjectColor; };
  385. virtual int Get_Sort_Level(void) const { return 0; /* SORT_LEVEL_NONE */ }
  386. virtual void Set_Sort_Level(int level) { }
  387. virtual int Is_Really_Visible(void) { return ((Bits & IS_REALLY_VISIBLE) == IS_REALLY_VISIBLE); }
  388. virtual int Is_Not_Hidden_At_All(void) { return ((Bits & IS_NOT_HIDDEN_AT_ALL) == IS_NOT_HIDDEN_AT_ALL); }
  389. virtual int Is_Visible(void) const { return (Bits & IS_VISIBLE); }
  390. virtual void Set_Visible(int onoff) { if (onoff) { Bits |= IS_VISIBLE; } else { Bits &= ~IS_VISIBLE; } }
  391. virtual int Is_Hidden(void) const { return !(Bits & IS_NOT_HIDDEN); }
  392. virtual void Set_Hidden(int onoff) { if (onoff) { Bits &= ~IS_NOT_HIDDEN; } else { Bits |= IS_NOT_HIDDEN; } }
  393. virtual int Is_Animation_Hidden(void) const { return !(Bits & IS_NOT_ANIMATION_HIDDEN); }
  394. virtual void Set_Animation_Hidden(int onoff) { if (onoff) { Bits &= ~IS_NOT_ANIMATION_HIDDEN; } else { Bits |= IS_NOT_ANIMATION_HIDDEN; } }
  395. virtual int Is_Force_Visible(void) const { return Bits & IS_FORCE_VISIBLE; }
  396. virtual void Set_Force_Visible(int onoff) { if (onoff) { Bits |= IS_FORCE_VISIBLE; } else { Bits &= ~IS_FORCE_VISIBLE; } }
  397. virtual int Is_Translucent(void) const { return Bits & IS_TRANSLUCENT; }
  398. virtual void Set_Translucent(int onoff) { if (onoff) { Bits |= IS_TRANSLUCENT; } else { Bits &= ~IS_TRANSLUCENT; } }
  399. virtual int Is_Alpha(void) const { return Bits & IS_ALPHA; }
  400. virtual void Set_Alpha(int onoff) { if (onoff) { Bits |= IS_ALPHA; } else { Bits &= ~IS_ALPHA; } }
  401. virtual int Is_Additive(void) const { return Bits & IS_ADDITIVE; }
  402. virtual void Set_Additive(int onoff) { if (onoff) { Bits |= IS_ADDITIVE; } else { Bits &= ~IS_ADDITIVE; } }
  403. virtual int Get_Collision_Type(void) const { return (Bits & COLLISION_TYPE_MASK); }
  404. virtual void Set_Collision_Type(int type) { Bits &= ~COLLISION_TYPE_MASK; Bits |= (type & COLLISION_TYPE_MASK) | COLLISION_TYPE_ALL; }
  405. virtual bool Is_Complete(void) { return false; }
  406. virtual bool Is_In_Scene(void) { return Scene != NULL; }
  407. virtual float Get_Native_Screen_Size(void) const { return NativeScreenSize; }
  408. virtual void Set_Native_Screen_Size(float screensize) { NativeScreenSize = screensize; }
  409. void Set_Sub_Objects_Match_LOD(int onoff) { if (onoff) { Bits |= SUBOBJS_MATCH_LOD; } else { Bits &= ~SUBOBJS_MATCH_LOD; } }
  410. int Is_Sub_Objects_Match_LOD_Enabled(void) { return Bits & SUBOBJS_MATCH_LOD; }
  411. void Set_Sub_Object_Transforms_Dirty(bool onoff) { if (onoff) { Bits |= SUBOBJ_TRANSFORMS_DIRTY; } else { Bits &= ~SUBOBJ_TRANSFORMS_DIRTY; } }
  412. bool Are_Sub_Object_Transforms_Dirty(void) { return (Bits & SUBOBJ_TRANSFORMS_DIRTY) != 0; }
  413. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  414. // Persistant object save-load interface
  415. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  416. virtual const PersistFactoryClass & Get_Factory (void) const;
  417. virtual bool Save (ChunkSaveClass &csave);
  418. virtual bool Load (ChunkLoadClass &cload);
  419. protected:
  420. virtual void Add_Dependencies_To_List (DynamicVectorClass<StringClass> &file_list, bool textures_only = false);
  421. virtual void Update_Cached_Bounding_Volumes(void) const;
  422. virtual void Update_Sub_Object_Bits(void);
  423. bool Bounding_Volumes_Valid(void) const { return (Bits & BOUNDING_VOLUMES_VALID) != 0; }
  424. void Invalidate_Cached_Bounding_Volumes(void) const { Bits &= ~BOUNDING_VOLUMES_VALID; }
  425. void Validate_Cached_Bounding_Volumes(void) const { Bits |= BOUNDING_VOLUMES_VALID; }
  426. enum
  427. {
  428. COLLISION_TYPE_MASK = 0x000000FF,
  429. IS_VISIBLE = 0x00000100,
  430. IS_NOT_HIDDEN = 0x00000200,
  431. IS_NOT_ANIMATION_HIDDEN = 0x00000400,
  432. IS_FORCE_VISIBLE = 0x00000800,
  433. BOUNDING_VOLUMES_VALID = 0x00002000,
  434. IS_TRANSLUCENT = 0x00004000, // is additive or alpha blended on any poly
  435. //IS_VERTEX_PROCESSOR = 0x00008000, // is or has a vertex processor, OBSOLETE!
  436. SUBOBJS_MATCH_LOD = 0x00010000, // force sub-objects to have same LOD level
  437. SUBOBJ_TRANSFORMS_DIRTY = 0x00020000, // my sub-objects need me to update their transform
  438. IS_ALPHA = 0x00040000, // added for Generals so we can default these meshes not to cast shadows. -MW
  439. IS_ADDITIVE = 0x00080000, //added for Generals so we quickly determine what type of blending is on the mesh. -MW
  440. IS_REALLY_VISIBLE = IS_VISIBLE | IS_NOT_HIDDEN | IS_NOT_ANIMATION_HIDDEN,
  441. IS_NOT_HIDDEN_AT_ALL = IS_NOT_HIDDEN | IS_NOT_ANIMATION_HIDDEN,
  442. DEFAULT_BITS = COLLISION_TYPE_ALL | IS_NOT_HIDDEN | IS_NOT_ANIMATION_HIDDEN,
  443. };
  444. mutable unsigned long Bits;
  445. Matrix3D Transform;
  446. float ObjectScale; //user applied scaling factor inside Transform matrix.
  447. unsigned int ObjectColor; //user applied coloring to the asset/prototype used to make this robj. - For Generals -MW
  448. mutable SphereClass CachedBoundingSphere;
  449. mutable AABoxClass CachedBoundingBox;
  450. float NativeScreenSize; // The screen size at which the object was designed to be viewed (used in texture resizing).
  451. mutable bool IsTransformIdentity;
  452. SceneClass * Scene;
  453. RenderObjClass * Container;
  454. void * User_Data;
  455. friend class SceneClass;
  456. friend class RenderObjProxyClass;
  457. };
  458. WWINLINE const SphereClass & RenderObjClass::Get_Bounding_Sphere(void) const
  459. {
  460. if (!(Bits & BOUNDING_VOLUMES_VALID)) {
  461. Update_Cached_Bounding_Volumes();
  462. }
  463. return CachedBoundingSphere;
  464. }
  465. WWINLINE const AABoxClass & RenderObjClass::Get_Bounding_Box(void) const
  466. {
  467. if (!(Bits & BOUNDING_VOLUMES_VALID)) {
  468. Update_Cached_Bounding_Volumes();
  469. }
  470. return CachedBoundingBox;
  471. }
  472. /**************************************************************************
  473. * Bound_Degrees -- Bounds a degree value between 0 and 360. *
  474. * *
  475. * INPUT: *
  476. * *
  477. * OUTPUT: *
  478. * *
  479. * WARNINGS: *
  480. * *
  481. * HISTORY: *
  482. * 09/22/1997 PWG : Created. *
  483. *========================================================================*/
  484. WWINLINE float Bound_Degrees(float angle)
  485. {
  486. while (angle > 359) angle -= 360;
  487. while (angle < 0) angle += 360;
  488. return angle;
  489. }
  490. /***********************************************************************************************
  491. * RenderObjClass::Get_Transform -- returns the transform for the object *
  492. * *
  493. * If the transform is invalid (a container has been moved or animated) then the transform *
  494. * will be recalculated. *
  495. * *
  496. * INPUT: *
  497. * *
  498. * OUTPUT: *
  499. * *
  500. * WARNINGS: *
  501. * *
  502. * HISTORY: *
  503. * 2/25/99 GTH : Created. *
  504. *=============================================================================================*/
  505. WWINLINE const Matrix3D & RenderObjClass::Get_Transform(void) const
  506. {
  507. Validate_Transform();
  508. return Transform;
  509. }
  510. WWINLINE const Matrix3D & RenderObjClass::Get_Transform(bool &is_transform_identity) const
  511. {
  512. Validate_Transform();
  513. is_transform_identity=IsTransformIdentity;
  514. return Transform;
  515. }
  516. WWINLINE bool RenderObjClass::Is_Transform_Identity() const
  517. {
  518. Validate_Transform();
  519. return IsTransformIdentity;
  520. }
  521. // Warning: Be sure to call this function only if the transform is known to be valid!
  522. WWINLINE const Matrix3D & RenderObjClass::Get_Transform_No_Validity_Check(void) const
  523. {
  524. return Transform;
  525. }
  526. // Warning: Be sure to call this function only if the transform is known to be valid!
  527. WWINLINE const Matrix3D & RenderObjClass::Get_Transform_No_Validity_Check(bool& is_transform_identity) const
  528. {
  529. is_transform_identity=IsTransformIdentity;
  530. return Transform;
  531. }
  532. // Warning: Be sure to call this function only if the transform is known to be valid!
  533. WWINLINE bool RenderObjClass::Is_Transform_Identity_No_Validity_Check() const
  534. {
  535. return IsTransformIdentity;
  536. }
  537. #endif