humanrecoil.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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/humanrecoil.cpp $*
  25. * *
  26. * Original Author:: Greg Hjelstrom *
  27. * *
  28. * $Author:: Byon_g $*
  29. * *
  30. * $Modtime:: 9/12/00 5:24p $*
  31. * *
  32. * $Revision:: 3 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #include "humanrecoil.h"
  38. #include "vector3.h"
  39. #include "wwdebug.h"
  40. #include "rendobj.h"
  41. #include "htree.h"
  42. #include <string.h>
  43. /*
  44. ** Static members of HumanRecoilClass
  45. */
  46. bool HumanRecoilClass::IsInitted = false;
  47. /*
  48. ** Recoil Data
  49. */
  50. struct RecoilDataStruct
  51. {
  52. RecoilDataStruct(const char * name,const Vector3 & translation) :
  53. BoneName(name),
  54. BoneIndex(0),
  55. Translation(translation)
  56. {}
  57. const char * BoneName;
  58. int BoneIndex;
  59. Vector3 Translation;
  60. };
  61. static RecoilDataStruct _RecoilData[] =
  62. {
  63. RecoilDataStruct("C L CLAVICLE",Vector3(-0.025f,0.0f,0.0f)),
  64. RecoilDataStruct("C L UPPERARM",Vector3(-0.025f,0.0f,0.0f)),
  65. RecoilDataStruct("C L FOREARM",Vector3(-0.05f,0.0f,0.0f)),
  66. RecoilDataStruct("C L HAND",Vector3(-0.05f,0.0f,0.0f)),
  67. RecoilDataStruct("C R CLAVICLE",Vector3(-0.05f,0.0f,0.0f)),
  68. RecoilDataStruct("C R UPPERARM",Vector3(-0.05f,0.0f,0.0f)),
  69. RecoilDataStruct("C R FOREARM",Vector3(-0.1f,0.0f,0.0f)),
  70. RecoilDataStruct("C R HAND",Vector3(-0.1f,0.0f,0.0f)),
  71. RecoilDataStruct("BACKGUNBONE",Vector3(-0.075f,0.0f,0.0f)),
  72. };
  73. const int _RECOIL_BONE_COUNT = sizeof(_RecoilData) / sizeof(RecoilDataStruct);
  74. /***********************************************************************************************
  75. **
  76. ** HumanRecoilClass Implementation
  77. **
  78. ***********************************************************************************************/
  79. HumanRecoilClass::HumanRecoilClass(void)
  80. {
  81. }
  82. void HumanRecoilClass::Capture_Bones(RenderObjClass * model)
  83. {
  84. WWASSERT(model != NULL);
  85. if (IsInitted == false) {
  86. Initialize(model);
  87. }
  88. for (int recoil_bone = 0; recoil_bone < _RECOIL_BONE_COUNT; recoil_bone++) {
  89. model->Capture_Bone(_RecoilData[recoil_bone].BoneIndex);
  90. }
  91. }
  92. void HumanRecoilClass::Apply_Recoil(const Matrix3D & recoil_tm,RenderObjClass * model,float scale)
  93. {
  94. WWASSERT(model != NULL);
  95. if (IsInitted == false) {
  96. Initialize(model);
  97. }
  98. Vector3 recoil_offset;
  99. for (int recoil_bone = 0; recoil_bone < _RECOIL_BONE_COUNT; recoil_bone++) {
  100. // for each bone to recoil, compute the translation and plug it in
  101. Matrix3D::Transform_Vector(recoil_tm,scale * _RecoilData[recoil_bone].Translation,&recoil_offset);
  102. Matrix3D tm(recoil_offset);
  103. model->Control_Bone(_RecoilData[recoil_bone].BoneIndex,tm,true);
  104. }
  105. }
  106. void HumanRecoilClass::Release_Bones(RenderObjClass * model)
  107. {
  108. WWASSERT(model != NULL);
  109. if (IsInitted == false) {
  110. Initialize(model);
  111. }
  112. for (int recoil_bone = 0; recoil_bone < _RECOIL_BONE_COUNT; recoil_bone++) {
  113. model->Release_Bone(_RecoilData[recoil_bone].BoneIndex);
  114. }
  115. }
  116. void HumanRecoilClass::Initialize(RenderObjClass * model)
  117. {
  118. const HTreeClass * tree = model->Get_HTree();
  119. for (int recoil_bone = 0; recoil_bone < _RECOIL_BONE_COUNT; recoil_bone++) {
  120. for (int model_bone = 0; model_bone < tree->Num_Pivots(); model_bone++) {
  121. if (stricmp(_RecoilData[recoil_bone].BoneName, tree->Get_Bone_Name(model_bone)) == 0) {
  122. _RecoilData[recoil_bone].BoneIndex = model_bone;
  123. model_bone = tree->Num_Pivots();
  124. }
  125. }
  126. }
  127. IsInitted = true;
  128. }