Team Fortress 2 Source Code as on 22/4/2020
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.

107 lines
3.0 KiB

  1. //========= Copyright 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/dmelement.h"
  13. #include "datamodel/dmattribute.h"
  14. #include "datamodel/dmattributevar.h"
  15. #include "movieobjects/dmeshape.h"
  16. #include "movieobjects/dmetransform.h"
  17. //-----------------------------------------------------------------------------
  18. // Forward declarations
  19. //-----------------------------------------------------------------------------
  20. class CDmeTransform;
  21. class CDmeShape;
  22. class CDmeDrawSettings;
  23. //-----------------------------------------------------------------------------
  24. // A class representing a camera
  25. //-----------------------------------------------------------------------------
  26. class CDmeDag : public CDmElement
  27. {
  28. DEFINE_ELEMENT( CDmeDag, CDmElement );
  29. public:
  30. // Accessors
  31. CDmeTransform *GetTransform();
  32. CDmeShape *GetShape();
  33. // Changes the shage
  34. void SetShape( CDmeShape *pShape );
  35. bool IsVisible() const;
  36. void SetVisible( bool bVisible = true );
  37. // child helpers
  38. const CUtlVector< DmElementHandle_t > &GetChildren() const;
  39. int GetChildCount() const;
  40. CDmeDag *GetChild( int i ) const;
  41. void AddChild( CDmeDag* pDag );
  42. void RemoveChild( int i );
  43. void RemoveChild( const CDmeDag *pChild, bool bRecurse = false );
  44. int FindChild( const CDmeDag *pChild ) const;
  45. int FindChild( CDmeDag *&pParent, const CDmeDag *pChild );
  46. int FindChild( const char *name ) const;
  47. CDmeDag *FindOrAddChild( const char *name );
  48. // Recursively render the Dag hierarchy
  49. virtual void Draw( CDmeDrawSettings *pDrawSettings = NULL );
  50. void GetBoundingSphere( Vector &center, float &radius ) const
  51. {
  52. matrix3x4_t identity;
  53. SetIdentityMatrix( identity );
  54. GetBoundingSphere( center, radius, identity );
  55. }
  56. void GetShapeToWorldTransform( matrix3x4_t &mat );
  57. void GetLocalMatrix( matrix3x4_t &mat );
  58. void GetWorldMatrix( matrix3x4_t &mat );
  59. void GetParentWorldMatrix( matrix3x4_t &mat );
  60. static void DrawUsingEngineCoordinates( bool bEnable );
  61. // Transform from DME to engine coordinates
  62. static void DmeToEngineMatrix( matrix3x4_t& dmeToEngine );
  63. static void EngineToDmeMatrix( matrix3x4_t& engineToDme );
  64. protected:
  65. void GetBoundingSphere( Vector &center, float &radius, const matrix3x4_t &pMat ) const;
  66. void PushDagTransform();
  67. void PopDagTransform();
  68. CDmAttribute *GetVisibilityAttribute();
  69. CDmaVar< bool > m_Visible;
  70. CDmaElement< CDmeTransform > m_Transform;
  71. CDmaElement< CDmeShape > m_Shape;
  72. CDmaElementArray< CDmeDag > m_Children;
  73. private:
  74. struct TransformInfo_t
  75. {
  76. CDmeTransform *m_pTransform;
  77. matrix3x4_t m_DagToWorld;
  78. bool m_bComputedDagToWorld;
  79. };
  80. static CUtlStack<TransformInfo_t> s_TransformStack;
  81. static bool s_bDrawUsingEngineCoordinates;
  82. };
  83. #endif // DMEDAG_H