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.

250 lines
8.2 KiB

  1. //====== Copyright � 1996-2004, Valve Corporation, All rights reserved. =======
  2. //
  3. // A class representing a Dag (directed acyclic graph) node used for holding transforms, lights, cameras and shapes
  4. //
  5. //=============================================================================
  6. #ifndef DMEDAG_H
  7. #define DMEDAG_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tier1/utlstack.h"
  12. #include "datamodel/dmehandle.h"
  13. #include "datamodel/dmelement.h"
  14. #include "datamodel/dmattribute.h"
  15. #include "datamodel/dmattributevar.h"
  16. #include "movieobjects/dmeshape.h"
  17. #include "movieobjects/dmetransform.h"
  18. #include "movieobjects/dmeoverlay.h"
  19. //-----------------------------------------------------------------------------
  20. // Forward declarations
  21. //-----------------------------------------------------------------------------
  22. class CDmeOverlay;
  23. class CDmeTransform;
  24. class CDmeShape;
  25. class CDmeDrawSettings;
  26. class CDmeChannel;
  27. class CDmeClip;
  28. class DmeLog_TimeSelection_t;
  29. class CDmeTransformControl;
  30. //-----------------------------------------------------------------------------
  31. // A class representing a camera
  32. //-----------------------------------------------------------------------------
  33. class CDmeDag : public CDmElement
  34. {
  35. DEFINE_ELEMENT( CDmeDag, CDmElement );
  36. public:
  37. virtual void Resolve();
  38. // Accessors
  39. CDmeTransform *GetTransform() const;
  40. CDmeShape *GetShape();
  41. // Changes the shage
  42. void SetShape( CDmeShape *pShape );
  43. bool IsVisible() const;
  44. void SetVisible( bool bVisible = true );
  45. // child helpers
  46. const CUtlVector< DmElementHandle_t > &GetChildren() const;
  47. int GetChildCount() const;
  48. CDmeDag *GetChild( int i ) const;
  49. bool AddChild( CDmeDag* pDag );
  50. void RemoveChild( int i );
  51. void RemoveChild( const CDmeDag *pChild, bool bRecurse = false );
  52. int FindChild( const CDmeDag *pChild ) const;
  53. int FindChild( CDmeDag *&pParent, const CDmeDag *pChild );
  54. int FindChild( const char *name ) const;
  55. CDmeDag *FindOrAddChild( const char *name );
  56. void RemoveAllChildren();
  57. bool SetParent( CDmeDag *pDmeDagParent );
  58. CDmeDag *FindChildByName_R( const char *name ) const;
  59. // Count the number of steps between the node and the specified child node, returns -1 if not related
  60. int StepsToChild( const CDmeDag *pChild ) const;
  61. // Recursively render the Dag hierarchy
  62. virtual void Draw( CDmeDrawSettings *pDrawSettings = NULL );
  63. void GetBoundingSphere( Vector &center, float &radius ) const
  64. {
  65. matrix3x4_t identity;
  66. SetIdentityMatrix( identity );
  67. GetBoundingSphere( center, radius, identity );
  68. }
  69. void GetBoundingBox( Vector &min, Vector &max ) const
  70. {
  71. matrix3x4_t identity;
  72. SetIdentityMatrix( identity );
  73. GetBoundingBox( min, max, identity );
  74. }
  75. void GetShapeToWorldTransform( matrix3x4_t &mat );
  76. void GetLocalMatrix( matrix3x4_t &mat ) const;
  77. void SetLocalMatrix( matrix3x4_t &mat );
  78. void GetAbsTransform( matrix3x4_t &matAbsTransform ) const;
  79. void SetAbsTransform( const matrix3x4_t &matAbsTransform );
  80. void GetAbsPosition( Vector &absPos ) const;
  81. void SetAbsPosition( const Vector &absPos );
  82. void GetAbsOrientation( Quaternion &absOrientation ) const;
  83. void SetAbsOrientation( const Quaternion &absOrientation );
  84. void BakeStaticTransforms( bool bRecurse = true );
  85. void OnAttachToDmeDag( CDmeDag *pParentDag, bool bFixupLogs = true );
  86. CDmeDag *GetParent() const;
  87. template <class T>
  88. T *FindParentDagOfType();
  89. // Find all nodes in the sub-tree of the dag which are of the specified type.
  90. template< class T >
  91. void FindChildrenOfType( CUtlVector< T* > &children );
  92. // Determine if the dag has an override parent
  93. bool HasOverrideParent() const;
  94. // Get the current override parent, returns NULL if no override parent is set
  95. const CDmeDag *GetOverrideParent( bool bIgnoreEnable = false ) const;
  96. const CDmeDag *GetOverrideParent( bool &bPosition, bool &bRotation, bool bIgnoreEnable = false ) const;
  97. // Set the current override parent, if the parameter is NULL the overrider parent will be cleared.
  98. void SetOverrideParent( const CDmeDag *pParentDag, bool bPosition, bool bRotation );
  99. // Set the flag which enables or disables the override parent
  100. void EnableOverrideParent( bool bEnable );
  101. // Determine if the override parent is enabled ( This only says if an override parent is allowed, not if the dag has an override parent)
  102. bool IsOverrideParentEnabled() const;
  103. // Determine if this dag node is ancestor of the specified dag
  104. bool IsAncestorOfDag( const CDmeDag *pDag ) const;
  105. // Find the dag node which is the root of the tree the dag node is in.
  106. CDmeDag *FindRoot();
  107. void BindTransformToDmeDag( const CDmeDag *pTargetDag, const DmeLog_TimeSelection_t &params, const CDmeClip *pMovie, const Vector& offsset,
  108. bool bPosition, bool bOrientation, bool bMaintainOffset );
  109. void ComputeTransformAtTime( DmeTime_t globalTime,const CDmeClip* pMovie, matrix3x4_t &matAbsTransform, matrix3x4_t &localTransform );
  110. void MoveToTarget( const CDmeDag *pTargetDag, const DmeLog_TimeSelection_t &params, const CDmeClip *pMovie );
  111. void GetParentWorldMatrix( matrix3x4_t &mat ) const;
  112. void GetTranslationParentWorldMatrix( matrix3x4_t &mParentToWorld );
  113. static void DrawUsingEngineCoordinates( bool bEnable );
  114. static void DrawZUp( bool bZUp );
  115. static bool IsDrawZUp() { return !s_bDrawZUp; }
  116. // Transform from DME to engine coordinates
  117. static void DmeToEngineMatrix( matrix3x4_t& dmeToEngine, bool bZUp );
  118. static void EngineToDmeMatrix( matrix3x4_t& engineToDme, bool bZUp );
  119. // Find the channels targeting the transform of the object either directly or through a constraint
  120. void FindTransformChannels( CUtlVector< CDmeChannel * > &list ) const;
  121. // Find the transform controls driving the dag node
  122. CDmeTransformControl *FindTransformControl() const;
  123. // Find all of the operators on which dag node is dependent, this recursively finds operators for the parents of the dag.
  124. void FindRelevantOperators( CUtlVector< CDmeOperator * > &operatorList ) const;
  125. // Find all of the operators on which the dag node is dependent, splitting the channels into a separate list.
  126. void FindRelevantOperators( CUtlVector< CDmeChannel * > &list, CUtlVector< CDmeOperator * > &operatorList ) const;
  127. // This one only looks at the current CDmeDag
  128. void FindLocalOperators( CUtlVector< CDmeOperator * > &operatorList ) const;
  129. protected:
  130. void GetBoundingSphere( Vector &center, float &radius, const matrix3x4_t &pMat ) const;
  131. void GetBoundingBox( Vector &min, Vector &max, const matrix3x4_t &pMat ) const;
  132. void PushDagTransform();
  133. void PopDagTransform();
  134. CDmAttribute *GetVisibilityAttribute();
  135. CDmaVar< bool > m_Visible;
  136. CDmaVar< bool > m_bDisableOverrideParent;
  137. CDmaElement< CDmeTransform > m_Transform;
  138. CDmaElement< CDmeShape > m_Shape;
  139. CDmaElementArray< CDmeDag > m_Children;
  140. private:
  141. struct TransformInfo_t
  142. {
  143. CDmeTransform *m_pTransform;
  144. matrix3x4_t m_DagToWorld;
  145. bool m_bComputedDagToWorld;
  146. };
  147. static CUtlStack<TransformInfo_t> s_TransformStack;
  148. static bool s_bDrawUsingEngineCoordinates;
  149. static bool s_bDrawZUp; // NOTE: s_bZUp doesn't mean the model is in engine coordinates, it means it's Z Up, -Y Front & X Right. Engine is Z Up, X Front & Y Right.
  150. };
  151. void RemoveDagFromParents( CDmeDag *pDag, bool bRecursivelyRemoveEmptyDagsFromParents = false );
  152. template <class T>
  153. inline T *CDmeDag::FindParentDagOfType()
  154. {
  155. CDmeDag *parent = GetParent();
  156. while ( parent )
  157. {
  158. if ( CastElement< T >( parent ) )
  159. return static_cast< T * >( parent );
  160. parent = parent->GetParent();
  161. }
  162. if ( CastElement< T >( this ) )
  163. return static_cast< T * >( this );
  164. return NULL;
  165. }
  166. //-----------------------------------------------------------------------------
  167. // Purpose: Find all dag nodes in the sub-tree of the dag which are of the
  168. // specified type.
  169. //-----------------------------------------------------------------------------
  170. template< class T >
  171. void CDmeDag::FindChildrenOfType( CUtlVector< T* > &children )
  172. {
  173. int nChildren = m_Children.Count();
  174. for ( int iChild = 0; iChild < nChildren; ++iChild )
  175. {
  176. CDmeDag *pChild = m_Children[ iChild ];
  177. if ( pChild == NULL )
  178. continue;
  179. // Add the child to the list if it is of the specified type
  180. T* pChildType = CastElement< T >( pChild );
  181. if ( pChildType )
  182. {
  183. children.AddToTail( pChildType );
  184. }
  185. // Recursively add the children of the child.
  186. pChild->FindChildrenOfType( children );
  187. }
  188. }
  189. #endif // DMEDAG_H