rendobj.h 29 KB

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