vehicledazzle.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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/vehicledazzle.cpp $*
  25. * *
  26. * Original Author:: Greg Hjelstrom *
  27. * *
  28. * $Author:: Greg_h $*
  29. * *
  30. * $Modtime:: 12/02/01 1:33p $*
  31. * *
  32. * $Revision:: 5 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * VehicleDazzleClass::VehicleDazzleClass -- Constructor *
  37. * VehicleDazzleClass::~VehicleDazzleClass -- Destructor *
  38. * VehicleDazzleClass::Set_Model -- sets the dazzle model for this object to control *
  39. * VehicleDazzleClass::Set_Time_Of_Day -- updates any parameters which depend on time of day *
  40. * VehicleDazzleClass::Pre_Render_Update -- Update dazzle state prior to rendering *
  41. * VehicleDazzleClass::Is_Vehicle_Dazzle -- static function for filtering vehicle dazzles *
  42. * VehicleDazzleClass::Determine_Type -- Determine the type of vehicle dazzle this is *
  43. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  44. #include "vehicledazzle.h"
  45. #include "dazzle.h"
  46. #include "ww3d.h"
  47. #include "vehiclephys.h"
  48. #include "physcontrol.h"
  49. /*
  50. ** Dazzle parsing constants
  51. */
  52. const char * HEADLIGHT_NAME_PREFIX = "REN_HEADLIGHT";
  53. const char * BRAKELIGHT_NAME_PREFIX = "REN_BRAKELIGHT";
  54. const char * BLINKLIGHT_NAME_PREFIX = "REN_BLINKLIGHT";
  55. /***********************************************************************************************
  56. * VehicleDazzleClass::VehicleDazzleClass -- Constructor *
  57. * *
  58. * INPUT: *
  59. * *
  60. * OUTPUT: *
  61. * *
  62. * WARNINGS: *
  63. * *
  64. * HISTORY: *
  65. * 7/27/2001 gth : Created. *
  66. *=============================================================================================*/
  67. VehicleDazzleClass::VehicleDazzleClass(void) :
  68. Type(HEADLIGHT_TYPE),
  69. Model(NULL),
  70. BlinkRate(0.0f),
  71. CreationTime(0)
  72. {
  73. }
  74. /***********************************************************************************************
  75. * VehicleDazzleClass::~VehicleDazzleClass -- Destructor *
  76. * *
  77. * INPUT: *
  78. * *
  79. * OUTPUT: *
  80. * *
  81. * WARNINGS: *
  82. * *
  83. * HISTORY: *
  84. * 7/27/2001 gth : Created. *
  85. *=============================================================================================*/
  86. VehicleDazzleClass::~VehicleDazzleClass(void)
  87. {
  88. REF_PTR_RELEASE(Model);
  89. }
  90. /***********************************************************************************************
  91. * VehicleDazzleClass::Set_Model -- sets the dazzle model for this object to control *
  92. * *
  93. * INPUT: *
  94. * *
  95. * OUTPUT: *
  96. * *
  97. * WARNINGS: *
  98. * *
  99. * HISTORY: *
  100. * 7/27/2001 gth : Created. *
  101. *=============================================================================================*/
  102. void VehicleDazzleClass::Set_Model(DazzleRenderObjClass * model)
  103. {
  104. REF_PTR_SET(Model,model);
  105. if (Model != NULL) {
  106. Type = Determine_Type(model);
  107. CreationTime = WW3D::Get_Sync_Time();
  108. }
  109. }
  110. /***********************************************************************************************
  111. * VehicleDazzleClass::Set_Time_Of_Day -- updates any parameters which depend on time of day *
  112. * *
  113. * INPUT: *
  114. * *
  115. * OUTPUT: *
  116. * *
  117. * WARNINGS: *
  118. * *
  119. * HISTORY: *
  120. * 7/27/2001 gth : Created. *
  121. *=============================================================================================*/
  122. void VehicleDazzleClass::Set_Time_Of_Day(float time)
  123. {
  124. }
  125. /***********************************************************************************************
  126. * VehicleDazzleClass::Pre_Render_Update -- Update dazzle state prior to rendering *
  127. * *
  128. * INPUT: *
  129. * *
  130. * OUTPUT: *
  131. * *
  132. * WARNINGS: *
  133. * *
  134. * HISTORY: *
  135. * 7/27/2001 gth : Created. *
  136. *=============================================================================================*/
  137. void VehicleDazzleClass::Pre_Render_Update(VehiclePhysClass * parent)
  138. {
  139. WWASSERT(parent != NULL);
  140. if (Model != NULL) {
  141. switch (Type)
  142. {
  143. case HEADLIGHT_TYPE:
  144. {
  145. /*
  146. ** Turn on the headlights if the engine is on
  147. */
  148. float intensity = (parent->Is_Engine_Enabled() ? 1.0f : 0.0f);
  149. Model->Set_Dazzle_Color(Vector3(intensity,intensity,intensity));
  150. break;
  151. }
  152. case BRAKELIGHT_TYPE:
  153. {
  154. /*
  155. ** Turn on the brakelights if the engine is on
  156. ** Make them bright if the vehicle has forward velocity but the controller is pointing backwards
  157. */
  158. Vector3 velocity;
  159. parent->Get_Velocity(&velocity);
  160. float forward_vel = Vector3::Dot_Product(parent->Get_Transform().Get_X_Vector(),velocity);
  161. bool controller_back = ((parent->Get_Controller() != NULL) && (parent->Get_Controller()->Get_Move_Forward() < 0.0f));
  162. bool is_braking = ((forward_vel > 0.0f) && (controller_back));
  163. float intensity = (parent->Is_Engine_Enabled() ? 1.0f : 0.0f);
  164. intensity *= (is_braking ? 1.0f : 0.25f);
  165. Model->Set_Dazzle_Color(Vector3(intensity,intensity,intensity));
  166. break;
  167. }
  168. case BLINKLIGHT_TYPE:
  169. {
  170. unsigned int elapsed_time = (WW3D::Get_Sync_Time() - CreationTime) & 0x000003FF;
  171. Model->Set_Hidden(elapsed_time > 0x0000001FF);
  172. //Model->Set_Hidden(true);
  173. break;
  174. }
  175. }
  176. }
  177. }
  178. /***********************************************************************************************
  179. * VehicleDazzleClass::Is_Vehicle_Dazzle -- static function for filtering vehicle dazzles *
  180. * *
  181. * INPUT: *
  182. * *
  183. * OUTPUT: *
  184. * *
  185. * WARNINGS: *
  186. * *
  187. * HISTORY: *
  188. * 7/27/2001 gth : Created. *
  189. *=============================================================================================*/
  190. bool VehicleDazzleClass::Is_Vehicle_Dazzle(RenderObjClass * obj)
  191. {
  192. int type = Determine_Type(obj);
  193. return type != NONE;
  194. }
  195. /***********************************************************************************************
  196. * VehicleDazzleClass::Determine_Type -- Determine the type of vehicle dazzle this is *
  197. * *
  198. * INPUT: *
  199. * *
  200. * OUTPUT: *
  201. * *
  202. * WARNINGS: *
  203. * *
  204. * HISTORY: *
  205. * 7/30/2001 gth : Created. *
  206. *=============================================================================================*/
  207. int VehicleDazzleClass::Determine_Type(RenderObjClass * obj)
  208. {
  209. if ((obj != NULL) && (obj->Class_ID() == RenderObjClass::CLASSID_DAZZLE)) {
  210. DazzleRenderObjClass * dazzle = (DazzleRenderObjClass *)obj;
  211. const char * type_name = DazzleRenderObjClass::Get_Type_Name(dazzle->Get_Dazzle_Type());
  212. if (strnicmp(type_name,HEADLIGHT_NAME_PREFIX,strlen(HEADLIGHT_NAME_PREFIX)) == 0) {
  213. return HEADLIGHT_TYPE;
  214. }
  215. if (strnicmp(type_name,BRAKELIGHT_NAME_PREFIX,strlen(BRAKELIGHT_NAME_PREFIX)) == 0) {
  216. return BRAKELIGHT_TYPE;
  217. }
  218. if (strnicmp(type_name,BLINKLIGHT_NAME_PREFIX,strlen(BLINKLIGHT_NAME_PREFIX)) == 0) {
  219. return BLINKLIGHT_TYPE;
  220. }
  221. }
  222. return NONE;
  223. }