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.

146 lines
5.4 KiB

  1. //============ Copyright (c) Valve Corporation, All rights reserved. ==========
  2. //
  3. // This is patterned after FbxAxisSystem
  4. //
  5. //=============================================================================
  6. #ifndef DMEAXISSYSTEM_H
  7. #define DMEAXISSYSTEM_H
  8. #include "datamodel/dmelement.h"
  9. //=============================================================================
  10. //
  11. // CDmeAxisSystem, an unambiguous definition of the axis system. Previously
  12. // the terms Y Up and Z Up got thrown around a lot but they do not unambiguously
  13. // specify a coordinate system.
  14. //
  15. // To define an axis system both the up axis and the parity of the axis system
  16. // need to be specified. The parity is not an independent variable, it depends
  17. // on the value of the up axis specified. Whichever axis is specified as the
  18. // up axis leaves two remaining axes and even implies the first remaining
  19. // axis, in alphabetical order, is the Forward axis.
  20. //
  21. // The Valve engine coordinate system has traditionally been +Z Up and
  22. // +X as the forward axis. By specifying +Z as the up axis that leaves
  23. // X & Y, since X is desired, that's even parity. It would be defined
  24. // in Axis, Parity as:
  25. //
  26. // pDmeAxisSystem->Init( CDmeAxisSystem::AS_AXIS_Z, CDmeAxisSystem::AS_PARITY_EVEN );
  27. //
  28. // By default, Maya's coordinate system is +Y Up with +Z forward. Taking
  29. // +Y as up leaves X & Z, since Z is 2nd, that's odd parity. i.e.
  30. //
  31. // pDmeAxisSystem->Init( CDmeAxisSystem::AS_AXIS_Y, CDmeAxisSystem::AS_PARITY_ODD );
  32. //
  33. //=============================================================================
  34. class CDmeAxisSystem : public CDmElement
  35. {
  36. DEFINE_ELEMENT( CDmeAxisSystem, CDmElement );
  37. public:
  38. enum Axis_t
  39. {
  40. AS_AXIS_NZ = -3,
  41. AS_AXIS_NY = -2,
  42. AS_AXIS_NX = -1,
  43. AS_AXIS_X = 1,
  44. AS_AXIS_Y = 2,
  45. AS_AXIS_Z = 3
  46. };
  47. enum ForwardParity_t
  48. {
  49. AS_PARITY_NODD = -2,
  50. AS_PARITY_NEVEN = -1,
  51. AS_PARITY_EVEN = 1,
  52. AS_PARITY_ODD = 2
  53. };
  54. enum CoordSys_t
  55. {
  56. AS_RIGHT_HANDED = 0,
  57. AS_LEFT_HANDED = 1
  58. };
  59. enum PredefinedAxisSystem
  60. {
  61. AS_INVALID = -1, // Invalid
  62. AS_VALVE_ENGINE, // Up: +Z, Forward: +X
  63. AS_SMD, // Up: +Z, Forward: -Y
  64. AS_MAYA_YUP, // Up: +Y, Forward: +Z
  65. AS_MAYA_ZUP, // Up: +Z, Forward: -Y
  66. AS_MODO_YUP, // Up: +Y, Forward: +Z
  67. AS_3DSMAX // Up: +Z, Forward: -Y
  68. };
  69. bool Init( Axis_t eUpAxis, ForwardParity_t eForwardParity, CoordSys_t eCoordSys = AS_RIGHT_HANDED );
  70. bool Init( PredefinedAxisSystem nPredefinedAxisSystem );
  71. // Returns true if the specified eUpAxis, eForward and eCoordSys are all valid values together
  72. static bool IsValid( Axis_t eUpAxis, ForwardParity_t eForwardAxis, CoordSys_t eCoordSys = AS_RIGHT_HANDED );
  73. bool IsValid() const;
  74. // Returns the upAxis, forwardParity & coordSys for the specified predefined axisSystem
  75. static bool GetPredefinedAxisSystem( Axis_t &eUpAxis, ForwardParity_t &eForwardParity, CoordSys_t &eCoordSys, PredefinedAxisSystem ePredefinedAxisSystem );
  76. // Specifies whether this CDmeAxisSystem is the same as the predefined axis system specified
  77. bool IsEqual( PredefinedAxisSystem ePredefinedAxisSystem ) const;
  78. // Returns one of [ AS_AXIS_NX, AS_AXIS_NY, AS_AXIS_NZ, AS_AXIS_X, AS_AXIS_Y, AS_AXIS_Z ] from m_nUpAxis
  79. Axis_t GetUpAxis() const;
  80. // Returns one of [ AS_PARITY_NEVEN, AS_PARITY_NODD, AS_PARITY_EVEN, AS_PARITY_ODD ] from m_nForwardParity
  81. ForwardParity_t GetForwardParity() const;
  82. // Returns one of [ AS_LEFT_HANDED, AS_RIGHT_HANDED ] from m_nCoordSys
  83. CoordSys_t GetCoordSys() const;
  84. // Get the matrix to convert the identity to this axis system
  85. static void ComputeMatrix( matrix3x4a_t &mMatrix, PredefinedAxisSystem ePredefinedAxisSystem );
  86. // Get the matrix to convert data from the specified axis system to the specified axis system
  87. static void GetConversionMatrix(
  88. matrix3x4a_t &mMat,
  89. PredefinedAxisSystem eFromAxisSystem,
  90. PredefinedAxisSystem eToAxisSystem );
  91. static void GetConversionMatrix( matrix3x4a_t &mMat,
  92. Axis_t eFromUpAxis, ForwardParity_t eFromForwardParity,
  93. Axis_t eToUpAxis, ForwardParity_t eToForwardParity );
  94. static void GetConversionMatrix( matrix3x4a_t &mMat,
  95. Axis_t eFromUpAxis, ForwardParity_t eFromForwardParity, CoordSys_t eFromCoordSys,
  96. Axis_t eToUpAxis, ForwardParity_t eToForwardParity, CoordSys_t eToCoordSys );
  97. static CUtlString GetAxisString(
  98. Axis_t eUpAxis,
  99. ForwardParity_t eForwardParity,
  100. CoordSys_t eCoordSys );
  101. protected:
  102. // Returns one of [ AS_AXIS_X, AS_AXIS_Y, AS_AXIS_Z ] along with one of [ -1, 1 ] to indicate the sign
  103. Axis_t GetAbsUpAxisAndSign( int &nSign ) const;
  104. // Returns one of [ AS_PARITY_EVEN, AS_PARITY_ODD ] along with one of [ -1, 1 ] to indicate the sign
  105. ForwardParity_t GetAbsForwardParityAndSign( int &nSign ) const;
  106. // Returns one of [ AS_AXIS_X, AS_AXIS_Y, AS_AXIS_Z ] along with one of [ -1, 1 ] to indicate the sign
  107. Axis_t ComputeAbsForwardAxisAndSign( int &nSign ) const;
  108. // Returns one of [ AS_AXIS_X, AS_AXIS_Y, AS_AXIS_Z ] along with one of [ -1, 1 ] to indicate the sign
  109. Axis_t ComputeLeftAxis( int &nSign ) const;
  110. // Computes the matrix for the specified upAxis, forwardParity and coordSys values
  111. static void ComputeMatrix( matrix3x4a_t &mMatrix, Axis_t eUpAxis, ForwardParity_t eForwardParity, CoordSys_t eCoordSys );
  112. CDmaVar< int > m_nUpAxis; // [ +/- AS_AXIS_X, +/- AS_AXIS_Y, +/- AS_AXIS_Z ]
  113. CDmaVar< int > m_nForwardParity; // [ +/- AS_PARITY_EVEN, +/- AS_PARITY_ODD ]
  114. CDmaVar< int > m_nCoordSys; // [ AS_RIGHT_HANDED, AS_LEFT_HANDED ]
  115. };
  116. #endif // DMEAXISSYSTEM_H