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.

115 lines
3.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "movieobjects/dmeshape.h"
  7. #include "datamodel/dmelementfactoryhelper.h"
  8. #include "movieobjects_interfaces.h"
  9. #include "movieobjects/dmedag.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. //-----------------------------------------------------------------------------
  13. // Expose this class to the scene database
  14. //-----------------------------------------------------------------------------
  15. IMPLEMENT_ELEMENT_FACTORY( DmeShape, CDmeShape );
  16. //-----------------------------------------------------------------------------
  17. // Purpose:
  18. //-----------------------------------------------------------------------------
  19. void CDmeShape::OnConstruction()
  20. {
  21. m_visible.InitAndSet( this, "visible", true );
  22. }
  23. void CDmeShape::OnDestruction()
  24. {
  25. }
  26. void CDmeShape::Draw( const matrix3x4_t &shapeToWorld, CDmeDrawSettings *pDrawSettings /* = NULL */ )
  27. {
  28. Assert( 0 );
  29. }
  30. //-----------------------------------------------------------------------------
  31. // The default bounding sphere is empty at the origin
  32. //-----------------------------------------------------------------------------
  33. void CDmeShape::GetBoundingSphere( Vector &c, float &r ) const
  34. {
  35. c.Zero();
  36. r = 0.0f;
  37. }
  38. //-----------------------------------------------------------------------------
  39. //
  40. //-----------------------------------------------------------------------------
  41. int CDmeShape::GetParentCount() const
  42. {
  43. int nReferringDags = 0;
  44. DmAttributeReferenceIterator_t i = g_pDataModel->FirstAttributeReferencingElement( GetHandle() );
  45. while ( i != DMATTRIBUTE_REFERENCE_ITERATOR_INVALID )
  46. {
  47. CDmAttribute *pAttribute = g_pDataModel->GetAttribute( i );
  48. CDmeDag *pDag = CastElement< CDmeDag >( pAttribute->GetOwner() );
  49. const static UtlSymId_t symShape = g_pDataModel->GetSymbol( "shape" );
  50. if ( pDag && pAttribute->GetNameSymbol() == symShape && pDag->GetFileId() == GetFileId() )
  51. {
  52. ++nReferringDags;
  53. }
  54. i = g_pDataModel->NextAttributeReferencingElement( i );
  55. }
  56. return nReferringDags;
  57. }
  58. //-----------------------------------------------------------------------------
  59. //
  60. //-----------------------------------------------------------------------------
  61. CDmeDag *CDmeShape::GetParent( int nParentIndex /*= 0 */ ) const
  62. {
  63. int nReferringDags = 0;
  64. DmAttributeReferenceIterator_t i = g_pDataModel->FirstAttributeReferencingElement( GetHandle() );
  65. while ( i != DMATTRIBUTE_REFERENCE_ITERATOR_INVALID )
  66. {
  67. CDmAttribute *pAttribute = g_pDataModel->GetAttribute( i );
  68. CDmeDag *pDag = CastElement< CDmeDag >( pAttribute->GetOwner() );
  69. const static UtlSymId_t symShape = g_pDataModel->GetSymbol( "shape" );
  70. if ( pDag && pAttribute->GetNameSymbol() == symShape && pDag->GetFileId() == GetFileId() )
  71. {
  72. if ( nReferringDags == nParentIndex )
  73. return pDag;
  74. ++nReferringDags;
  75. }
  76. i = g_pDataModel->NextAttributeReferencingElement( i );
  77. }
  78. return NULL;
  79. }
  80. //-----------------------------------------------------------------------------
  81. //
  82. //-----------------------------------------------------------------------------
  83. void CDmeShape::GetShapeToWorldTransform( matrix3x4_t &mat, int nParentIndex /*= 0 */ ) const
  84. {
  85. CDmeDag *pDag = GetParent( nParentIndex );
  86. if ( pDag )
  87. {
  88. pDag->GetShapeToWorldTransform( mat );
  89. }
  90. else
  91. {
  92. SetIdentityMatrix( mat );
  93. }
  94. }