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.

136 lines
3.8 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "clientsideeffects.h"
  9. #include "materialsystem/imaterial.h"
  10. #include "materialsystem/imesh.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. class FX_Cube : public CClientSideEffect
  14. {
  15. public:
  16. FX_Cube(IMaterial *pMaterial) : CClientSideEffect("FX_Cube")
  17. {
  18. m_pMaterial = pMaterial;
  19. if(m_pMaterial)
  20. m_pMaterial->IncrementReferenceCount();
  21. }
  22. virtual ~FX_Cube()
  23. {
  24. if(m_pMaterial)
  25. m_pMaterial->DecrementReferenceCount();
  26. }
  27. void SetupVec(Vector& v, int dim1, int dim2, int fixedDim, float dim1Val, float dim2Val, float fixedDimVal)
  28. {
  29. v[dim1] = dim1Val;
  30. v[dim2] = dim2Val;
  31. v[fixedDim] = fixedDimVal;
  32. }
  33. void DrawBoxSide(
  34. int dim1, int dim2, int fixedDim,
  35. float minX, float minY,
  36. float maxX, float maxY,
  37. float fixedDimVal,
  38. bool bFlip,
  39. float shade)
  40. {
  41. Vector v;
  42. Vector color;
  43. VectorScale( m_vColor, shade, color );
  44. CMatRenderContextPtr pRenderContext( materials );
  45. IMesh *pMesh = pRenderContext->GetDynamicMesh();
  46. CMeshBuilder builder;
  47. builder.Begin(pMesh, MATERIAL_TRIANGLE_STRIP, 2);
  48. SetupVec(v, dim1, dim2, fixedDim, minX, maxY, fixedDimVal);
  49. builder.Position3fv(v.Base());
  50. builder.Color3fv(color.Base());
  51. builder.AdvanceVertex();
  52. SetupVec(v, dim1, dim2, fixedDim, bFlip ? maxX : minX, bFlip ? maxY : minY, fixedDimVal);
  53. builder.Position3fv(v.Base());
  54. builder.Color3fv(color.Base());
  55. builder.AdvanceVertex();
  56. SetupVec(v, dim1, dim2, fixedDim, bFlip ? minX : maxX, bFlip ? minY : maxY, fixedDimVal);
  57. builder.Position3fv(v.Base());
  58. builder.Color3fv(color.Base());
  59. builder.AdvanceVertex();
  60. SetupVec(v, dim1, dim2, fixedDim, maxX, minY, fixedDimVal);
  61. builder.Position3fv(v.Base());
  62. builder.Color3fv(color.Base());
  63. builder.AdvanceVertex();
  64. builder.End();
  65. pMesh->Draw();
  66. }
  67. virtual void Draw( double frametime )
  68. {
  69. CMatRenderContextPtr pRenderContext( materials );
  70. // Draw it.
  71. pRenderContext->Bind( m_pMaterial );
  72. Vector vLightDir(-1,-2,-3);
  73. VectorNormalize( vLightDir );
  74. DrawBoxSide(1, 2, 0, m_mins[1], m_mins[2], m_maxs[1], m_maxs[2], m_mins[0], false, vLightDir.x * 0.5f + 0.5f);
  75. DrawBoxSide(1, 2, 0, m_mins[1], m_mins[2], m_maxs[1], m_maxs[2], m_maxs[0], true, -vLightDir.x * 0.5f + 0.5f);
  76. DrawBoxSide(0, 2, 1, m_mins[0], m_mins[2], m_maxs[0], m_maxs[2], m_mins[1], true, vLightDir.y * 0.5f + 0.5f);
  77. DrawBoxSide(0, 2, 1, m_mins[0], m_mins[2], m_maxs[0], m_maxs[2], m_maxs[1], false, -vLightDir.y * 0.5f + 0.5f);
  78. DrawBoxSide(0, 1, 2, m_mins[0], m_mins[1], m_maxs[0], m_maxs[1], m_mins[2], false, vLightDir.z * 0.5f + 0.5f);
  79. DrawBoxSide(0, 1, 2, m_mins[0], m_mins[1], m_maxs[0], m_maxs[1], m_maxs[2], true, -vLightDir.z * 0.5f + 0.5f);
  80. // Decrease lifetime.
  81. m_Life -= frametime;
  82. }
  83. bool IsActive( void )
  84. {
  85. return m_Life > 0.0;
  86. }
  87. public:
  88. Vector m_mins;
  89. Vector m_maxs;
  90. Vector m_vColor;
  91. float m_Life;
  92. IMaterial *m_pMaterial;
  93. };
  94. void FX_AddCube( const Vector &mins, const Vector &maxs, const Vector &vColor, float life, const char *materialName )
  95. {
  96. IMaterial *mat = materials->FindMaterial(materialName, TEXTURE_GROUP_CLIENT_EFFECTS);
  97. FX_Cube *pCube = new FX_Cube(mat);
  98. pCube->m_mins = mins;
  99. pCube->m_maxs = maxs;
  100. pCube->m_vColor = vColor;
  101. pCube->m_Life = life;
  102. clienteffects->AddEffect(pCube);
  103. }
  104. void FX_AddCenteredCube( const Vector &center, float size, const Vector &vColor, float life, const char *materialName )
  105. {
  106. FX_AddCube(center-Vector(size,size,size), center+Vector(size,size,size), vColor, life, materialName);
  107. }