W3DPoliceCarDraw.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: W3DPoliceCarDraw.cpp /////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, May 2001
  25. // Desc: W3DPoliceCarDraw
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include <stdlib.h>
  29. #include "Common/STLTypedefs.h"
  30. #include "Common/Thing.h"
  31. #include "Common/Xfer.h"
  32. #include "GameClient/Drawable.h"
  33. #include "W3DDevice/GameClient/Module/W3DPoliceCarDraw.h"
  34. #include "W3DDevice/GameClient/W3DDisplay.h"
  35. #include "common/RandomValue.h"
  36. #include "WW3D2/HAnim.h"
  37. #include "W3DDevice/GameClient/W3DScene.h"
  38. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////////////////////////
  39. //-------------------------------------------------------------------------------------------------
  40. /** Create a dynamic light for the search light */
  41. //-------------------------------------------------------------------------------------------------
  42. W3DDynamicLight *W3DPoliceCarDraw::createDynamicLight( void )
  43. {
  44. W3DDynamicLight *light = NULL;
  45. // get me a dynamic light from the scene
  46. light = W3DDisplay::m_3DScene->getADynamicLight();
  47. if( light )
  48. {
  49. light->setEnabled( TRUE );
  50. light->Set_Ambient( Vector3( 0.0f, 0.0f, 0.0f ) );
  51. // Use all ambient, and no diffuse. This produces a circle of light on
  52. // even and uneven ground. Diffuse lighting shows up ground unevenness, which looks
  53. // funny on a searchlight. So no diffuse. jba.
  54. light->Set_Diffuse( Vector3( 0.0f, 0.0f, 0.0f ) );
  55. light->Set_Position( Vector3( 0.0f, 0.0f, 0.0f ) );
  56. light->Set_Far_Attenuation_Range( 5, 15 );
  57. } // end if
  58. return light;
  59. } // end createDynamicSearchLight
  60. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////////////////////////
  61. //-------------------------------------------------------------------------------------------------
  62. //-------------------------------------------------------------------------------------------------
  63. W3DPoliceCarDraw::W3DPoliceCarDraw( Thing *thing, const ModuleData* moduleData ) : W3DTruckDraw( thing, moduleData )
  64. {
  65. m_light = NULL;
  66. m_curFrame = GameClientRandomValueReal(0, 10 );
  67. }
  68. //-------------------------------------------------------------------------------------------------
  69. //-------------------------------------------------------------------------------------------------
  70. W3DPoliceCarDraw::~W3DPoliceCarDraw( void )
  71. {
  72. // disable the light ... the scene will re-use it later
  73. if( m_light )
  74. {
  75. // Have it fade out over 5 frames.
  76. m_light->setFrameFade(0, 5);
  77. m_light->setDecayRange();
  78. m_light->setDecayColor();
  79. m_light = NULL;
  80. } // end if
  81. }
  82. //-------------------------------------------------------------------------------------------------
  83. //-------------------------------------------------------------------------------------------------
  84. void W3DPoliceCarDraw::doDrawModule(const Matrix3D* transformMtx)
  85. {
  86. const Real floatAmt = 8.0f;
  87. const Real animAmt = 0.25;
  88. // get pointers to our render objects that we'll need
  89. RenderObjClass* policeCarRenderObj = getRenderObject();
  90. if( policeCarRenderObj == NULL )
  91. return;
  92. HAnimClass *anim = policeCarRenderObj->Peek_Animation();
  93. if (anim)
  94. {
  95. Real frames = anim->Get_Num_Frames();
  96. m_curFrame += animAmt;
  97. if (m_curFrame > frames-1) {
  98. m_curFrame = 0;
  99. }
  100. policeCarRenderObj->Set_Animation(anim, m_curFrame);
  101. }
  102. Real red = 0;
  103. Real green = 0;
  104. Real blue = 0;
  105. if (m_curFrame < 3) {
  106. red = 1; green = 0.5;
  107. } else if (m_curFrame < 6) {
  108. red = 1;
  109. } else if (m_curFrame < 7) {
  110. red = 1; green = 0.5;
  111. } else if (m_curFrame < 9) {
  112. red = 0.5+(9-m_curFrame)/4;
  113. blue = (m_curFrame-5)/6;
  114. } else if (m_curFrame < 12) {
  115. blue=1;
  116. } else if (m_curFrame <= 14) {
  117. green = (m_curFrame-11)/3;
  118. blue = (14-m_curFrame)/2;
  119. red = (m_curFrame-11)/3;
  120. }
  121. // make us a light if we don't already have one
  122. if( m_light == NULL )
  123. m_light = createDynamicLight();
  124. // if we have a search light, position it
  125. if( m_light )
  126. {
  127. Coord3D pos = *getDrawable()->getPosition();
  128. m_light->Set_Diffuse( Vector3( red, green, blue) );
  129. m_light->Set_Ambient( Vector3( red/2, green/2, blue/2) );
  130. m_light->Set_Far_Attenuation_Range( 3, 20 );
  131. m_light->Set_Position( Vector3( pos.x,pos.y,pos.z+floatAmt ) );
  132. }
  133. W3DTruckDraw::doDrawModule(transformMtx);
  134. }
  135. // ------------------------------------------------------------------------------------------------
  136. /** CRC */
  137. // ------------------------------------------------------------------------------------------------
  138. void W3DPoliceCarDraw::crc( Xfer *xfer )
  139. {
  140. // extend base class
  141. W3DTruckDraw::crc( xfer );
  142. } // end crc
  143. // ------------------------------------------------------------------------------------------------
  144. /** Xfer method
  145. * Version Info:
  146. * 1: Initial version */
  147. // ------------------------------------------------------------------------------------------------
  148. void W3DPoliceCarDraw::xfer( Xfer *xfer )
  149. {
  150. // version
  151. XferVersion currentVersion = 1;
  152. XferVersion version = currentVersion;
  153. xfer->xferVersion( &version, currentVersion );
  154. // extend base class
  155. W3DTruckDraw::xfer( xfer );
  156. // John A says there is no data for these to save
  157. } // end xfer
  158. // ------------------------------------------------------------------------------------------------
  159. /** Load post process */
  160. // ------------------------------------------------------------------------------------------------
  161. void W3DPoliceCarDraw::loadPostProcess( void )
  162. {
  163. // extend base class
  164. W3DTruckDraw::loadPostProcess();
  165. } // end loadPostProcess