menubackdrop.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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 : Combat *
  23. * *
  24. * $Archive:: /Commando/Code/wwui/menubackdrop.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 11/21/01 11:30a $*
  29. * *
  30. * $Revision:: 8 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "menubackdrop.h"
  36. #include "scene.h"
  37. #include "camera.h"
  38. #include "ww3d.h"
  39. #include "assetmgr.h"
  40. #include "render2d.h"
  41. #include "light.h"
  42. #include "hanim.h"
  43. ////////////////////////////////////////////////////////////////
  44. //
  45. // MenuBackDropClass
  46. //
  47. ////////////////////////////////////////////////////////////////
  48. MenuBackDropClass::MenuBackDropClass (void) :
  49. Scene (NULL),
  50. Camera (NULL),
  51. Model (NULL),
  52. Anim (NULL),
  53. ClearScreen (true)
  54. {
  55. //
  56. // Create a scene to use for the background
  57. //
  58. Scene = new SimpleSceneClass;
  59. Scene->Set_Ambient_Light (Vector3(1, 1, 1));
  60. //
  61. // Create a single scene light
  62. //
  63. LightClass *light = new LightClass;
  64. if (light != NULL) {
  65. //
  66. // Configure the light
  67. //
  68. light->Set_Position (Vector3 (0, 0, 15000.0F));
  69. light->Set_Intensity (1.0F);
  70. light->Set_Force_Visible(true);
  71. light->Set_Flag (LightClass::NEAR_ATTENUATION, false);
  72. light->Set_Far_Attenuation_Range (1000000, 1000000);
  73. light->Set_Ambient(Vector3 (0,0,0));
  74. light->Set_Diffuse (Vector3 (1.0F, 1.0F, 1.0F));
  75. light->Set_Specular (Vector3 (1.0F, 1.0F, 1.0F));
  76. //
  77. // Add this light to the scene
  78. //
  79. Scene->Add_Render_Object (light);
  80. REF_PTR_RELEASE(light);
  81. }
  82. //
  83. // Create a camera to use in background-scene
  84. //
  85. Camera = new CameraClass();
  86. Camera->Set_Position (Vector3 (0, 0, 800));
  87. //
  88. // Configure the view plane
  89. //
  90. const RectClass &screen_size = Render2DClass::Get_Screen_Resolution ();
  91. float hfov = DEG_TO_RAD(45.0F);
  92. float vfov = (screen_size.Height () / screen_size.Width ()) * hfov;
  93. Camera->Set_View_Plane (hfov, vfov);
  94. //
  95. // Set the clip planes
  96. //
  97. Camera->Set_Clip_Planes (5.0F, 12000.0F);
  98. return ;
  99. }
  100. ////////////////////////////////////////////////////////////////
  101. //
  102. // ~MenuBackDropClass
  103. //
  104. ////////////////////////////////////////////////////////////////
  105. MenuBackDropClass::~MenuBackDropClass (void)
  106. {
  107. Remove_Model();
  108. REF_PTR_RELEASE (Camera);
  109. REF_PTR_RELEASE (Scene);
  110. return ;
  111. }
  112. ////////////////////////////////////////////////////////////////
  113. //
  114. // Render
  115. //
  116. ////////////////////////////////////////////////////////////////
  117. void
  118. MenuBackDropClass::Render (void)
  119. {
  120. //
  121. // Simple render the scene
  122. //
  123. WW3D::Render (Scene, Camera, ClearScreen, ClearScreen);
  124. return ;
  125. }
  126. ////////////////////////////////////////////////////////////////
  127. //
  128. // Set_Model
  129. //
  130. ////////////////////////////////////////////////////////////////
  131. void
  132. MenuBackDropClass::Set_Model (const char *name)
  133. {
  134. // Get rid of the old model.
  135. Remove_Model();
  136. //
  137. // Load the new model
  138. //
  139. Model = WW3DAssetManager::Get_Instance ()->Create_Render_Obj (name);
  140. if (Model != NULL) {
  141. //
  142. // Check to see if this model has a camera bone
  143. //
  144. int camera_bone_index = Model->Get_Bone_Index ("CAMERA");
  145. if (camera_bone_index > 0) {
  146. //
  147. // Convert the bone's transform into a camera transform
  148. //
  149. const Matrix3D &tm = Model->Get_Bone_Transform (camera_bone_index);
  150. Matrix3D cam_tm (Vector3 (0, -1, 0), Vector3 (0, 0, 1), Vector3 (-1, 0, 0), Vector3 (0, 0, 0));
  151. Matrix3D new_tm = tm * cam_tm;
  152. //
  153. // Set the camera's new transform
  154. //
  155. Camera->Set_Transform (new_tm);
  156. }
  157. //
  158. // Add the model to the scene
  159. //
  160. Scene->Add_Render_Object (Model);
  161. }
  162. //
  163. // Update the animation
  164. //
  165. Play_Animation ();
  166. return ;
  167. }
  168. ////////////////////////////////////////////////////////////////
  169. //
  170. // Remove_Model
  171. //
  172. ////////////////////////////////////////////////////////////////
  173. void
  174. MenuBackDropClass::Remove_Model (void)
  175. {
  176. if (Model != NULL) {
  177. Model->Remove();
  178. }
  179. REF_PTR_RELEASE (Model);
  180. REF_PTR_RELEASE (Anim);
  181. }
  182. ////////////////////////////////////////////////////////////////
  183. //
  184. // Set_Animation
  185. //
  186. ////////////////////////////////////////////////////////////////
  187. void
  188. MenuBackDropClass::Set_Animation (const char *anim_name)
  189. {
  190. REF_PTR_RELEASE (Anim);
  191. AnimationName = anim_name;
  192. Play_Animation ();
  193. return ;
  194. }
  195. ////////////////////////////////////////////////////////////////
  196. //
  197. // Set_Animation_Percentage
  198. //
  199. ////////////////////////////////////////////////////////////////
  200. void
  201. MenuBackDropClass::Set_Animation_Percentage (float percent)
  202. {
  203. if ( Model != NULL && Anim != NULL ) {
  204. float frame = (float)(Anim->Get_Num_Frames()-1) * WWMath::Clamp( percent, 0, 1 );
  205. Model->Set_Animation (Anim, frame, RenderObjClass::ANIM_MODE_MANUAL);
  206. }
  207. return ;
  208. }
  209. ////////////////////////////////////////////////////////////////
  210. //
  211. // Play_Animation
  212. //
  213. ////////////////////////////////////////////////////////////////
  214. void
  215. MenuBackDropClass::Play_Animation (void)
  216. {
  217. if (Model == NULL) {
  218. return ;
  219. }
  220. if (AnimationName.Get_Length () > 0) {
  221. //
  222. // Play the animation on the background (if necessary)
  223. //
  224. REF_PTR_RELEASE (Anim);
  225. Anim = WW3DAssetManager::Get_Instance ()->Get_HAnim (AnimationName);
  226. if (Anim != NULL) {
  227. Model->Set_Animation (Anim, 0, RenderObjClass::ANIM_MODE_LOOP);
  228. }
  229. } else {
  230. //
  231. // Stop the animation
  232. //
  233. REF_PTR_RELEASE (Anim);
  234. Model->Set_Animation (NULL);
  235. }
  236. return ;
  237. }