muzzlerecoil.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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/Combat/muzzlerecoil.cpp $*
  25. * *
  26. * Original Author:: Greg Hjelstrom *
  27. * *
  28. * $Author:: Greg_h $*
  29. * *
  30. * $Modtime:: 8/22/00 8:31a $*
  31. * *
  32. * $Revision:: 1 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #include "muzzlerecoil.h"
  38. #include "timemgr.h"
  39. #include "rendobj.h"
  40. #include "wwdebug.h"
  41. MuzzleRecoilClass::MuzzleRecoilClass(void)
  42. {
  43. Init(0);
  44. }
  45. void MuzzleRecoilClass::Init(int bone_index)
  46. {
  47. BoneIndex = bone_index;
  48. RecoilScale = 1.0f;
  49. RecoilTimer = 0.0f;
  50. OORecoilTime = 0.0f;
  51. }
  52. void MuzzleRecoilClass::Start_Recoil(float recoil_scale,float recoil_time)
  53. {
  54. RecoilScale = recoil_scale;
  55. RecoilTimer = recoil_time;
  56. if (RecoilTimer > 0.0f) {
  57. OORecoilTime = 1.0f / RecoilTimer;
  58. }
  59. }
  60. void MuzzleRecoilClass::Update(RenderObjClass * model)
  61. {
  62. WWASSERT(model != NULL);
  63. if ((RecoilTimer <= 0.0f) || (BoneIndex <= 0)) {
  64. return;
  65. }
  66. // Since our timer is active, go ahead and capture the bone
  67. model->Capture_Bone(BoneIndex);
  68. // Apply the recoil effect.
  69. float recoil_scale = RecoilScale * RecoilTimer * OORecoilTime;
  70. Matrix3D recoil_tm(1);
  71. recoil_tm.Translate_X(-recoil_scale);
  72. model->Control_Bone(BoneIndex,recoil_tm);
  73. // Decrement the recoil timer and release the bone if it expires
  74. RecoilTimer -= TimeManager::Get_Frame_Seconds();
  75. if (RecoilTimer <= 0.0f) {
  76. RecoilTimer = 0.0f;
  77. model->Release_Bone(BoneIndex);
  78. }
  79. }