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.

107 lines
3.4 KiB

  1. //====== Copyright � 1996-2004, Valve Corporation, All rights reserved. =======
  2. //
  3. // The transform operator class - shortcut to setting transform values from floats
  4. //
  5. //=============================================================================
  6. #include "movieobjects/dmetransformoperator.h"
  7. #include "movieobjects/dmetransform.h"
  8. #include "movieobjects_interfaces.h"
  9. #include "datamodel/dmelementfactoryhelper.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( DmeTransformOperator, CDmeTransformOperator );
  16. //-----------------------------------------------------------------------------
  17. // Purpose:
  18. //-----------------------------------------------------------------------------
  19. void CDmeTransformOperator::OnConstruction()
  20. {
  21. m_transform.Init( this, "transform" );
  22. m_positionX.Init( this, "positionX" );
  23. m_positionY.Init( this, "positionY" );
  24. m_positionZ.Init( this, "positionZ" );
  25. m_orientationX.Init( this, "orientationX" );
  26. m_orientationY.Init( this, "orientationY" );
  27. m_orientationZ.Init( this, "orientationZ" );
  28. m_orientationW.Init( this, "orientationW" );
  29. }
  30. void CDmeTransformOperator::OnDestruction()
  31. {
  32. }
  33. //-----------------------------------------------------------------------------
  34. // Purpose:
  35. //-----------------------------------------------------------------------------
  36. void CDmeTransformOperator::Operate()
  37. {
  38. CDmeTransform *pTransform = m_transform.GetElement();
  39. if ( pTransform == NULL )
  40. return;
  41. Vector position = pTransform->GetValue< Vector >( TRANSFORM_POSITION );
  42. Quaternion orientation = pTransform->GetValue< Quaternion >( TRANSFORM_ORIENTATION );
  43. position.x = m_positionX.Get();
  44. position.y = m_positionY.Get();
  45. position.z = m_positionZ.Get();
  46. orientation.x = m_orientationX.Get();
  47. orientation.y = m_orientationY.Get();
  48. orientation.z = m_orientationZ.Get();
  49. orientation.w = m_orientationW.Get();
  50. pTransform->SetValue( TRANSFORM_POSITION, position );
  51. pTransform->SetValue( TRANSFORM_ORIENTATION, orientation );
  52. }
  53. // hack to avoid MSVC complaining about multiply defined symbols
  54. namespace TransformOp
  55. {
  56. void AddAttr( CUtlVector< CDmAttribute * > &attrs, CDmAttribute *pAttr )
  57. {
  58. if ( pAttr == NULL )
  59. return;
  60. attrs.AddToTail( pAttr );
  61. }
  62. };
  63. using namespace TransformOp;
  64. void CDmeTransformOperator::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
  65. {
  66. AddAttr( attrs, m_positionX.GetAttribute() );
  67. AddAttr( attrs, m_positionY.GetAttribute() );
  68. AddAttr( attrs, m_positionZ.GetAttribute() );
  69. AddAttr( attrs, m_orientationX.GetAttribute() );
  70. AddAttr( attrs, m_orientationY.GetAttribute() );
  71. AddAttr( attrs, m_orientationZ.GetAttribute() );
  72. AddAttr( attrs, m_orientationW.GetAttribute() );
  73. }
  74. void CDmeTransformOperator::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
  75. {
  76. CDmeTransform *pTransform = m_transform.GetElement();
  77. if ( pTransform == NULL )
  78. return;
  79. AddAttr( attrs, pTransform->GetAttribute( TRANSFORM_POSITION ) );
  80. AddAttr( attrs, pTransform->GetAttribute( TRANSFORM_ORIENTATION ) );
  81. }
  82. void CDmeTransformOperator::SetTransform( CDmeTransform *pTransform )
  83. {
  84. m_transform.Set( pTransform );
  85. }
  86. const CDmeTransform *CDmeTransformOperator::GetTransform() const
  87. {
  88. return m_transform.GetElement();
  89. }