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.

139 lines
3.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "particle_litsmokeemitter.h"
  8. //
  9. // CLitSmokeEmitter
  10. //
  11. CLitSmokeEmitter::CLitSmokeEmitter( const char *pDebugName ) : CSimpleEmitter( pDebugName )
  12. {
  13. m_bInitted = false;
  14. m_hSmokeMaterial = INVALID_MATERIAL_HANDLE;
  15. }
  16. //-----------------------------------------------------------------------------
  17. // Purpose:
  18. // Input : *materialName -
  19. //-----------------------------------------------------------------------------
  20. void CLitSmokeEmitter::Init( const char *materialName, Vector sortOrigin )
  21. {
  22. m_hSmokeMaterial = GetPMaterial( materialName );
  23. IMaterial *pMaterial = ParticleMgr()->PMaterialToIMaterial( m_hSmokeMaterial );
  24. if ( pMaterial )
  25. {
  26. m_Renderer.Init( ParticleMgr(), pMaterial );
  27. }
  28. SetSortOrigin( sortOrigin );
  29. m_bInitted = true;
  30. }
  31. //-----------------------------------------------------------------------------
  32. // Purpose:
  33. // Input : position -
  34. // color -
  35. //-----------------------------------------------------------------------------
  36. void CLitSmokeEmitter::SetDirectionalLight( Vector position, Vector color, float intensity )
  37. {
  38. CParticleLightInfo info;
  39. info.m_flIntensity = intensity;
  40. info.m_vColor = color;
  41. info.m_vPos = position;
  42. m_Renderer.SetDirectionalLight( info );
  43. }
  44. //-----------------------------------------------------------------------------
  45. // Purpose:
  46. // Input : position -
  47. // color -
  48. // intensity -
  49. //-----------------------------------------------------------------------------
  50. void CLitSmokeEmitter::SetLight( Vector position, Vector color, float intensity )
  51. {
  52. CParticleLightInfo info;
  53. info.m_flIntensity = intensity;
  54. info.m_vColor = color;
  55. info.m_vPos = position;
  56. m_Renderer.SetAmbientLight( info );
  57. }
  58. //-----------------------------------------------------------------------------
  59. // Purpose:
  60. // Input : flTimeDelta -
  61. //-----------------------------------------------------------------------------
  62. void CLitSmokeEmitter::Update( float flTimeDelta )
  63. {
  64. if ( flTimeDelta > 0.0f )
  65. {
  66. //m_Renderer.DirectionalLight().m_vColor *= 0.9f;
  67. }
  68. CSimpleEmitter::Update( flTimeDelta );
  69. }
  70. void CLitSmokeEmitter::StartRender( VMatrix &effectMatrix )
  71. {
  72. m_Renderer.StartRender( effectMatrix );
  73. }
  74. void CLitSmokeEmitter::RenderParticles( CParticleRenderIterator *pIterator )
  75. {
  76. const LitSmokeParticle *pParticle = (const LitSmokeParticle*)pIterator->GetFirst();
  77. while ( pParticle )
  78. {
  79. float tLifetime = pParticle->m_flLifetime / pParticle->m_flDieTime;
  80. // Transform.
  81. Vector tPos;
  82. TransformParticle( ParticleMgr()->GetModelView(), pParticle->m_Pos, tPos );
  83. float sortKey = tPos.z;
  84. float alpha255 = ( ( (float) pParticle->m_uchColor[3]/255.0f ) * sin( M_PI_F * tLifetime ) ) * 255.0f;
  85. Vector color01 = Vector( pParticle->m_uchColor[0], pParticle->m_uchColor[1], pParticle->m_uchColor[2] ) * (tLifetime / 255.0f);
  86. m_Renderer.RenderParticle_AddColor (
  87. pIterator->GetParticleDraw(),
  88. pParticle->m_Pos,
  89. tPos,
  90. alpha255,
  91. FLerp( pParticle->m_uchStartSize, pParticle->m_uchEndSize, tLifetime ),
  92. color01
  93. );
  94. pParticle = (const LitSmokeParticle*)pIterator->GetNext( sortKey );
  95. }
  96. }
  97. void CLitSmokeEmitter::SimulateParticles( CParticleSimulateIterator *pIterator )
  98. {
  99. // Make sure they've called Init().
  100. Assert( m_bInitted );
  101. LitSmokeParticle *pParticle = (LitSmokeParticle*)pIterator->GetFirst();
  102. while ( pParticle )
  103. {
  104. // Should this particle die?
  105. pParticle->m_flLifetime += pIterator->GetTimeDelta();
  106. pParticle->m_Pos = pParticle->m_Pos + ( pParticle->m_vecVelocity * pIterator->GetTimeDelta() );
  107. if ( pParticle->m_flLifetime >= pParticle->m_flDieTime )
  108. pIterator->RemoveParticle( pParticle );
  109. pParticle = (LitSmokeParticle*)pIterator->GetNext();
  110. }
  111. }