renderobjphys.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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/renderobjphys.cpp $*
  25. * *
  26. * Author:: Greg Hjelstrom *
  27. * *
  28. * $Modtime:: 9/27/00 1:54p $*
  29. * *
  30. * $Revision:: 9 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "renderobjphys.h"
  36. #include "rendobj.h"
  37. #include "persistfactory.h"
  38. #include "wwphysids.h"
  39. /*
  40. ** Declare a PersistFactory for RenderObjPhysClasses
  41. */
  42. SimplePersistFactoryClass<RenderObjPhysClass,PHYSICS_CHUNKID_RENDEROBJPHYS> _RenderObjPhysFactory;
  43. /*
  44. ** Chunk ID's used by RenderObjPhysClass
  45. */
  46. enum
  47. {
  48. RENDEROBJPHYS_CHUNK_PHYS = 0x00099900, // obsolete, old parent class
  49. RENDEROBJPHYS_CHUNK_DYNAMICPHYS
  50. };
  51. /**
  52. ** RenderObjPhysClass
  53. ** NOTE: remember that this class is mainly intended just as a simple wrapper around render
  54. ** objects that are added directly to the physics scene. Normally, only the physics scene
  55. ** itself will be creating and using these. If you find yourself creating these objects,
  56. ** consider using DecorationPhysClass instead...
  57. */
  58. RenderObjPhysClass::RenderObjPhysClass(void)
  59. {
  60. Enable_Is_Pre_Lit(true);
  61. if (Model) {
  62. Model->Set_User_Data(this);
  63. }
  64. }
  65. RenderObjPhysClass::~RenderObjPhysClass(void)
  66. {
  67. if (Model) {
  68. Model->Set_User_Data(0);
  69. }
  70. }
  71. void RenderObjPhysClass::Set_Model(RenderObjClass * model)
  72. {
  73. if (Model) {
  74. Model->Set_User_Data(0);
  75. }
  76. // Let the base class have the model
  77. DynamicPhysClass::Set_Model(model);
  78. if (Model) {
  79. Model->Set_User_Data(this);
  80. if (Model->Class_ID() == RenderObjClass::CLASSID_HLOD) {
  81. Enable_Is_Pre_Lit(false);
  82. } else {
  83. Enable_Is_Pre_Lit(true);
  84. }
  85. }
  86. }
  87. const AABoxClass & RenderObjPhysClass::Get_Bounding_Box(void) const
  88. {
  89. assert(Model);
  90. return Model->Get_Bounding_Box();
  91. }
  92. const Matrix3D & RenderObjPhysClass::Get_Transform(void) const
  93. {
  94. assert(Model);
  95. return Model->Get_Transform();
  96. }
  97. void RenderObjPhysClass::Set_Transform(const Matrix3D & m)
  98. {
  99. // Note: this kind of object never causes collisions so we
  100. // can just warp it to the users desired position. However,
  101. // we do need to tell the scene that we moved so that
  102. // it can update us in the culling system
  103. assert(Model);
  104. Model->Set_Transform(m);
  105. Update_Cull_Box();
  106. }
  107. bool RenderObjPhysClass::Cast_Ray(PhysRayCollisionTestClass & raytest)
  108. {
  109. assert(Model);
  110. if (Model->Cast_Ray(raytest)) {
  111. raytest.CollidedPhysObj = this;
  112. return true;
  113. }
  114. return false;
  115. }
  116. bool RenderObjPhysClass::Cast_AABox(PhysAABoxCollisionTestClass & boxtest)
  117. {
  118. assert(Model);
  119. if (Model->Cast_AABox(boxtest)) {
  120. boxtest.CollidedPhysObj = this;
  121. return true;
  122. }
  123. return false;
  124. }
  125. bool RenderObjPhysClass::Cast_OBBox(PhysOBBoxCollisionTestClass & boxtest)
  126. {
  127. assert(Model);
  128. if (Model->Cast_OBBox(boxtest)) {
  129. boxtest.CollidedPhysObj = this;
  130. return true;
  131. }
  132. return false;
  133. }
  134. /*
  135. ** Save-Load System
  136. */
  137. const PersistFactoryClass & RenderObjPhysClass::Get_Factory (void) const
  138. {
  139. return _RenderObjPhysFactory;
  140. }
  141. bool RenderObjPhysClass::Save (ChunkSaveClass &csave)
  142. {
  143. csave.Begin_Chunk(RENDEROBJPHYS_CHUNK_DYNAMICPHYS);
  144. DynamicPhysClass::Save(csave);
  145. csave.End_Chunk();
  146. return true;
  147. }
  148. bool RenderObjPhysClass::Load (ChunkLoadClass &cload)
  149. {
  150. while (cload.Open_Chunk()) {
  151. switch(cload.Cur_Chunk_ID())
  152. {
  153. case RENDEROBJPHYS_CHUNK_PHYS:
  154. PhysClass::Load(cload); // note, legacy loading here... file must be old.
  155. break;
  156. case RENDEROBJPHYS_CHUNK_DYNAMICPHYS:
  157. DynamicPhysClass::Load(cload);
  158. break;
  159. default:
  160. WWDEBUG_SAY(("Unhandled Chunk: 0x%X File: %s Line: %d\r\n",cload.Cur_Chunk_ID(),__FILE__,__LINE__));
  161. break;
  162. }
  163. cload.Close_Chunk();
  164. }
  165. SaveLoadSystemClass::Register_Post_Load_Callback(this);
  166. return true;
  167. }
  168. void RenderObjPhysClass::On_Post_Load (void)
  169. {
  170. DynamicPhysClass::On_Post_Load();
  171. if (Model) {
  172. Model->Set_User_Data((void*)this);
  173. }
  174. }