Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

536 lines
19 KiB

  1. //============ Copyright (c) Valve Corporation, All rights reserved. ==========
  2. //
  3. //=============================================================================
  4. #include "datamodel/dmelementfactoryhelper.h"
  5. #include "movieobjects/dmechannel.h"
  6. #include "movieobjects/dmelog.h"
  7. #include "movieobjects/dmemesh.h"
  8. #include "movieobjects/dmemodel.h"
  9. #include "movieobjects/dmevertexdata.h"
  10. #include "tier1/fmtstr.h"
  11. #include "movieobjects/dmeaxissystem.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. //-----------------------------------------------------------------------------
  15. // Expose this class to the scene database
  16. //-----------------------------------------------------------------------------
  17. IMPLEMENT_ELEMENT_FACTORY( DmeAxisSystem, CDmeAxisSystem );
  18. //-----------------------------------------------------------------------------
  19. //
  20. //-----------------------------------------------------------------------------
  21. static CDmeAxisSystem::Axis_t GetAbsAxisAndSign(
  22. int &nSign, const CDmeAxisSystem::Axis_t eAxis )
  23. {
  24. nSign = ( eAxis < 0 ) ? -1 : 1;
  25. return static_cast< CDmeAxisSystem::Axis_t >( abs( eAxis ) );
  26. }
  27. //-----------------------------------------------------------------------------
  28. //
  29. //-----------------------------------------------------------------------------
  30. static CDmeAxisSystem::ForwardParity_t GetAbsForwardParityAndSign(
  31. int &nSign, const CDmeAxisSystem::ForwardParity_t eForwardParity )
  32. {
  33. nSign = ( eForwardParity < 0 ) ? -1 : 1;
  34. return static_cast< CDmeAxisSystem::ForwardParity_t >( abs( eForwardParity ) );
  35. }
  36. //-----------------------------------------------------------------------------
  37. //
  38. //-----------------------------------------------------------------------------
  39. static CDmeAxisSystem::Axis_t ComputeAbsForwardAxisAndSign(
  40. int &nSign,
  41. const CDmeAxisSystem::Axis_t eUpAxis,
  42. const CDmeAxisSystem::ForwardParity_t eForwardParity )
  43. {
  44. Assert( CDmeAxisSystem::IsValid( eUpAxis, eForwardParity ) );
  45. int nUpAxisSign = 0;
  46. const CDmeAxisSystem::Axis_t eAbsUpAxis = GetAbsAxisAndSign( nUpAxisSign, eUpAxis );
  47. AssertDbg( eAbsUpAxis >= CDmeAxisSystem::AS_AXIS_X && eAbsUpAxis <= CDmeAxisSystem::AS_AXIS_Z );
  48. const CDmeAxisSystem::ForwardParity_t eAbsForwardParity = GetAbsForwardParityAndSign( nSign, eForwardParity );
  49. AssertDbg( eAbsForwardParity >= CDmeAxisSystem::AS_PARITY_EVEN && eAbsForwardParity <= CDmeAxisSystem::AS_PARITY_ODD );
  50. // eAxisParityMap[Axis_t - 1][ ForwardParityType_t - 1 ] gives parity axis
  51. static const CDmeAxisSystem::Axis_t eAxisParityMap[][2] = {
  52. { CDmeAxisSystem::AS_AXIS_Y, CDmeAxisSystem::AS_AXIS_Z }, // Up X
  53. { CDmeAxisSystem::AS_AXIS_X, CDmeAxisSystem::AS_AXIS_Z }, // Up Y
  54. { CDmeAxisSystem::AS_AXIS_X, CDmeAxisSystem::AS_AXIS_Y } // Up Z
  55. };
  56. const CDmeAxisSystem::Axis_t nAbsForwardAxis = eAxisParityMap[ eAbsUpAxis - 1 ][ eAbsForwardParity - 1 ];
  57. AssertDbg( nAbsForwardAxis != eAbsUpAxis );
  58. return nAbsForwardAxis;
  59. }
  60. //-----------------------------------------------------------------------------
  61. //
  62. //-----------------------------------------------------------------------------
  63. static CDmeAxisSystem::Axis_t ComputeAbsLeftAxisAndSign(
  64. int &nSign,
  65. const CDmeAxisSystem::Axis_t eUpAxis,
  66. const CDmeAxisSystem::ForwardParity_t eForwardParity,
  67. const CDmeAxisSystem::CoordSys_t eCoordSys )
  68. {
  69. Assert( CDmeAxisSystem::IsValid( eUpAxis, eForwardParity, eCoordSys ) );
  70. int nUpAxisSign = 0;
  71. const CDmeAxisSystem::Axis_t eAbsUpAxis = GetAbsAxisAndSign( nUpAxisSign, eUpAxis );
  72. AssertDbg( nUpAxisSign == -1 || nUpAxisSign == 1 );
  73. AssertDbg( eAbsUpAxis >= CDmeAxisSystem::AS_AXIS_X && eAbsUpAxis <= CDmeAxisSystem::AS_AXIS_Z );
  74. int nForwardAxisSign = 0;
  75. const CDmeAxisSystem::Axis_t eAbsForwardAxis = ComputeAbsForwardAxisAndSign( nForwardAxisSign, eUpAxis, eForwardParity );
  76. AssertDbg( eAbsForwardAxis >= CDmeAxisSystem::AS_AXIS_X && eAbsForwardAxis <= CDmeAxisSystem::AS_AXIS_Z );
  77. AssertDbg( nForwardAxisSign == -1 || nForwardAxisSign == 1 );
  78. AssertDbg( eAbsForwardAxis != eAbsUpAxis );
  79. // Chart of cross products, COL x ROW, 24 possibilities as parallel vectors are not allowed
  80. // NOTE: The 3x3 matrices are the same across both diagonals and the two sets of 3x3's are
  81. // simply the negative image of each other
  82. //
  83. // +=====+=====+=====+=====+=====+=====+
  84. // | -X | -Y | -Z | X | Y | Z |
  85. // +=====+=====+=====+=====+=====+=====+
  86. //
  87. // +=====+ +-----+-----+-----+-----+-----+-----+
  88. // | -X | | . | Z | -Y | . | -Z | Y |
  89. // +-----+ +-----+-----+-----+-----+-----+-----+
  90. // | -Y | | -Z | . | X | Z | . | -X |
  91. // +-----+ +-----+-----+-----+-----+-----+-----+
  92. // | -Z | | Y | -X | . | -Y | X | . |
  93. // +-----+ +-----+-----+-----+-----+-----+-----+
  94. // | X | | . | -Z | Y | . | Z | -Y |
  95. // +-----+ +-----+-----+-----+-----+-----+-----+
  96. // | Y | | Z | . | -X | -Z | . | X |
  97. // +-----+ +-----+-----+-----+-----+-----+-----+
  98. // | Z | | -Y | X | . | Y | -X | . |
  99. // +=====+ +-----+-----+-----+-----+-----+-----+
  100. // The 3x3 matrix from the above table without sign, sign is broken down in next table
  101. // 0's are invalid cases, index [up - 1][forward - 1]
  102. static const CDmeAxisSystem::Axis_t eAxisUpForwardMap[3][3] = {
  103. { (CDmeAxisSystem::Axis_t)0, CDmeAxisSystem::AS_AXIS_Z, CDmeAxisSystem::AS_AXIS_Y },
  104. { CDmeAxisSystem::AS_AXIS_Z, (CDmeAxisSystem::Axis_t)0, CDmeAxisSystem::AS_AXIS_X },
  105. { CDmeAxisSystem::AS_AXIS_Y, CDmeAxisSystem::AS_AXIS_X, (CDmeAxisSystem::Axis_t)0 }
  106. };
  107. // The signs from the lower right 3x3 case (positive axis x positive axis)
  108. // 0's are invalid cases, index [up - 1][forward - 1]
  109. static const int nSignUpForwardMap[3][3] = {
  110. { 0, 1, -1 },
  111. { -1, 0, 1 },
  112. { 1, -1, 0 }
  113. };
  114. const CDmeAxisSystem::Axis_t eAbsLeftAxis = eAxisUpForwardMap[ eAbsUpAxis - 1 ][ eAbsForwardAxis - 1 ];
  115. AssertDbg( eAbsLeftAxis >= CDmeAxisSystem::AS_AXIS_X && eAbsLeftAxis <= CDmeAxisSystem::AS_AXIS_Z );
  116. AssertDbg( eAbsLeftAxis != eAbsUpAxis );
  117. AssertDbg( eAbsLeftAxis != eAbsForwardAxis );
  118. nSign = nSignUpForwardMap[ eAbsUpAxis - 1 ][ eAbsForwardAxis - 1 ];
  119. // If up and forward are not the same sign, then sign is reversed from table
  120. if ( nUpAxisSign != nForwardAxisSign )
  121. {
  122. nSign = -nSign;
  123. }
  124. // If left handed, reverse sign of axis
  125. if ( eCoordSys == CDmeAxisSystem::AS_LEFT_HANDED )
  126. {
  127. nSign = -nSign;
  128. }
  129. return eAbsLeftAxis;
  130. }
  131. //-----------------------------------------------------------------------------
  132. //
  133. //-----------------------------------------------------------------------------
  134. void CDmeAxisSystem::OnConstruction()
  135. {
  136. // Initialize to Maya Y Up
  137. m_nUpAxis.InitAndSet( this, "upAxis", AS_AXIS_Y );
  138. m_nForwardParity.InitAndSet( this, "forwardParity", AS_PARITY_ODD );
  139. m_nCoordSys.InitAndSet( this, "coordSys", AS_RIGHT_HANDED );
  140. Assert( IsValid() );
  141. }
  142. //-----------------------------------------------------------------------------
  143. //
  144. //-----------------------------------------------------------------------------
  145. void CDmeAxisSystem::OnDestruction()
  146. {
  147. }
  148. //-----------------------------------------------------------------------------
  149. //
  150. //-----------------------------------------------------------------------------
  151. bool CDmeAxisSystem::Init( Axis_t eUpAxis, ForwardParity_t eForwardParity, CoordSys_t eCoordSys /*= AS_RIGHT_HANDED */ )
  152. {
  153. if ( !IsValid( eUpAxis, eForwardParity, eCoordSys ) )
  154. {
  155. AssertMsg( false, "Invalid Initialization of CDmeAxisSystem" );
  156. return false;
  157. }
  158. m_nUpAxis = eUpAxis;
  159. m_nForwardParity = eForwardParity;
  160. m_nCoordSys = eCoordSys;
  161. return true;
  162. }
  163. //-----------------------------------------------------------------------------
  164. //
  165. //-----------------------------------------------------------------------------
  166. bool CDmeAxisSystem::Init( PredefinedAxisSystem ePredefinedAxisSystem )
  167. {
  168. Axis_t eUpAxis = static_cast< Axis_t >( m_nUpAxis.Get() );
  169. ForwardParity_t eForwardParity = static_cast< ForwardParity_t >( m_nForwardParity.Get() );
  170. CoordSys_t eCoordSys = static_cast< CoordSys_t >( m_nCoordSys.Get() );
  171. if ( !GetPredefinedAxisSystem( eUpAxis, eForwardParity, eCoordSys, ePredefinedAxisSystem ) )
  172. return false;
  173. return Init( eUpAxis, eForwardParity, eCoordSys );
  174. }
  175. //-----------------------------------------------------------------------------
  176. //
  177. //-----------------------------------------------------------------------------
  178. bool CDmeAxisSystem::IsValid() const
  179. {
  180. return IsValid(
  181. static_cast< Axis_t >( m_nUpAxis.Get() ),
  182. static_cast< ForwardParity_t >( m_nForwardParity.Get() ),
  183. static_cast< CoordSys_t >( m_nCoordSys.Get() ) );
  184. }
  185. //-----------------------------------------------------------------------------
  186. //
  187. //-----------------------------------------------------------------------------
  188. bool CDmeAxisSystem::IsValid( Axis_t nUpAxis, ForwardParity_t eForwardParity, CoordSys_t eCoordSys )
  189. {
  190. if ( nUpAxis == 0 || nUpAxis < AS_AXIS_NZ || nUpAxis > AS_AXIS_Z )
  191. return false;
  192. if ( eForwardParity == 0 || eForwardParity < AS_PARITY_NODD || eForwardParity > AS_PARITY_ODD )
  193. return false;
  194. if ( eCoordSys < AS_RIGHT_HANDED || eCoordSys > AS_LEFT_HANDED )
  195. return false;
  196. return true;
  197. }
  198. //-----------------------------------------------------------------------------
  199. //
  200. //-----------------------------------------------------------------------------
  201. bool CDmeAxisSystem::GetPredefinedAxisSystem(
  202. Axis_t &eUpAxis,
  203. ForwardParity_t &eForwardParity,
  204. CoordSys_t &eCoordSys,
  205. PredefinedAxisSystem ePredefinedAxisSystem )
  206. {
  207. if ( ePredefinedAxisSystem < AS_VALVE_ENGINE || ePredefinedAxisSystem > AS_3DSMAX )
  208. return false;
  209. static int predefinedAxisSystemList[][3] = {
  210. { AS_AXIS_Z, AS_PARITY_EVEN, AS_RIGHT_HANDED }, // AS_VALVE_ENGINE +Z, +X
  211. { AS_AXIS_Z, -AS_PARITY_ODD, AS_RIGHT_HANDED }, // AS_SMD +Z, -Y
  212. { AS_AXIS_Y, AS_PARITY_ODD, AS_RIGHT_HANDED }, // AS_MAYA_YUP +Y, +Z
  213. { AS_AXIS_Z, -AS_PARITY_ODD, AS_RIGHT_HANDED }, // AS_MAYA_ZUP +Z, -Y
  214. { AS_AXIS_Y, AS_PARITY_ODD, AS_RIGHT_HANDED }, // AS_MODO +Y, +Z
  215. { AS_AXIS_Z, -AS_PARITY_ODD, AS_RIGHT_HANDED } // AS_3DSMAX +Z, -Y
  216. };
  217. COMPILE_TIME_ASSERT( AS_VALVE_ENGINE == 0 );
  218. COMPILE_TIME_ASSERT( AS_SMD == 1 );
  219. COMPILE_TIME_ASSERT( AS_MAYA_YUP == 2 );
  220. COMPILE_TIME_ASSERT( AS_MAYA_ZUP == 3 );
  221. COMPILE_TIME_ASSERT( AS_MODO_YUP == 4 );
  222. COMPILE_TIME_ASSERT( AS_3DSMAX == 5 );
  223. COMPILE_TIME_ASSERT( AS_3DSMAX + 1 == ARRAYSIZE( predefinedAxisSystemList ) );
  224. eUpAxis = static_cast< Axis_t >( predefinedAxisSystemList[ePredefinedAxisSystem][0] );
  225. eForwardParity = static_cast< ForwardParity_t >( predefinedAxisSystemList[ePredefinedAxisSystem][1] );
  226. eCoordSys = static_cast< CoordSys_t >( predefinedAxisSystemList[ePredefinedAxisSystem][2] );
  227. Assert( IsValid( eUpAxis, eForwardParity, eCoordSys ) );
  228. return true;
  229. }
  230. //-----------------------------------------------------------------------------
  231. //
  232. //-----------------------------------------------------------------------------
  233. bool CDmeAxisSystem::IsEqual( PredefinedAxisSystem ePredefinedAxisSystem ) const
  234. {
  235. Axis_t eAUpAxis;
  236. ForwardParity_t eAForwardParity;
  237. CoordSys_t eACoordSys;
  238. if ( !GetPredefinedAxisSystem( eAUpAxis, eAForwardParity, eACoordSys, ePredefinedAxisSystem ) )
  239. return false;
  240. const Axis_t eBUpAxis = GetUpAxis();
  241. const ForwardParity_t eBForwardParity = GetForwardParity();
  242. const CoordSys_t eBCoordSys = GetCoordSys();
  243. return ( eBUpAxis == eAUpAxis ) && ( eBForwardParity == eAForwardParity ) && ( eBCoordSys == eACoordSys );
  244. }
  245. //-----------------------------------------------------------------------------
  246. //
  247. //-----------------------------------------------------------------------------
  248. CDmeAxisSystem::Axis_t CDmeAxisSystem::GetUpAxis() const
  249. {
  250. return static_cast< Axis_t >( m_nUpAxis.Get() );
  251. }
  252. //-----------------------------------------------------------------------------
  253. //
  254. //-----------------------------------------------------------------------------
  255. CDmeAxisSystem::ForwardParity_t CDmeAxisSystem::GetForwardParity() const
  256. {
  257. return static_cast< ForwardParity_t >( m_nForwardParity.Get() );
  258. }
  259. //-----------------------------------------------------------------------------
  260. //
  261. //-----------------------------------------------------------------------------
  262. CDmeAxisSystem::CoordSys_t CDmeAxisSystem::GetCoordSys() const
  263. {
  264. return static_cast< CoordSys_t >( m_nCoordSys.Get() );
  265. }
  266. //-----------------------------------------------------------------------------
  267. //
  268. //-----------------------------------------------------------------------------
  269. void CDmeAxisSystem::ComputeMatrix(
  270. matrix3x4a_t &mMatrix, const PredefinedAxisSystem ePredefinedAxisSystem )
  271. {
  272. Axis_t eUpAxis;
  273. ForwardParity_t eForwardParity;
  274. CoordSys_t eCoordSys;
  275. GetPredefinedAxisSystem( eUpAxis, eForwardParity, eCoordSys, ePredefinedAxisSystem );
  276. ComputeMatrix( mMatrix, eUpAxis, eForwardParity, eCoordSys );
  277. }
  278. //-----------------------------------------------------------------------------
  279. //
  280. //-----------------------------------------------------------------------------
  281. void CDmeAxisSystem::GetConversionMatrix(
  282. matrix3x4a_t &mMat,
  283. PredefinedAxisSystem eFromAxisSystem,
  284. PredefinedAxisSystem eToAxisSystem )
  285. {
  286. Axis_t eFromUpAxis;
  287. ForwardParity_t eFromForwardParity;
  288. CoordSys_t eFromCoordSys;
  289. GetPredefinedAxisSystem( eFromUpAxis, eFromForwardParity, eFromCoordSys, eFromAxisSystem );
  290. Assert( IsValid( eFromUpAxis, eFromForwardParity, eFromCoordSys ) );
  291. Axis_t eToUpAxis;
  292. ForwardParity_t eToForwardParity;
  293. CoordSys_t eToCoordSys;
  294. GetPredefinedAxisSystem( eToUpAxis, eToForwardParity, eToCoordSys, eToAxisSystem );
  295. Assert( IsValid( eToUpAxis, eToForwardParity, eToCoordSys ) );
  296. GetConversionMatrix( mMat,
  297. eFromUpAxis, eFromForwardParity, eFromCoordSys,
  298. eToUpAxis, eToForwardParity, eToCoordSys );
  299. }
  300. //-----------------------------------------------------------------------------
  301. //
  302. //-----------------------------------------------------------------------------
  303. void CDmeAxisSystem::GetConversionMatrix(
  304. matrix3x4a_t &mMat,
  305. Axis_t eFromUpAxis, ForwardParity_t eFromForwardParity,
  306. Axis_t eToUpAxis, ForwardParity_t eToForwardParity )
  307. {
  308. GetConversionMatrix( mMat,
  309. eFromUpAxis, eFromForwardParity, AS_RIGHT_HANDED,
  310. eToUpAxis, eToForwardParity, AS_RIGHT_HANDED );
  311. }
  312. //-----------------------------------------------------------------------------
  313. //
  314. //-----------------------------------------------------------------------------
  315. void CDmeAxisSystem::GetConversionMatrix(
  316. matrix3x4a_t &mMat,
  317. Axis_t eFromUpAxis, ForwardParity_t eFromForwardParity, CoordSys_t eFromCoordSys,
  318. Axis_t eToUpAxis, ForwardParity_t eToForwardParity, CoordSys_t eToCoordSys )
  319. {
  320. matrix3x4a_t mFrom;
  321. ComputeMatrix( mFrom, eFromUpAxis, eFromForwardParity, eFromCoordSys );
  322. matrix3x4a_t mTo;
  323. ComputeMatrix( mTo, eToUpAxis, eToForwardParity, eToCoordSys );
  324. // Matrix is guaranteed to be a rotation matrix (orthonormal upper 3x3) with no translation
  325. // so in this case, Transpose is the same as Inverse
  326. matrix3x4a_t mFromInv;
  327. MatrixTranspose( mFrom, mFromInv );
  328. MatrixMultiply( mTo, mFromInv, mMat );
  329. }
  330. //-----------------------------------------------------------------------------
  331. //
  332. //-----------------------------------------------------------------------------
  333. CUtlString CDmeAxisSystem::GetAxisString(
  334. Axis_t eUpAxis,
  335. ForwardParity_t eForwardParity,
  336. CoordSys_t eCoordSys )
  337. {
  338. int nUSign = 0;
  339. const int nU = GetAbsAxisAndSign( nUSign, eUpAxis );
  340. int nFSign = 0;
  341. const int nF = ::ComputeAbsForwardAxisAndSign( nFSign, eUpAxis, eForwardParity );
  342. int nLSign = 0;
  343. const int nL = ::ComputeAbsLeftAxisAndSign( nLSign, eUpAxis, eForwardParity, eCoordSys );
  344. const char *szAxis[] = { "x", "y", "z" };
  345. return CUtlString( CFmtStr( "u_%s%s_f_%s%s_l_%s%s",
  346. nUSign < 0 ? "n" : "", szAxis[nU - 1],
  347. nFSign < 0 ? "n" : "", szAxis[nF - 1],
  348. nLSign < 0 ? "n" : "", szAxis[nL - 1] ).Get() );
  349. }
  350. //-----------------------------------------------------------------------------
  351. //
  352. //-----------------------------------------------------------------------------
  353. CDmeAxisSystem::Axis_t CDmeAxisSystem::GetAbsUpAxisAndSign( int &nSign ) const
  354. {
  355. return ::GetAbsAxisAndSign( nSign, static_cast< Axis_t >( m_nUpAxis.Get() ) );
  356. }
  357. //-----------------------------------------------------------------------------
  358. //
  359. //-----------------------------------------------------------------------------
  360. CDmeAxisSystem::ForwardParity_t CDmeAxisSystem::GetAbsForwardParityAndSign( int &nSign ) const
  361. {
  362. return ::GetAbsForwardParityAndSign( nSign, GetForwardParity() );
  363. }
  364. //-----------------------------------------------------------------------------
  365. //
  366. //-----------------------------------------------------------------------------
  367. CDmeAxisSystem::Axis_t CDmeAxisSystem::ComputeAbsForwardAxisAndSign( int &nSign ) const
  368. {
  369. Assert( IsValid() );
  370. return ::ComputeAbsForwardAxisAndSign( nSign, GetUpAxis(), GetForwardParity() );
  371. }
  372. //-----------------------------------------------------------------------------
  373. //
  374. //-----------------------------------------------------------------------------
  375. CDmeAxisSystem::Axis_t CDmeAxisSystem::ComputeLeftAxis( int &nSign ) const
  376. {
  377. Assert( IsValid() );
  378. return ::ComputeAbsLeftAxisAndSign( nSign, GetUpAxis(), GetForwardParity(), GetCoordSys() );
  379. }
  380. //-----------------------------------------------------------------------------
  381. //
  382. //-----------------------------------------------------------------------------
  383. void CDmeAxisSystem::ComputeMatrix(
  384. matrix3x4a_t &mMatrix,
  385. const Axis_t eUpAxis,
  386. const ForwardParity_t eForwardParity,
  387. const CoordSys_t eCoordSys )
  388. {
  389. Assert( IsValid( eUpAxis, eForwardParity, eCoordSys ) );
  390. int nUpAxisSign = 0;
  391. const Axis_t eAbsUpAxis = ::GetAbsAxisAndSign( nUpAxisSign, eUpAxis );
  392. AssertDbg( nUpAxisSign == -1 || nUpAxisSign == 1 );
  393. AssertDbg( eAbsUpAxis >= AS_AXIS_X && eAbsUpAxis <= AS_AXIS_Z );
  394. int nForwardAxisSign = 0;
  395. const Axis_t eAbsForwardAxis = ::ComputeAbsForwardAxisAndSign( nForwardAxisSign, eUpAxis, eForwardParity );
  396. AssertDbg( eAbsForwardAxis >= AS_AXIS_X && eAbsForwardAxis <= AS_AXIS_Z );
  397. AssertDbg( nForwardAxisSign == -1 || nForwardAxisSign == 1 );
  398. AssertDbg( eAbsForwardAxis != eAbsUpAxis );
  399. int nLeftAxisSign = 0;
  400. const Axis_t eAbsLeftAxis = ::ComputeAbsLeftAxisAndSign( nLeftAxisSign, eUpAxis, eForwardParity, eCoordSys );
  401. AssertDbg( eAbsLeftAxis >= AS_AXIS_X && eAbsLeftAxis <= AS_AXIS_Z );
  402. AssertDbg( nLeftAxisSign == -1 || nLeftAxisSign == 1 );
  403. AssertDbg( eAbsLeftAxis != eAbsUpAxis );
  404. AssertDbg( eAbsLeftAxis != eAbsForwardAxis );
  405. // flVectorList[nAbsAxis - 1][( nSign + 1 ) / 2][]
  406. static const float flVectorList[][2][3] = {
  407. {
  408. { -1.0f, 0.0f, 0.0f }, // -X
  409. { 1.0f, 0.0f, 0.0f } // X
  410. },
  411. {
  412. { 0.0f, -1.0f, 0.0f }, // -Y
  413. { 0.0f, 1.0f, 0.0f } // Y
  414. },
  415. {
  416. { 0.0f, 0.0f, -1.0f }, // -Z
  417. { 0.0f, 0.0f, 1.0f } // Z
  418. }
  419. };
  420. const int nUpSignIndex = ( nUpAxisSign + 1 ) / 2;
  421. const int nForwardSignIndex = ( nForwardAxisSign + 1 ) / 2;
  422. const int nLeftSignIndex = ( nLeftAxisSign + 1 ) / 2;
  423. // Is this a bad idea?
  424. const Vector &vUp = *reinterpret_cast< const Vector * >( flVectorList[eAbsUpAxis - 1][nUpSignIndex] );
  425. const Vector &vForward = *reinterpret_cast< const Vector * >( flVectorList[eAbsForwardAxis - 1][nForwardSignIndex] );
  426. const Vector &vLeft = *reinterpret_cast< const Vector * >( flVectorList[eAbsLeftAxis - 1][nLeftSignIndex] );
  427. MatrixInitialize/*FLU*/( mMatrix, vec3_origin, vForward, vLeft, vUp );
  428. }