From 39ed87570bdb2f86969d4be821c94b722dc71179 Mon Sep 17 00:00:00 2001 From: Joe Ludwig Date: Wed, 26 Jun 2013 15:22:04 -0700 Subject: First version of the SOurce SDK 2013 --- mp/src/game/client/particle_simple3d.cpp | 134 +++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 mp/src/game/client/particle_simple3d.cpp (limited to 'mp/src/game/client/particle_simple3d.cpp') diff --git a/mp/src/game/client/particle_simple3d.cpp b/mp/src/game/client/particle_simple3d.cpp new file mode 100644 index 00000000..c547db56 --- /dev/null +++ b/mp/src/game/client/particle_simple3d.cpp @@ -0,0 +1,134 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Workfile: $ +// $NoKeywords: $ +//=============================================================================// +#include "cbase.h" +#include "particle_simple3d.h" +#include "view.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +// Defined in pm_math.c +float anglemod( float a ); + +//------------------------------------------------------------------------------ +// Purpose : +// Input : +// Output : +//------------------------------------------------------------------------------ +CSmartPtr CSimple3DEmitter::Create( const char *pDebugName ) +{ + CSimple3DEmitter* pSimple3DEmitter = new CSimple3DEmitter( pDebugName ); + + // Do in world space + pSimple3DEmitter->m_ParticleEffect.SetEffectCameraSpace( false ); + return pSimple3DEmitter; +} + + +void CSimple3DEmitter::SimulateParticles( CParticleSimulateIterator *pIterator ) +{ + Particle3D *pParticle = (Particle3D*)pIterator->GetFirst(); + while ( pParticle ) + { + const float timeDelta = pIterator->GetTimeDelta(); + + //Should this particle die? + pParticle->m_flLifeRemaining -= timeDelta; + + if ( pParticle->IsDead() ) + { + pIterator->RemoveParticle( pParticle ); + } + else + { + // Angular rotation + pParticle->m_vAngles.x += pParticle->m_flAngSpeed * timeDelta; + pParticle->m_vAngles.y += pParticle->m_flAngSpeed * timeDelta; + pParticle->m_vAngles.z += pParticle->m_flAngSpeed * timeDelta; + + //Simulate the movement with collision + trace_t trace; + m_ParticleCollision.MoveParticle( pParticle->m_Pos, pParticle->m_vecVelocity, &pParticle->m_flAngSpeed, timeDelta, &trace ); + + // --------------------------------------- + // Decay towards flat + // --------------------------------------- + if (pParticle->m_flAngSpeed == 0 || trace.fraction != 1.0) + { + pParticle->m_vAngles.x = anglemod(pParticle->m_vAngles.x); + if (pParticle->m_vAngles.x < 180) + { + if (fabs(pParticle->m_vAngles.x - 90) > 0.5) + { + pParticle->m_vAngles.x = 0.5*pParticle->m_vAngles.x + 46; + } + } + else + { + if (fabs(pParticle->m_vAngles.x - 270) > 0.5) + { + pParticle->m_vAngles.x = 0.5*pParticle->m_vAngles.x + 135; + } + } + + pParticle->m_vAngles.y = anglemod(pParticle->m_vAngles.y); + if (fabs(pParticle->m_vAngles.y) > 0.5) + { + pParticle->m_vAngles.y = 0.5*pParticle->m_vAngles.z; + } + } + } + + pParticle = (Particle3D*)pIterator->GetNext(); + } +} + + +void CSimple3DEmitter::RenderParticles( CParticleRenderIterator *pIterator ) +{ + const Particle3D *pParticle = (const Particle3D *)pIterator->GetFirst(); + while ( pParticle ) + { + float sortKey = CurrentViewForward().Dot( CurrentViewOrigin() - pParticle->m_Pos ); + + // ------------------------------------------------------- + // Set color based on direction towards camera + // ------------------------------------------------------- + Vector color; + Vector vFaceNorm; + Vector vCameraToFace = (pParticle->m_Pos - CurrentViewOrigin()); + AngleVectors(pParticle->m_vAngles,&vFaceNorm); + float flFacing = DotProduct(vCameraToFace,vFaceNorm); + + if (flFacing <= 0) + { + color[0] = pParticle->m_uchFrontColor[0] / 255.0f; + color[1] = pParticle->m_uchFrontColor[1] / 255.0f; + color[2] = pParticle->m_uchFrontColor[2] / 255.0f; + } + else + { + color[0] = pParticle->m_uchBackColor[0] / 255.0f; + color[1] = pParticle->m_uchBackColor[1] / 255.0f; + color[2] = pParticle->m_uchBackColor[2] / 255.0f; + } + + //Render it in world space + RenderParticle_ColorSizeAngles( + pIterator->GetParticleDraw(), + pParticle->m_Pos, + color, + pParticle->GetFadeFraction(), + pParticle->m_uchSize, + pParticle->m_vAngles); + + pParticle = (const Particle3D *)pIterator->GetNext( sortKey ); + } +} + + -- cgit v1.2.3