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.

142 lines
3.9 KiB

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