JointTransform.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code 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. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __JOINTTRANSFORM_H__
  21. #define __JOINTTRANSFORM_H__
  22. /*
  23. ===============================================================================
  24. Joint Quaternion
  25. ===============================================================================
  26. */
  27. class idJointQuat {
  28. public:
  29. const float * ToFloatPtr() const { return q.ToFloatPtr(); }
  30. float * ToFloatPtr() { return q.ToFloatPtr(); }
  31. idQuat q;
  32. idVec3 t;
  33. float w;
  34. };
  35. // offsets for SIMD code
  36. #define JOINTQUAT_SIZE (8*4) // sizeof( idJointQuat )
  37. #define JOINTQUAT_SIZE_SHIFT 5 // log2( sizeof( idJointQuat ) )
  38. #define JOINTQUAT_Q_OFFSET (0*4) // offsetof( idJointQuat, q )
  39. #define JOINTQUAT_T_OFFSET (4*4) // offsetof( idJointQuat, t )
  40. assert_sizeof( idJointQuat, JOINTQUAT_SIZE );
  41. assert_sizeof( idJointQuat, (1<<JOINTQUAT_SIZE_SHIFT) );
  42. assert_offsetof( idJointQuat, q, JOINTQUAT_Q_OFFSET );
  43. assert_offsetof( idJointQuat, t, JOINTQUAT_T_OFFSET );
  44. /*
  45. ===============================================================================
  46. Joint Matrix
  47. ===============================================================================
  48. */
  49. /*
  50. ================================================
  51. idJointMat has the following structure:
  52. idMat3 m;
  53. idVec3 t;
  54. m[0][0], m[1][0], m[2][0], t[0]
  55. m[0][1], m[1][1], m[2][1], t[1]
  56. m[0][2], m[1][2], m[2][2], t[2]
  57. ================================================
  58. */
  59. class idJointMat {
  60. public:
  61. void SetRotation( const idMat3 &m );
  62. idMat3 GetRotation() const;
  63. void SetTranslation( const idVec3 &t );
  64. idVec3 GetTranslation() const;
  65. idVec3 operator*( const idVec3 &v ) const; // only rotate
  66. idVec3 operator*( const idVec4 &v ) const; // rotate and translate
  67. idJointMat & operator*=( const idJointMat &a ); // transform
  68. idJointMat & operator/=( const idJointMat &a ); // untransform
  69. bool Compare( const idJointMat &a ) const; // exact compare, no epsilon
  70. bool Compare( const idJointMat &a, const float epsilon ) const; // compare with epsilon
  71. bool operator==( const idJointMat &a ) const; // exact compare, no epsilon
  72. bool operator!=( const idJointMat &a ) const; // exact compare, no epsilon
  73. void Identity();
  74. void Invert();
  75. void FromMat4( const idMat4 & m );
  76. idMat3 ToMat3() const;
  77. idMat4 ToMat4() const;
  78. idVec3 ToVec3() const;
  79. const float * ToFloatPtr() const { return mat; }
  80. float * ToFloatPtr() { return mat; }
  81. idJointQuat ToJointQuat() const;
  82. void Transform( idVec3 &result, const idVec3 &v ) const;
  83. void Rotate( idVec3 &result, const idVec3 &v ) const;
  84. static void Mul( idJointMat &result, const idJointMat &mat, const float s );
  85. static void Mad( idJointMat &result, const idJointMat &mat, const float s );
  86. static void Multiply( idJointMat &result, const idJointMat &m1, const idJointMat &m2 );
  87. static void InverseMultiply( idJointMat &result, const idJointMat &m1, const idJointMat &m2 );
  88. float mat[3*4];
  89. };
  90. // offsets for SIMD code
  91. #define JOINTMAT_SIZE (4*3*4) // sizeof( idJointMat )
  92. assert_sizeof( idJointMat, JOINTMAT_SIZE );
  93. #define JOINTMAT_TYPESIZE ( 4 * 3 )
  94. /*
  95. ========================
  96. idJointMat::SetRotation
  97. ========================
  98. */
  99. ID_INLINE void idJointMat::SetRotation( const idMat3 &m ) {
  100. // NOTE: idMat3 is transposed because it is column-major
  101. mat[0 * 4 + 0] = m[0][0];
  102. mat[0 * 4 + 1] = m[1][0];
  103. mat[0 * 4 + 2] = m[2][0];
  104. mat[1 * 4 + 0] = m[0][1];
  105. mat[1 * 4 + 1] = m[1][1];
  106. mat[1 * 4 + 2] = m[2][1];
  107. mat[2 * 4 + 0] = m[0][2];
  108. mat[2 * 4 + 1] = m[1][2];
  109. mat[2 * 4 + 2] = m[2][2];
  110. }
  111. /*
  112. ========================
  113. idJointMat::GetRotation
  114. ========================
  115. */
  116. ID_INLINE idMat3 idJointMat::GetRotation() const {
  117. idMat3 m;
  118. m[0][0] = mat[0 * 4 + 0];
  119. m[1][0] = mat[0 * 4 + 1];
  120. m[2][0] = mat[0 * 4 + 2];
  121. m[0][1] = mat[1 * 4 + 0];
  122. m[1][1] = mat[1 * 4 + 1];
  123. m[2][1] = mat[1 * 4 + 2];
  124. m[0][2] = mat[2 * 4 + 0];
  125. m[1][2] = mat[2 * 4 + 1];
  126. m[2][2] = mat[2 * 4 + 2];
  127. return m;
  128. }
  129. /*
  130. ========================
  131. idJointMat::SetTranslation
  132. ========================
  133. */
  134. ID_INLINE void idJointMat::SetTranslation( const idVec3 &t ) {
  135. mat[0 * 4 + 3] = t[0];
  136. mat[1 * 4 + 3] = t[1];
  137. mat[2 * 4 + 3] = t[2];
  138. }
  139. /*
  140. ========================
  141. idJointMat::GetTranslation
  142. ========================
  143. */
  144. ID_INLINE idVec3 idJointMat::GetTranslation() const {
  145. idVec3 t;
  146. t[0] = mat[0 * 4 + 3];
  147. t[1] = mat[1 * 4 + 3];
  148. t[2] = mat[2 * 4 + 3];
  149. return t;
  150. }
  151. /*
  152. ========================
  153. idJointMat::operator*
  154. ========================
  155. */
  156. ID_INLINE idVec3 idJointMat::operator*( const idVec3 &v ) const {
  157. return idVec3( mat[0 * 4 + 0] * v[0] + mat[0 * 4 + 1] * v[1] + mat[0 * 4 + 2] * v[2],
  158. mat[1 * 4 + 0] * v[0] + mat[1 * 4 + 1] * v[1] + mat[1 * 4 + 2] * v[2],
  159. mat[2 * 4 + 0] * v[0] + mat[2 * 4 + 1] * v[1] + mat[2 * 4 + 2] * v[2] );
  160. }
  161. ID_INLINE idVec3 idJointMat::operator*( const idVec4 &v ) const {
  162. return idVec3( mat[0 * 4 + 0] * v[0] + mat[0 * 4 + 1] * v[1] + mat[0 * 4 + 2] * v[2] + mat[0 * 4 + 3] * v[3],
  163. mat[1 * 4 + 0] * v[0] + mat[1 * 4 + 1] * v[1] + mat[1 * 4 + 2] * v[2] + mat[1 * 4 + 3] * v[3],
  164. mat[2 * 4 + 0] * v[0] + mat[2 * 4 + 1] * v[1] + mat[2 * 4 + 2] * v[2] + mat[2 * 4 + 3] * v[3] );
  165. }
  166. /*
  167. ========================
  168. idJointMat::operator*=
  169. ========================
  170. */
  171. ID_INLINE idJointMat & idJointMat::operator*=( const idJointMat &a ) {
  172. float tmp[3];
  173. tmp[0] = mat[0 * 4 + 0] * a.mat[0 * 4 + 0] + mat[1 * 4 + 0] * a.mat[0 * 4 + 1] + mat[2 * 4 + 0] * a.mat[0 * 4 + 2];
  174. tmp[1] = mat[0 * 4 + 0] * a.mat[1 * 4 + 0] + mat[1 * 4 + 0] * a.mat[1 * 4 + 1] + mat[2 * 4 + 0] * a.mat[1 * 4 + 2];
  175. tmp[2] = mat[0 * 4 + 0] * a.mat[2 * 4 + 0] + mat[1 * 4 + 0] * a.mat[2 * 4 + 1] + mat[2 * 4 + 0] * a.mat[2 * 4 + 2];
  176. mat[0 * 4 + 0] = tmp[0];
  177. mat[1 * 4 + 0] = tmp[1];
  178. mat[2 * 4 + 0] = tmp[2];
  179. tmp[0] = mat[0 * 4 + 1] * a.mat[0 * 4 + 0] + mat[1 * 4 + 1] * a.mat[0 * 4 + 1] + mat[2 * 4 + 1] * a.mat[0 * 4 + 2];
  180. tmp[1] = mat[0 * 4 + 1] * a.mat[1 * 4 + 0] + mat[1 * 4 + 1] * a.mat[1 * 4 + 1] + mat[2 * 4 + 1] * a.mat[1 * 4 + 2];
  181. tmp[2] = mat[0 * 4 + 1] * a.mat[2 * 4 + 0] + mat[1 * 4 + 1] * a.mat[2 * 4 + 1] + mat[2 * 4 + 1] * a.mat[2 * 4 + 2];
  182. mat[0 * 4 + 1] = tmp[0];
  183. mat[1 * 4 + 1] = tmp[1];
  184. mat[2 * 4 + 1] = tmp[2];
  185. tmp[0] = mat[0 * 4 + 2] * a.mat[0 * 4 + 0] + mat[1 * 4 + 2] * a.mat[0 * 4 + 1] + mat[2 * 4 + 2] * a.mat[0 * 4 + 2];
  186. tmp[1] = mat[0 * 4 + 2] * a.mat[1 * 4 + 0] + mat[1 * 4 + 2] * a.mat[1 * 4 + 1] + mat[2 * 4 + 2] * a.mat[1 * 4 + 2];
  187. tmp[2] = mat[0 * 4 + 2] * a.mat[2 * 4 + 0] + mat[1 * 4 + 2] * a.mat[2 * 4 + 1] + mat[2 * 4 + 2] * a.mat[2 * 4 + 2];
  188. mat[0 * 4 + 2] = tmp[0];
  189. mat[1 * 4 + 2] = tmp[1];
  190. mat[2 * 4 + 2] = tmp[2];
  191. tmp[0] = mat[0 * 4 + 3] * a.mat[0 * 4 + 0] + mat[1 * 4 + 3] * a.mat[0 * 4 + 1] + mat[2 * 4 + 3] * a.mat[0 * 4 + 2];
  192. tmp[1] = mat[0 * 4 + 3] * a.mat[1 * 4 + 0] + mat[1 * 4 + 3] * a.mat[1 * 4 + 1] + mat[2 * 4 + 3] * a.mat[1 * 4 + 2];
  193. tmp[2] = mat[0 * 4 + 3] * a.mat[2 * 4 + 0] + mat[1 * 4 + 3] * a.mat[2 * 4 + 1] + mat[2 * 4 + 3] * a.mat[2 * 4 + 2];
  194. mat[0 * 4 + 3] = tmp[0];
  195. mat[1 * 4 + 3] = tmp[1];
  196. mat[2 * 4 + 3] = tmp[2];
  197. mat[0 * 4 + 3] += a.mat[0 * 4 + 3];
  198. mat[1 * 4 + 3] += a.mat[1 * 4 + 3];
  199. mat[2 * 4 + 3] += a.mat[2 * 4 + 3];
  200. return *this;
  201. }
  202. /*
  203. ========================
  204. idJointMat::operator/=
  205. ========================
  206. */
  207. ID_INLINE idJointMat &idJointMat::operator/=( const idJointMat &a ) {
  208. float tmp[3];
  209. mat[0 * 4 + 3] -= a.mat[0 * 4 + 3];
  210. mat[1 * 4 + 3] -= a.mat[1 * 4 + 3];
  211. mat[2 * 4 + 3] -= a.mat[2 * 4 + 3];
  212. tmp[0] = mat[0 * 4 + 0] * a.mat[0 * 4 + 0] + mat[1 * 4 + 0] * a.mat[1 * 4 + 0] + mat[2 * 4 + 0] * a.mat[2 * 4 + 0];
  213. tmp[1] = mat[0 * 4 + 0] * a.mat[0 * 4 + 1] + mat[1 * 4 + 0] * a.mat[1 * 4 + 1] + mat[2 * 4 + 0] * a.mat[2 * 4 + 1];
  214. tmp[2] = mat[0 * 4 + 0] * a.mat[0 * 4 + 2] + mat[1 * 4 + 0] * a.mat[1 * 4 + 2] + mat[2 * 4 + 0] * a.mat[2 * 4 + 2];
  215. mat[0 * 4 + 0] = tmp[0];
  216. mat[1 * 4 + 0] = tmp[1];
  217. mat[2 * 4 + 0] = tmp[2];
  218. tmp[0] = mat[0 * 4 + 1] * a.mat[0 * 4 + 0] + mat[1 * 4 + 1] * a.mat[1 * 4 + 0] + mat[2 * 4 + 1] * a.mat[2 * 4 + 0];
  219. tmp[1] = mat[0 * 4 + 1] * a.mat[0 * 4 + 1] + mat[1 * 4 + 1] * a.mat[1 * 4 + 1] + mat[2 * 4 + 1] * a.mat[2 * 4 + 1];
  220. tmp[2] = mat[0 * 4 + 1] * a.mat[0 * 4 + 2] + mat[1 * 4 + 1] * a.mat[1 * 4 + 2] + mat[2 * 4 + 1] * a.mat[2 * 4 + 2];
  221. mat[0 * 4 + 1] = tmp[0];
  222. mat[1 * 4 + 1] = tmp[1];
  223. mat[2 * 4 + 1] = tmp[2];
  224. tmp[0] = mat[0 * 4 + 2] * a.mat[0 * 4 + 0] + mat[1 * 4 + 2] * a.mat[1 * 4 + 0] + mat[2 * 4 + 2] * a.mat[2 * 4 + 0];
  225. tmp[1] = mat[0 * 4 + 2] * a.mat[0 * 4 + 1] + mat[1 * 4 + 2] * a.mat[1 * 4 + 1] + mat[2 * 4 + 2] * a.mat[2 * 4 + 1];
  226. tmp[2] = mat[0 * 4 + 2] * a.mat[0 * 4 + 2] + mat[1 * 4 + 2] * a.mat[1 * 4 + 2] + mat[2 * 4 + 2] * a.mat[2 * 4 + 2];
  227. mat[0 * 4 + 2] = tmp[0];
  228. mat[1 * 4 + 2] = tmp[1];
  229. mat[2 * 4 + 2] = tmp[2];
  230. tmp[0] = mat[0 * 4 + 3] * a.mat[0 * 4 + 0] + mat[1 * 4 + 3] * a.mat[1 * 4 + 0] + mat[2 * 4 + 3] * a.mat[2 * 4 + 0];
  231. tmp[1] = mat[0 * 4 + 3] * a.mat[0 * 4 + 1] + mat[1 * 4 + 3] * a.mat[1 * 4 + 1] + mat[2 * 4 + 3] * a.mat[2 * 4 + 1];
  232. tmp[2] = mat[0 * 4 + 3] * a.mat[0 * 4 + 2] + mat[1 * 4 + 3] * a.mat[1 * 4 + 2] + mat[2 * 4 + 3] * a.mat[2 * 4 + 2];
  233. mat[0 * 4 + 3] = tmp[0];
  234. mat[1 * 4 + 3] = tmp[1];
  235. mat[2 * 4 + 3] = tmp[2];
  236. return *this;
  237. }
  238. /*
  239. ========================
  240. idJointMat::Compare
  241. ========================
  242. */
  243. ID_INLINE bool idJointMat::Compare( const idJointMat &a ) const {
  244. int i;
  245. for ( i = 0; i < 12; i++ ) {
  246. if ( mat[i] != a.mat[i] ) {
  247. return false;
  248. }
  249. }
  250. return true;
  251. }
  252. /*
  253. ========================
  254. idJointMat::Compare
  255. ========================
  256. */
  257. ID_INLINE bool idJointMat::Compare( const idJointMat &a, const float epsilon ) const {
  258. int i;
  259. for ( i = 0; i < 12; i++ ) {
  260. if ( idMath::Fabs( mat[i] - a.mat[i] ) > epsilon ) {
  261. return false;
  262. }
  263. }
  264. return true;
  265. }
  266. /*
  267. ========================
  268. idJointMat::operator==
  269. ========================
  270. */
  271. ID_INLINE bool idJointMat::operator==( const idJointMat &a ) const {
  272. return Compare( a );
  273. }
  274. /*
  275. ========================
  276. idJointMat::operator!=
  277. ========================
  278. */
  279. ID_INLINE bool idJointMat::operator!=( const idJointMat &a ) const {
  280. return !Compare( a );
  281. }
  282. /*
  283. ========================
  284. idJointMat::Identity
  285. ========================
  286. */
  287. ID_INLINE void idJointMat::Identity() {
  288. mat[0 * 4 + 0] = 1.0f; mat[0 * 4 + 1] = 0.0f; mat[0 * 4 + 2] = 0.0f; mat[0 * 4 + 3] = 0.0f;
  289. mat[1 * 4 + 0] = 0.0f; mat[1 * 4 + 1] = 1.0f; mat[1 * 4 + 2] = 0.0f; mat[1 * 4 + 3] = 0.0f;
  290. mat[2 * 4 + 0] = 0.0f; mat[2 * 4 + 1] = 0.0f; mat[2 * 4 + 2] = 1.0f; mat[2 * 4 + 3] = 0.0f;
  291. }
  292. /*
  293. ========================
  294. idJointMat::Invert
  295. ========================
  296. */
  297. ID_INLINE void idJointMat::Invert() {
  298. float tmp[3];
  299. // negate inverse rotated translation part
  300. tmp[0] = mat[0 * 4 + 0] * mat[0 * 4 + 3] + mat[1 * 4 + 0] * mat[1 * 4 + 3] + mat[2 * 4 + 0] * mat[2 * 4 + 3];
  301. tmp[1] = mat[0 * 4 + 1] * mat[0 * 4 + 3] + mat[1 * 4 + 1] * mat[1 * 4 + 3] + mat[2 * 4 + 1] * mat[2 * 4 + 3];
  302. tmp[2] = mat[0 * 4 + 2] * mat[0 * 4 + 3] + mat[1 * 4 + 2] * mat[1 * 4 + 3] + mat[2 * 4 + 2] * mat[2 * 4 + 3];
  303. mat[0 * 4 + 3] = -tmp[0];
  304. mat[1 * 4 + 3] = -tmp[1];
  305. mat[2 * 4 + 3] = -tmp[2];
  306. // transpose rotation part
  307. tmp[0] = mat[0 * 4 + 1];
  308. mat[0 * 4 + 1] = mat[1 * 4 + 0];
  309. mat[1 * 4 + 0] = tmp[0];
  310. tmp[1] = mat[0 * 4 + 2];
  311. mat[0 * 4 + 2] = mat[2 * 4 + 0];
  312. mat[2 * 4 + 0] = tmp[1];
  313. tmp[2] = mat[1 * 4 + 2];
  314. mat[1 * 4 + 2] = mat[2 * 4 + 1];
  315. mat[2 * 4 + 1] = tmp[2];
  316. }
  317. /*
  318. ========================
  319. idJointMat::ToMat3
  320. ========================
  321. */
  322. ID_INLINE idMat3 idJointMat::ToMat3() const {
  323. return idMat3( mat[0 * 4 + 0], mat[1 * 4 + 0], mat[2 * 4 + 0],
  324. mat[0 * 4 + 1], mat[1 * 4 + 1], mat[2 * 4 + 1],
  325. mat[0 * 4 + 2], mat[1 * 4 + 2], mat[2 * 4 + 2] );
  326. }
  327. /*
  328. ========================
  329. idJointMat::ToMat4
  330. ========================
  331. */
  332. ID_INLINE idMat4 idJointMat::ToMat4() const {
  333. return idMat4(
  334. mat[0 * 4 + 0], mat[0 * 4 + 1], mat[0 * 4 + 2], mat[0 * 4 + 3],
  335. mat[1 * 4 + 0], mat[1 * 4 + 1], mat[1 * 4 + 2], mat[1 * 4 + 3],
  336. mat[2 * 4 + 0], mat[2 * 4 + 1], mat[2 * 4 + 2], mat[2 * 4 + 3],
  337. 0.0f, 0.0f, 0.0f, 1.0f
  338. );
  339. }
  340. /*
  341. ========================
  342. idJointMat::FromMat4
  343. ========================
  344. */
  345. ID_INLINE void idJointMat::FromMat4( const idMat4 & m ) {
  346. mat[0*4+0] = m[0][0], mat[0*4+1] = m[0][1], mat[0*4+2] = m[0][2], mat[0*4+3] = m[0][3];
  347. mat[1*4+0] = m[1][0], mat[1*4+1] = m[1][1], mat[1*4+2] = m[1][2], mat[1*4+3] = m[1][3];
  348. mat[2*4+0] = m[2][0], mat[2*4+1] = m[2][1], mat[2*4+2] = m[2][2], mat[2*4+3] = m[2][3];
  349. assert( m[3][0] == 0.0f );
  350. assert( m[3][1] == 0.0f );
  351. assert( m[3][2] == 0.0f );
  352. assert( m[3][3] == 1.0f );
  353. }
  354. /*
  355. ========================
  356. idJointMat::ToVec3
  357. ========================
  358. */
  359. ID_INLINE idVec3 idJointMat::ToVec3() const {
  360. return idVec3( mat[0 * 4 + 3], mat[1 * 4 + 3], mat[2 * 4 + 3] );
  361. }
  362. /*
  363. ========================
  364. idJointMat::Transform
  365. ========================
  366. */
  367. ID_INLINE void idJointMat::Transform( idVec3 &result, const idVec3 &v ) const {
  368. result.x = mat[0 * 4 + 0] * v.x + mat[0 * 4 + 1] * v.y + mat[0 * 4 + 2] * v.z + mat[0 * 4 + 3];
  369. result.y = mat[1 * 4 + 0] * v.x + mat[1 * 4 + 1] * v.y + mat[1 * 4 + 2] * v.z + mat[1 * 4 + 3];
  370. result.z = mat[2 * 4 + 0] * v.x + mat[2 * 4 + 1] * v.y + mat[2 * 4 + 2] * v.z + mat[2 * 4 + 3];
  371. }
  372. /*
  373. ========================
  374. idJointMat::Rotate
  375. ========================
  376. */
  377. ID_INLINE void idJointMat::Rotate( idVec3 &result, const idVec3 &v ) const {
  378. result.x = mat[0 * 4 + 0] * v.x + mat[0 * 4 + 1] * v.y + mat[0 * 4 + 2] * v.z;
  379. result.y = mat[1 * 4 + 0] * v.x + mat[1 * 4 + 1] * v.y + mat[1 * 4 + 2] * v.z;
  380. result.z = mat[2 * 4 + 0] * v.x + mat[2 * 4 + 1] * v.y + mat[2 * 4 + 2] * v.z;
  381. }
  382. /*
  383. ========================
  384. idJointMat::Mul
  385. ========================
  386. */
  387. ID_INLINE void idJointMat::Mul( idJointMat &result, const idJointMat &mat, const float s ) {
  388. result.mat[0 * 4 + 0] = s * mat.mat[0 * 4 + 0];
  389. result.mat[0 * 4 + 1] = s * mat.mat[0 * 4 + 1];
  390. result.mat[0 * 4 + 2] = s * mat.mat[0 * 4 + 2];
  391. result.mat[0 * 4 + 3] = s * mat.mat[0 * 4 + 3];
  392. result.mat[1 * 4 + 0] = s * mat.mat[1 * 4 + 0];
  393. result.mat[1 * 4 + 1] = s * mat.mat[1 * 4 + 1];
  394. result.mat[1 * 4 + 2] = s * mat.mat[1 * 4 + 2];
  395. result.mat[1 * 4 + 3] = s * mat.mat[1 * 4 + 3];
  396. result.mat[2 * 4 + 0] = s * mat.mat[2 * 4 + 0];
  397. result.mat[2 * 4 + 1] = s * mat.mat[2 * 4 + 1];
  398. result.mat[2 * 4 + 2] = s * mat.mat[2 * 4 + 2];
  399. result.mat[2 * 4 + 3] = s * mat.mat[2 * 4 + 3];
  400. }
  401. /*
  402. ========================
  403. idJointMat::Mad
  404. ========================
  405. */
  406. ID_INLINE void idJointMat::Mad( idJointMat &result, const idJointMat &mat, const float s ) {
  407. result.mat[0 * 4 + 0] += s * mat.mat[0 * 4 + 0];
  408. result.mat[0 * 4 + 1] += s * mat.mat[0 * 4 + 1];
  409. result.mat[0 * 4 + 2] += s * mat.mat[0 * 4 + 2];
  410. result.mat[0 * 4 + 3] += s * mat.mat[0 * 4 + 3];
  411. result.mat[1 * 4 + 0] += s * mat.mat[1 * 4 + 0];
  412. result.mat[1 * 4 + 1] += s * mat.mat[1 * 4 + 1];
  413. result.mat[1 * 4 + 2] += s * mat.mat[1 * 4 + 2];
  414. result.mat[1 * 4 + 3] += s * mat.mat[1 * 4 + 3];
  415. result.mat[2 * 4 + 0] += s * mat.mat[2 * 4 + 0];
  416. result.mat[2 * 4 + 1] += s * mat.mat[2 * 4 + 1];
  417. result.mat[2 * 4 + 2] += s * mat.mat[2 * 4 + 2];
  418. result.mat[2 * 4 + 3] += s * mat.mat[2 * 4 + 3];
  419. }
  420. /*
  421. ========================
  422. idJointMat::Multiply
  423. ========================
  424. */
  425. ID_INLINE void idJointMat::Multiply( idJointMat &result, const idJointMat &m1, const idJointMat &m2 ) {
  426. result.mat[0 * 4 + 0] = m1.mat[0 * 4 + 0] * m2.mat[0 * 4 + 0] + m1.mat[0 * 4 + 1] * m2.mat[1 * 4 + 0] + m1.mat[0 * 4 + 2] * m2.mat[2 * 4 + 0];
  427. result.mat[0 * 4 + 1] = m1.mat[0 * 4 + 0] * m2.mat[0 * 4 + 1] + m1.mat[0 * 4 + 1] * m2.mat[1 * 4 + 1] + m1.mat[0 * 4 + 2] * m2.mat[2 * 4 + 1];
  428. result.mat[0 * 4 + 2] = m1.mat[0 * 4 + 0] * m2.mat[0 * 4 + 2] + m1.mat[0 * 4 + 1] * m2.mat[1 * 4 + 2] + m1.mat[0 * 4 + 2] * m2.mat[2 * 4 + 2];
  429. result.mat[0 * 4 + 3] = m1.mat[0 * 4 + 0] * m2.mat[0 * 4 + 3] + m1.mat[0 * 4 + 1] * m2.mat[1 * 4 + 3] + m1.mat[0 * 4 + 2] * m2.mat[2 * 4 + 3] + m1.mat[0 * 4 + 3];
  430. result.mat[1 * 4 + 0] = m1.mat[1 * 4 + 0] * m2.mat[0 * 4 + 0] + m1.mat[1 * 4 + 1] * m2.mat[1 * 4 + 0] + m1.mat[1 * 4 + 2] * m2.mat[2 * 4 + 0];
  431. result.mat[1 * 4 + 1] = m1.mat[1 * 4 + 0] * m2.mat[0 * 4 + 1] + m1.mat[1 * 4 + 1] * m2.mat[1 * 4 + 1] + m1.mat[1 * 4 + 2] * m2.mat[2 * 4 + 1];
  432. result.mat[1 * 4 + 2] = m1.mat[1 * 4 + 0] * m2.mat[0 * 4 + 2] + m1.mat[1 * 4 + 1] * m2.mat[1 * 4 + 2] + m1.mat[1 * 4 + 2] * m2.mat[2 * 4 + 2];
  433. result.mat[1 * 4 + 3] = m1.mat[1 * 4 + 0] * m2.mat[0 * 4 + 3] + m1.mat[1 * 4 + 1] * m2.mat[1 * 4 + 3] + m1.mat[1 * 4 + 2] * m2.mat[2 * 4 + 3] + m1.mat[1 * 4 + 3];
  434. result.mat[2 * 4 + 0] = m1.mat[2 * 4 + 0] * m2.mat[0 * 4 + 0] + m1.mat[2 * 4 + 1] * m2.mat[1 * 4 + 0] + m1.mat[2 * 4 + 2] * m2.mat[2 * 4 + 0];
  435. result.mat[2 * 4 + 1] = m1.mat[2 * 4 + 0] * m2.mat[0 * 4 + 1] + m1.mat[2 * 4 + 1] * m2.mat[1 * 4 + 1] + m1.mat[2 * 4 + 2] * m2.mat[2 * 4 + 1];
  436. result.mat[2 * 4 + 2] = m1.mat[2 * 4 + 0] * m2.mat[0 * 4 + 2] + m1.mat[2 * 4 + 1] * m2.mat[1 * 4 + 2] + m1.mat[2 * 4 + 2] * m2.mat[2 * 4 + 2];
  437. result.mat[2 * 4 + 3] = m1.mat[2 * 4 + 0] * m2.mat[0 * 4 + 3] + m1.mat[2 * 4 + 1] * m2.mat[1 * 4 + 3] + m1.mat[2 * 4 + 2] * m2.mat[2 * 4 + 3] + m1.mat[2 * 4 + 3];
  438. }
  439. /*
  440. ========================
  441. idJointMat::InverseMultiply
  442. ========================
  443. */
  444. ID_INLINE void idJointMat::InverseMultiply( idJointMat &result, const idJointMat &m1, const idJointMat &m2 ) {
  445. float dst[3];
  446. result.mat[0 * 4 + 0] = m1.mat[0 * 4 + 0] * m2.mat[0 * 4 + 0] + m1.mat[0 * 4 + 1] * m2.mat[0 * 4 + 1] + m1.mat[0 * 4 + 2] * m2.mat[0 * 4 + 2];
  447. result.mat[0 * 4 + 1] = m1.mat[0 * 4 + 0] * m2.mat[1 * 4 + 0] + m1.mat[0 * 4 + 1] * m2.mat[1 * 4 + 1] + m1.mat[0 * 4 + 2] * m2.mat[1 * 4 + 2];
  448. result.mat[0 * 4 + 2] = m1.mat[0 * 4 + 0] * m2.mat[2 * 4 + 0] + m1.mat[0 * 4 + 1] * m2.mat[2 * 4 + 1] + m1.mat[0 * 4 + 2] * m2.mat[2 * 4 + 2];
  449. result.mat[1 * 4 + 0] = m1.mat[1 * 4 + 0] * m2.mat[0 * 4 + 0] + m1.mat[1 * 4 + 1] * m2.mat[0 * 4 + 1] + m1.mat[1 * 4 + 2] * m2.mat[0 * 4 + 2];
  450. result.mat[1 * 4 + 1] = m1.mat[1 * 4 + 0] * m2.mat[1 * 4 + 0] + m1.mat[1 * 4 + 1] * m2.mat[1 * 4 + 1] + m1.mat[1 * 4 + 2] * m2.mat[1 * 4 + 2];
  451. result.mat[1 * 4 + 2] = m1.mat[1 * 4 + 0] * m2.mat[2 * 4 + 0] + m1.mat[1 * 4 + 1] * m2.mat[2 * 4 + 1] + m1.mat[1 * 4 + 2] * m2.mat[2 * 4 + 2];
  452. result.mat[2 * 4 + 0] = m1.mat[2 * 4 + 0] * m2.mat[0 * 4 + 0] + m1.mat[2 * 4 + 1] * m2.mat[0 * 4 + 1] + m1.mat[2 * 4 + 2] * m2.mat[0 * 4 + 2];
  453. result.mat[2 * 4 + 1] = m1.mat[2 * 4 + 0] * m2.mat[1 * 4 + 0] + m1.mat[2 * 4 + 1] * m2.mat[1 * 4 + 1] + m1.mat[2 * 4 + 2] * m2.mat[1 * 4 + 2];
  454. result.mat[2 * 4 + 2] = m1.mat[2 * 4 + 0] * m2.mat[2 * 4 + 0] + m1.mat[2 * 4 + 1] * m2.mat[2 * 4 + 1] + m1.mat[2 * 4 + 2] * m2.mat[2 * 4 + 2];
  455. dst[0] = - ( m2.mat[0 * 4 + 0] * m2.mat[0 * 4 + 3] + m2.mat[1 * 4 + 0] * m2.mat[1 * 4 + 3] + m2.mat[2 * 4 + 0] * m2.mat[2 * 4 + 3] );
  456. dst[1] = - ( m2.mat[0 * 4 + 1] * m2.mat[0 * 4 + 3] + m2.mat[1 * 4 + 1] * m2.mat[1 * 4 + 3] + m2.mat[2 * 4 + 1] * m2.mat[2 * 4 + 3] );
  457. dst[2] = - ( m2.mat[0 * 4 + 2] * m2.mat[0 * 4 + 3] + m2.mat[1 * 4 + 2] * m2.mat[1 * 4 + 3] + m2.mat[2 * 4 + 2] * m2.mat[2 * 4 + 3] );
  458. result.mat[0 * 4 + 3] = m1.mat[0 * 4 + 0] * dst[0] + m1.mat[0 * 4 + 1] * dst[1] + m1.mat[0 * 4 + 2] * dst[2] + m1.mat[0 * 4 + 3];
  459. result.mat[1 * 4 + 3] = m1.mat[1 * 4 + 0] * dst[0] + m1.mat[1 * 4 + 1] * dst[1] + m1.mat[1 * 4 + 2] * dst[2] + m1.mat[1 * 4 + 3];
  460. result.mat[2 * 4 + 3] = m1.mat[2 * 4 + 0] * dst[0] + m1.mat[2 * 4 + 1] * dst[1] + m1.mat[2 * 4 + 2] * dst[2] + m1.mat[2 * 4 + 3];
  461. }
  462. #endif /* !__JOINTTRANSFORM_H__ */