diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /game/client/fx_cube.cpp | |
| download | archived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.tar.xz archived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.zip | |
Diffstat (limited to 'game/client/fx_cube.cpp')
| -rw-r--r-- | game/client/fx_cube.cpp | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/game/client/fx_cube.cpp b/game/client/fx_cube.cpp new file mode 100644 index 0000000..6532f63 --- /dev/null +++ b/game/client/fx_cube.cpp @@ -0,0 +1,136 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "cbase.h" +#include "clientsideeffects.h" +#include "materialsystem/imaterial.h" +#include "materialsystem/imesh.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +class FX_Cube : public CClientSideEffect +{ +public: + FX_Cube(IMaterial *pMaterial) : CClientSideEffect("FX_Cube") + { + m_pMaterial = pMaterial; + if(m_pMaterial) + m_pMaterial->IncrementReferenceCount(); + } + + virtual ~FX_Cube() + { + if(m_pMaterial) + m_pMaterial->DecrementReferenceCount(); + + } + + void SetupVec(Vector& v, int dim1, int dim2, int fixedDim, float dim1Val, float dim2Val, float fixedDimVal) + { + v[dim1] = dim1Val; + v[dim2] = dim2Val; + v[fixedDim] = fixedDimVal; + } + + void DrawBoxSide( + int dim1, int dim2, int fixedDim, + float minX, float minY, + float maxX, float maxY, + float fixedDimVal, + bool bFlip, + float shade) + { + Vector v; + Vector color; + VectorScale( m_vColor, shade, color ); + + CMatRenderContextPtr pRenderContext( materials ); + IMesh *pMesh = pRenderContext->GetDynamicMesh(); + + CMeshBuilder builder; + builder.Begin(pMesh, MATERIAL_TRIANGLE_STRIP, 2); + + SetupVec(v, dim1, dim2, fixedDim, minX, maxY, fixedDimVal); + builder.Position3fv(v.Base()); + builder.Color3fv(color.Base()); + builder.AdvanceVertex(); + + SetupVec(v, dim1, dim2, fixedDim, bFlip ? maxX : minX, bFlip ? maxY : minY, fixedDimVal); + builder.Position3fv(v.Base()); + builder.Color3fv(color.Base()); + builder.AdvanceVertex(); + + SetupVec(v, dim1, dim2, fixedDim, bFlip ? minX : maxX, bFlip ? minY : maxY, fixedDimVal); + builder.Position3fv(v.Base()); + builder.Color3fv(color.Base()); + builder.AdvanceVertex(); + + SetupVec(v, dim1, dim2, fixedDim, maxX, minY, fixedDimVal); + builder.Position3fv(v.Base()); + builder.Color3fv(color.Base()); + builder.AdvanceVertex(); + + builder.End(); + pMesh->Draw(); + } + + virtual void Draw( double frametime ) + { + CMatRenderContextPtr pRenderContext( materials ); + // Draw it. + pRenderContext->Bind( m_pMaterial ); + + Vector vLightDir(-1,-2,-3); + VectorNormalize( vLightDir ); + + 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); + 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); + + 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); + 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); + + 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); + 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); + + // Decrease lifetime. + m_Life -= frametime; + } + + bool IsActive( void ) + { + return m_Life > 0.0; + } + +public: + Vector m_mins; + Vector m_maxs; + Vector m_vColor; + float m_Life; + IMaterial *m_pMaterial; +}; + + +void FX_AddCube( const Vector &mins, const Vector &maxs, const Vector &vColor, float life, const char *materialName ) +{ + IMaterial *mat = materials->FindMaterial(materialName, TEXTURE_GROUP_CLIENT_EFFECTS); + + FX_Cube *pCube = new FX_Cube(mat); + pCube->m_mins = mins; + pCube->m_maxs = maxs; + pCube->m_vColor = vColor; + pCube->m_Life = life; + + clienteffects->AddEffect(pCube); +} + +void FX_AddCenteredCube( const Vector ¢er, float size, const Vector &vColor, float life, const char *materialName ) +{ + FX_AddCube(center-Vector(size,size,size), center+Vector(size,size,size), vColor, life, materialName); +} + + |