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.

110 lines
2.7 KiB

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