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.

195 lines
5.4 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "foundryhelpers_client.h"
  8. #include "c_basetempentity.h"
  9. #include "tier2/beamsegdraw.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. static CUtlVector<EHANDLE> g_EntityHighlightEffects;
  13. static ConVar cl_foundry_ShowEntityHighlights( "cl_foundry_ShowEntityHighlights", "1" );
  14. void AddCoolLine( const Vector &v1, const Vector &v2, unsigned long iExtraFadeOffset, bool bNegateMovementDir )
  15. {
  16. float flLineSectionLength = 3; // How many inches each line travels. Each line is a solid color and alpha.
  17. int nLineSectionsToFade = 2; // How many lines to fade from translucent to opaque.
  18. int baseColor[3] = { 216, 183, 67 }; // gold
  19. float flTimeBetweenUpdates = 0.2f;
  20. unsigned long iLineFadeOffset = iExtraFadeOffset + (int)(gpGlobals->curtime / flTimeBetweenUpdates);
  21. if ( bNegateMovementDir )
  22. iLineFadeOffset = 0xFFFFFFFF - iLineFadeOffset;
  23. Vector vDelta = v2 - v1;
  24. float flLineLen = vDelta.Length();
  25. vDelta /= flLineLen;
  26. int nMaxLines = (int)(flLineLen / flLineSectionLength) + 1;
  27. static IMaterial *pWireframeMaterial = NULL;
  28. if ( !pWireframeMaterial )
  29. pWireframeMaterial = materials->FindMaterial( "debug/debugwireframevertexcolor", TEXTURE_GROUP_OTHER );
  30. static IMaterial *pBeamMaterial = NULL;
  31. if ( !pBeamMaterial )
  32. pBeamMaterial = materials->FindMaterial( "effects/laser1", TEXTURE_GROUP_OTHER );
  33. CMatRenderContextPtr pRenderContext( materials );
  34. // Draw the solid underlying lines.
  35. IMesh* pMesh = pRenderContext->GetDynamicMesh( true, NULL, NULL, pWireframeMaterial );
  36. CMeshBuilder meshBuilder;
  37. meshBuilder.Begin( pMesh, MATERIAL_LINES, 1 );
  38. meshBuilder.Position3fv( v1.Base() );
  39. meshBuilder.Color4ub( baseColor[0], baseColor[1], baseColor[2], 255 );
  40. meshBuilder.AdvanceVertex();
  41. meshBuilder.Position3fv( v2.Base() );
  42. meshBuilder.Color4ub( baseColor[0], baseColor[1], baseColor[2], 255 );
  43. meshBuilder.AdvanceVertex();
  44. meshBuilder.End( false, true );
  45. // Draw the additive beams.
  46. float flCurDist = 0;
  47. Vector vStartPos = v1;
  48. for ( int i=0; i < nMaxLines; i++ )
  49. {
  50. float flEndDist = MIN( flCurDist + flLineSectionLength, flLineLen );
  51. Vector vEndPos = v1 + vDelta * flEndDist;
  52. int alpha;
  53. int iFadeAmt = (iLineFadeOffset+i) % (nLineSectionsToFade * 2);
  54. if ( iFadeAmt < nLineSectionsToFade )
  55. alpha = (iFadeAmt * 255) / nLineSectionsToFade;
  56. else
  57. alpha = (255 * (nLineSectionsToFade - (iFadeAmt - nLineSectionsToFade))) / nLineSectionsToFade;
  58. float flAlpha = Bias( alpha / 255.0f, 0.6 );
  59. CBeamSegDraw beamDraw;
  60. beamDraw.Start( pRenderContext, 2, pBeamMaterial );
  61. BeamSeg_t beamSeg;
  62. beamSeg.SetColor( baseColor[0] * flAlpha / 255.0f, baseColor[1] * flAlpha / 255.0f, baseColor[2] * flAlpha / 255.0f, 1.0f );
  63. beamSeg.m_flTexCoord = 0;
  64. beamSeg.m_flWidth = 6;
  65. beamSeg.m_vPos = vStartPos;
  66. beamDraw.NextSeg( &beamSeg );
  67. beamSeg.m_vPos = vEndPos;
  68. beamDraw.NextSeg( &beamSeg );
  69. beamDraw.End();
  70. flCurDist = flEndDist;
  71. vStartPos = vEndPos;
  72. }
  73. }
  74. void FoundryHelpers_DrawEntityHighlightEffect( C_BaseEntity *pEnt )
  75. {
  76. CCollisionProperty *pCollision = pEnt->CollisionProp();
  77. // Transform the OBB corners into world space.
  78. const Vector &vMins = pCollision->OBBMins();
  79. const Vector &vMaxs = pCollision->OBBMaxs();
  80. Vector vPoints[8] =
  81. {
  82. Vector( vMins.x, vMins.y, vMins.z ),
  83. Vector( vMaxs.x, vMins.y, vMins.z ),
  84. Vector( vMaxs.x, vMaxs.y, vMins.z ),
  85. Vector( vMins.x, vMaxs.y, vMins.z ),
  86. Vector( vMins.x, vMins.y, vMaxs.z ),
  87. Vector( vMaxs.x, vMins.y, vMaxs.z ),
  88. Vector( vMaxs.x, vMaxs.y, vMaxs.z ),
  89. Vector( vMins.x, vMaxs.y, vMaxs.z )
  90. };
  91. for ( int i=0; i < 8; i++ )
  92. {
  93. Vector vTmp;
  94. vPoints[i] = pCollision->CollisionToWorldSpace( vPoints[i], &vTmp );
  95. }
  96. // Draw lines connecting them up...
  97. for ( int i=0; i < 4; i++ )
  98. {
  99. AddCoolLine( vPoints[i], vPoints[(i+1)%4], 0, false );
  100. AddCoolLine( vPoints[i+4], vPoints[(i+1)%4 + 4], 4, true );
  101. AddCoolLine( vPoints[i], vPoints[i+4], i*2+4, (i%1) == 0 );
  102. }
  103. }
  104. void FoundryHelpers_DrawAll()
  105. {
  106. if ( cl_foundry_ShowEntityHighlights.GetBool() )
  107. {
  108. for ( int i=0; i < g_EntityHighlightEffects.Count(); i++ )
  109. {
  110. C_BaseEntity *pEnt = g_EntityHighlightEffects[i];
  111. if ( !pEnt )
  112. continue;
  113. FoundryHelpers_DrawEntityHighlightEffect( pEnt );
  114. }
  115. }
  116. }
  117. void FoundryHelpers_ClearEntityHighlightEffects()
  118. {
  119. g_EntityHighlightEffects.Purge();
  120. }
  121. void FoundryHelpers_AddEntityHighlightEffect( int iEntity )
  122. {
  123. EHANDLE hEnt = cl_entitylist->GetBaseEntity( iEntity );
  124. if ( hEnt.IsValid() )
  125. g_EntityHighlightEffects.AddToTail( hEnt );
  126. }
  127. //-----------------------------------------------------------------------------
  128. // Purpose: This marshalls calls from the server to the client.
  129. //-----------------------------------------------------------------------------
  130. class C_TEFoundryHelpers : public C_BaseTempEntity
  131. {
  132. public:
  133. DECLARE_CLASS( C_TEFoundryHelpers, C_BaseTempEntity );
  134. DECLARE_CLIENTCLASS();
  135. virtual void PostDataUpdate( DataUpdateType_t updateType );
  136. int m_iEntity;
  137. };
  138. void C_TEFoundryHelpers::PostDataUpdate( DataUpdateType_t updateType )
  139. {
  140. if ( m_iEntity == -1 )
  141. FoundryHelpers_ClearEntityHighlightEffects();
  142. else
  143. FoundryHelpers_AddEntityHighlightEffect( m_iEntity );
  144. }
  145. IMPLEMENT_CLIENTCLASS_EVENT_DT( C_TEFoundryHelpers, DT_TEFoundryHelpers, CTEFoundryHelpers )
  146. RecvPropInt( RECVINFO(m_iEntity) )
  147. END_RECV_TABLE()