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.

184 lines
4.8 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "view.h"
  8. #include "materialsystem/imesh.h"
  9. #include "fx_quad.h"
  10. #include "tier0/vprof.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. CFXQuad::CFXQuad( const FXQuadData_t &data )
  14. : CClientSideEffect( "Quad" )
  15. {
  16. m_FXData = data;
  17. }
  18. CFXQuad::~CFXQuad( void )
  19. {
  20. Destroy();
  21. }
  22. //-----------------------------------------------------------------------------
  23. // Purpose:
  24. // Input : frametime -
  25. //-----------------------------------------------------------------------------
  26. void CFXQuad::Draw( double frametime )
  27. {
  28. VPROF_BUDGET( "FX_Quad::Draw", VPROF_BUDGETGROUP_PARTICLE_RENDERING );
  29. // Update the effect
  30. Update( frametime );
  31. float scaleTimePerc, alphaTimePerc;
  32. //Determine the scale
  33. if ( m_FXData.m_flDieTime == 0.0f )
  34. {
  35. scaleTimePerc = 1.0f; // don't divide by 0...
  36. }
  37. else
  38. {
  39. if ( m_FXData.m_uiFlags & FXQUAD_BIAS_SCALE )
  40. {
  41. scaleTimePerc = Bias( ( m_FXData.m_flLifeTime / m_FXData.m_flDieTime ), m_FXData.m_flScaleBias );
  42. }
  43. else
  44. {
  45. scaleTimePerc = ( m_FXData.m_flLifeTime / m_FXData.m_flDieTime );
  46. }
  47. }
  48. float scale = m_FXData.m_flStartScale + ( ( m_FXData.m_flEndScale - m_FXData.m_flStartScale ) * scaleTimePerc );
  49. //Determine the alpha
  50. if ( m_FXData.m_flDieTime == 0.0f )
  51. {
  52. alphaTimePerc = 1.0f; // don't divide by 0...
  53. }
  54. else
  55. {
  56. if ( m_FXData.m_uiFlags & FXQUAD_BIAS_ALPHA )
  57. {
  58. alphaTimePerc = Bias( ( m_FXData.m_flLifeTime / m_FXData.m_flDieTime ), m_FXData.m_flAlphaBias );
  59. }
  60. else
  61. {
  62. alphaTimePerc = ( m_FXData.m_flLifeTime / m_FXData.m_flDieTime );
  63. }
  64. }
  65. float alpha = m_FXData.m_flStartAlpha + ( ( m_FXData.m_flEndAlpha - m_FXData.m_flStartAlpha ) * alphaTimePerc );
  66. alpha = clamp( alpha, 0.0f, 1.0f );
  67. CMatRenderContextPtr pRenderContext( materials );
  68. //Bind the material
  69. IMesh* pMesh = pRenderContext->GetDynamicMesh( true, NULL, NULL, m_FXData.m_pMaterial );
  70. CMeshBuilder meshBuilder;
  71. meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );
  72. //Update our roll
  73. m_FXData.m_flYaw = anglemod( m_FXData.m_flYaw + ( m_FXData.m_flDeltaYaw * frametime ) );
  74. Vector pos;
  75. Vector vRight, vUp;
  76. float color[4];
  77. color[0] = m_FXData.m_Color[0];
  78. color[1] = m_FXData.m_Color[1];
  79. color[2] = m_FXData.m_Color[2];
  80. if ( m_FXData.m_uiFlags & FXQUAD_COLOR_FADE )
  81. {
  82. color[0] *= alpha;
  83. color[1] *= alpha;
  84. color[2] *= alpha;
  85. }
  86. color[3] = alpha;
  87. VectorVectors( m_FXData.m_vecNormal, vRight, vUp );
  88. Vector rRight, rUp;
  89. rRight = ( vRight * cos( DEG2RAD( m_FXData.m_flYaw ) ) ) - ( vUp * sin( DEG2RAD( m_FXData.m_flYaw ) ) );
  90. rUp = ( vRight * cos( DEG2RAD( m_FXData.m_flYaw+90.0f ) ) ) - ( vUp * sin( DEG2RAD( m_FXData.m_flYaw+90.0f ) ) );
  91. vRight = rRight * ( scale * 0.5f );
  92. vUp = rUp * ( scale * 0.5f );
  93. pos = m_FXData.m_vecOrigin + vRight - vUp;
  94. meshBuilder.Position3fv( pos.Base() );
  95. meshBuilder.Normal3fv( m_FXData.m_vecNormal.Base() );
  96. meshBuilder.TexCoord2f( 0, 1.0f, 1.0f );
  97. meshBuilder.Color4fv( color );
  98. meshBuilder.AdvanceVertex();
  99. pos = m_FXData.m_vecOrigin - vRight - vUp;
  100. meshBuilder.Position3fv( pos.Base() );
  101. meshBuilder.Normal3fv( m_FXData.m_vecNormal.Base() );
  102. meshBuilder.TexCoord2f( 0, 0.0f, 1.0f );
  103. meshBuilder.Color4fv( color );
  104. meshBuilder.AdvanceVertex();
  105. pos = m_FXData.m_vecOrigin - vRight + vUp;
  106. meshBuilder.Position3fv( pos.Base() );
  107. meshBuilder.Normal3fv( m_FXData.m_vecNormal.Base() );
  108. meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
  109. meshBuilder.Color4fv( color );
  110. meshBuilder.AdvanceVertex();
  111. pos = m_FXData.m_vecOrigin + vRight + vUp;
  112. meshBuilder.Position3fv( pos.Base() );
  113. meshBuilder.Normal3fv( m_FXData.m_vecNormal.Base() );
  114. meshBuilder.TexCoord2f( 0, 1.0f, 0.0f );
  115. meshBuilder.Color4fv( color );
  116. meshBuilder.AdvanceVertex();
  117. meshBuilder.End();
  118. pMesh->Draw();
  119. }
  120. //-----------------------------------------------------------------------------
  121. // Purpose:
  122. // Output : Returns true on success, false on failure.
  123. //-----------------------------------------------------------------------------
  124. bool CFXQuad::IsActive( void )
  125. {
  126. return ( m_FXData.m_flLifeTime < m_FXData.m_flDieTime ) ? true : false;
  127. }
  128. //-----------------------------------------------------------------------------
  129. // Purpose:
  130. //-----------------------------------------------------------------------------
  131. void CFXQuad::Destroy( void )
  132. {
  133. //Release the material
  134. if ( m_FXData.m_pMaterial != NULL )
  135. {
  136. m_FXData.m_pMaterial->DecrementReferenceCount();
  137. m_FXData.m_pMaterial = NULL;
  138. }
  139. }
  140. //-----------------------------------------------------------------------------
  141. // Purpose:
  142. // Input : frametime -
  143. //-----------------------------------------------------------------------------
  144. void CFXQuad::Update( double frametime )
  145. {
  146. m_FXData.m_flLifeTime += frametime;
  147. }