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.

105 lines
2.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "proxyentity.h"
  9. #include "materialsystem/imaterial.h"
  10. #include "materialsystem/imaterialvar.h"
  11. void HueToRGB( float frac, Vector& color );
  12. // $ThermalVar : name of variable to run Thermal wave on (can either be a color or a float)
  13. // $ThermalPeriod: time that it takes to go through whole Thermal wave in seconds (default: 1.0f)
  14. // $ThermalMax : the max value for the Thermal wave (default: 1.0f )
  15. // $ThermalMin: the min value for the Thermal wave (default: 0.0f )
  16. class CThermalMaterialProxy : public CEntityMaterialProxy
  17. {
  18. public:
  19. CThermalMaterialProxy();
  20. virtual ~CThermalMaterialProxy();
  21. virtual bool Init( IMaterial *pMaterial, KeyValues* pKeyValues );
  22. virtual void OnBind( C_BaseEntity *pEntity );
  23. private:
  24. IMaterialVar *m_ThermalVar;
  25. IMaterialVar *m_ThermalPeriod;
  26. IMaterialVar *m_ThermalMax;
  27. IMaterialVar *m_ThermalMin;
  28. };
  29. CThermalMaterialProxy::CThermalMaterialProxy()
  30. {
  31. m_ThermalVar = NULL;
  32. m_ThermalPeriod = NULL;
  33. m_ThermalMax = NULL;
  34. m_ThermalMin = NULL;
  35. }
  36. CThermalMaterialProxy::~CThermalMaterialProxy()
  37. {
  38. }
  39. bool CThermalMaterialProxy::Init( IMaterial *pMaterial, KeyValues* pKeyValues )
  40. {
  41. bool foundVar;
  42. m_ThermalVar = pMaterial->FindVar( "$color", &foundVar, false );
  43. if( !foundVar )
  44. {
  45. m_ThermalVar = NULL;
  46. return false;
  47. }
  48. m_ThermalPeriod = pMaterial->FindVar( "$ThermalPeriod", &foundVar, false );
  49. if( !foundVar )
  50. {
  51. m_ThermalPeriod = NULL;
  52. }
  53. m_ThermalMax = pMaterial->FindVar( "$ThermalMax", &foundVar, false );
  54. if( !foundVar )
  55. {
  56. m_ThermalMax = NULL;
  57. }
  58. m_ThermalMin = pMaterial->FindVar( "$ThermalMin", &foundVar, false );
  59. if( !foundVar )
  60. {
  61. m_ThermalMin = NULL;
  62. }
  63. return true;
  64. }
  65. void CThermalMaterialProxy::OnBind( C_BaseEntity *pEntity )
  66. {
  67. // FIXME, enable this later
  68. return;
  69. if( !m_ThermalVar )
  70. {
  71. return;
  72. }
  73. float min, max, period, value;
  74. // set default values if these variables don't exist.
  75. min = m_ThermalMin ? m_ThermalMin->GetFloatValue() : 0.0f;
  76. max = m_ThermalMax ? m_ThermalMax->GetFloatValue() : 1.0f;
  77. period = m_ThermalPeriod ? m_ThermalPeriod->GetFloatValue() : 1.0f;
  78. // get a value in [0,1]
  79. value = ( sin( 2.0f * M_PI * gpGlobals->curtime / period ) * 0.5f ) + 0.5f;
  80. // get a value in [min,max]
  81. value = ( max - min ) * value + min;
  82. Vector color;
  83. HueToRGB( 360.f * value, color );
  84. m_ThermalVar->SetVecValue( color[0], color[1], color[2] );
  85. }
  86. EXPOSE_INTERFACE( CThermalMaterialProxy, IMaterialProxy, "Thermal" IMATERIAL_PROXY_INTERFACE_VERSION );