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.

91 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/imaterialvar.h"
  10. #include "materialsystem/imaterial.h"
  11. #include "view.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. //-----------------------------------------------------------------------------
  15. // Purpose: Used for 'card' beams on lamps, this material fades the sprite out
  16. // as the viewer nears, so that the viewer can't see that the effect is really
  17. // a card.
  18. //-----------------------------------------------------------------------------
  19. class CLampBeamProxy : public CEntityMaterialProxy
  20. {
  21. public:
  22. CLampBeamProxy( void );
  23. virtual ~CLampBeamProxy( void );
  24. virtual bool Init( IMaterial *pMaterial, KeyValues* pKeyValues );
  25. virtual void OnBind( C_BaseEntity *pC_BaseEntity );
  26. virtual IMaterial * GetMaterial();
  27. private:
  28. IMaterialVar *m_pFadeValue;
  29. };
  30. //-----------------------------------------------------------------------------
  31. // Purpose:
  32. //-----------------------------------------------------------------------------
  33. CLampBeamProxy::CLampBeamProxy( void )
  34. {
  35. m_pFadeValue = NULL;
  36. }
  37. //-----------------------------------------------------------------------------
  38. // Purpose:
  39. //-----------------------------------------------------------------------------
  40. CLampBeamProxy::~CLampBeamProxy( void )
  41. {
  42. }
  43. //-----------------------------------------------------------------------------
  44. // Purpose: Get pointer to the color value
  45. // Input : *pMaterial -
  46. //-----------------------------------------------------------------------------
  47. bool CLampBeamProxy::Init( IMaterial *pMaterial, KeyValues* pKeyValues )
  48. {
  49. assert( pMaterial );
  50. // Need to get the color variable.
  51. bool found;
  52. m_pFadeValue = pMaterial->FindVar( "$alpha", &found );
  53. return found;
  54. }
  55. //-----------------------------------------------------------------------------
  56. // Purpose:
  57. // Input : *pC_BaseEntity -
  58. //-----------------------------------------------------------------------------
  59. #define FADE_DIST 150
  60. void CLampBeamProxy::OnBind( C_BaseEntity *pEnt )
  61. {
  62. if ( !m_pFadeValue )
  63. return;
  64. Vector vecLocal = pEnt->GetAbsOrigin() - CurrentViewOrigin();
  65. VectorNormalize( vecLocal );
  66. float fade = 1.0 - fabs( vecLocal.z );
  67. m_pFadeValue->SetFloatValue( fade );
  68. }
  69. IMaterial *CLampBeamProxy::GetMaterial()
  70. {
  71. if ( !m_pFadeValue )
  72. return NULL;
  73. return m_pFadeValue->GetOwningMaterial();
  74. }
  75. EXPOSE_INTERFACE( CLampBeamProxy, IMaterialProxy, "lampbeam" IMATERIAL_PROXY_INTERFACE_VERSION );