pivot.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. ** Command & Conquer Generals(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. /* $Header: /Commando/Code/ww3d2/pivot.cpp 1 1/22/01 3:36p Greg_h $ */
  19. /***********************************************************************************************
  20. *** Confidential - Westwood Studios ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Commando / G 3D Library *
  24. * *
  25. * $Archive:: /Commando/Code/ww3d2/pivot.cpp $*
  26. * *
  27. * Author:: Greg_h *
  28. * *
  29. * $Modtime:: 1/08/01 10:04a $*
  30. * *
  31. * $Revision:: 1 $*
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * PivotClass::PivotClass -- Constructor for PivotClass *
  36. * PivotClass::Compute_Transform -- Update the pivot's transformation matrix *
  37. * PivotClass::Compute_Transform -- Update the pivot's transformation matrix *
  38. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  39. #include "pivot.h"
  40. #include "wwmath.h"
  41. #include <string.h>
  42. /***********************************************************************************************
  43. * PivotClass::PivotClass -- Constructor for PivotClass *
  44. * *
  45. * INPUT: *
  46. * *
  47. * OUTPUT: *
  48. * *
  49. * WARNINGS: *
  50. * *
  51. * HISTORY: *
  52. * 07/24/1997 GH : Created. *
  53. *=============================================================================================*/
  54. PivotClass::PivotClass(void) :
  55. Parent(NULL),
  56. BaseTransform(1),
  57. Transform(1),
  58. #ifdef LAZY_CAP_MTX_ALLOC
  59. CapTransformPtr(NULL),
  60. Index(0),
  61. IsVisible(true),
  62. WorldSpaceTranslation(false)
  63. #else
  64. CapTransform(1),
  65. Index(0),
  66. IsVisible(true),
  67. WorldSpaceTranslation(false),
  68. IsCaptured(false),
  69. Unused(false)
  70. #endif
  71. {
  72. Name[0] = 0;
  73. }
  74. PivotClass::PivotClass(const PivotClass& that) :
  75. Parent(that.Parent),
  76. BaseTransform(that.BaseTransform),
  77. Transform(that.Transform),
  78. #ifdef LAZY_CAP_MTX_ALLOC
  79. CapTransformPtr(NULL),
  80. Index(that.Index),
  81. IsVisible(that.IsVisible),
  82. WorldSpaceTranslation(that.WorldSpaceTranslation)
  83. #else
  84. CapTransform(that.CapTransform),
  85. Index(that.Index),
  86. IsVisible(that.IsVisible),
  87. WorldSpaceTranslation(that.WorldSpaceTranslation),
  88. IsCaptured(that.IsCaptured),
  89. Unused(that.Unused)
  90. #endif
  91. {
  92. memcpy(Name, that.Name, sizeof(Name));
  93. #ifdef LAZY_CAP_MTX_ALLOC
  94. if (that.CapTransformPtr != NULL)
  95. {
  96. CapTransformPtr = MSGW3DNEW("PivotClassCaptureBoneMtx") DynamicMatrix3D;
  97. CapTransformPtr->Mat = that.CapTransformPtr->Mat;
  98. }
  99. #endif
  100. }
  101. PivotClass& PivotClass::operator=(const PivotClass& that)
  102. {
  103. if (this != &that)
  104. {
  105. memcpy(Name, that.Name, sizeof(Name));
  106. Parent = that.Parent;
  107. BaseTransform = that.BaseTransform;
  108. Transform = that.Transform;
  109. #ifdef LAZY_CAP_MTX_ALLOC
  110. CapTransformPtr = NULL;
  111. Index = that.Index;
  112. IsVisible = that.IsVisible;
  113. WorldSpaceTranslation = that.WorldSpaceTranslation;
  114. if (that.CapTransformPtr != NULL)
  115. {
  116. CapTransformPtr = MSGW3DNEW("PivotClassCaptureBoneMtx") DynamicMatrix3D;
  117. CapTransformPtr->Mat = that.CapTransformPtr->Mat;
  118. }
  119. #else
  120. CapTransform = that.CapTransform;
  121. Index = that.Index;
  122. IsVisible = that.IsVisible;
  123. WorldSpaceTranslation = that.WorldSpaceTranslation;
  124. IsCaptured = that.IsCaptured;
  125. Unused = that.Unused;
  126. #endif
  127. }
  128. return *this;
  129. }
  130. void PivotClass::Capture_Update(void)
  131. {
  132. #ifdef LAZY_CAP_MTX_ALLOC
  133. if (!CapTransformPtr)
  134. return;
  135. const Matrix3D* ct = &CapTransformPtr->Mat;
  136. #else
  137. const Matrix3D* ct = &CapTransform;
  138. #endif
  139. if ( WorldSpaceTranslation )
  140. {
  141. // The Translation of CapTransform is meant to be in world space,
  142. // so remove before applying orientation
  143. Matrix3D CapOrientation = *ct;
  144. CapOrientation.Set_Translation( Vector3( 0,0,0 ) );
  145. #ifdef ALLOW_TEMPORARIES
  146. Matrix3D::Multiply(Transform,CapOrientation,&(Transform));
  147. #else
  148. Transform.postMul(CapOrientation);
  149. #endif
  150. // Now apply translation in world space
  151. Transform.Adjust_Translation( ct->Get_Translation() );
  152. }
  153. else
  154. {
  155. #ifdef ALLOW_TEMPORARIES
  156. Matrix3D::Multiply(Transform, *ct, &(Transform));
  157. #else
  158. Transform.postMul(*ct);
  159. #endif
  160. }
  161. }