void CreateSpurtParticles( void ) { SimpleParticle *pParticle; // PMaterialHandle hMaterial = GetPMaterial( "particle/particle_smokegrenade" ); Vector vecOrigin = m_vSortOrigin; IClientRenderable *pRenderable = ClientEntityList().GetClientRenderableFromHandle(m_hEntity); if ( pRenderable && m_nAttachmentIndex ) { QAngle tmp; pRenderable->GetAttachment( m_nAttachmentIndex, vecOrigin, tmp ); SetSortOrigin( vecOrigin ); } // Smoke int numParticles = RandomInt( 1,2 ); for ( int i = 0; i < numParticles; i++ ) { pParticle = (SimpleParticle *) AddParticle( sizeof( SimpleParticle ), g_Mat_DustPuff[0], vecOrigin ); if ( pParticle == NULL ) break; pParticle->m_flLifetime = 0.0f; pParticle->m_flDieTime = RandomFloat( 0.5, 1.0 ); // Random velocity around the angles forward Vector vecVelocity; vecVelocity.Random( -0.1f, 0.1f ); vecVelocity += m_vecSpurtForward; VectorNormalize( vecVelocity ); vecVelocity *= RandomFloat( 160.0f, 640.0f ); pParticle->m_vecVelocity = vecVelocity; // Randomize the color a little int color[3][2]; for( int i = 0; i < 3; ++i ) { color[i][0] = MAX( 0, m_SpurtColor[i] - 64 ); color[i][1] = MIN( 255, m_SpurtColor[i] + 64 ); } pParticle->m_uchColor[0] = random->RandomInt( color[0][0], color[0][1] ); pParticle->m_uchColor[1] = random->RandomInt( color[1][0], color[1][1] ); pParticle->m_uchColor[2] = random->RandomInt( color[2][0], color[2][1] ); pParticle->m_uchStartAlpha = m_SpurtColor[3]; pParticle->m_uchEndAlpha = 0; pParticle->m_uchStartSize = RandomInt( 50, 60 ); pParticle->m_uchEndSize = pParticle->m_uchStartSize*3; pParticle->m_flRoll = RandomFloat( 0, 360 ); pParticle->m_flRollDelta = RandomFloat( -4.0f, 4.0f ); } m_flLastParticleSpawnTime = gpGlobals->curtime + m_flSpawnRate; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- Vector GetTracerOrigin( const CEffectData &data ) { Vector vecStart = data.m_vStart; QAngle vecAngles; int iAttachment = data.m_nAttachmentIndex;; // Attachment? if ( data.m_fFlags & TRACER_FLAG_USEATTACHMENT ) { C_BaseViewModel *pViewModel = NULL; // If the entity specified is a weapon being carried by this player, use the viewmodel instead IClientRenderable *pRenderable = data.GetRenderable(); if ( !pRenderable ) return vecStart; C_BaseEntity *pEnt = data.GetEntity(); FOR_EACH_VALID_SPLITSCREEN_PLAYER( hh ) { ACTIVE_SPLITSCREEN_PLAYER_GUARD( hh ); C_BaseCombatWeapon *pWpn = ToBaseCombatWeapon( pEnt ); if ( pWpn && pWpn->IsCarriedByLocalPlayer() ) { C_BasePlayer *player = ToBasePlayer( pWpn->GetOwner() ); if( !player && pWpn->GetOwner() && pWpn->GetOwner()->IsUnit() ) { player = pWpn->GetOwner()->MyUnitPointer()->GetCommander(); } pViewModel = player ? player->GetViewModel( 0 ) : NULL; if ( pViewModel ) { // Get the viewmodel and use it instead pRenderable = pViewModel; break; } } } // Get the attachment origin if ( !pRenderable->GetAttachment( iAttachment, vecStart, vecAngles ) ) { DevMsg( "GetTracerOrigin: Couldn't find attachment %d on model %s\n", iAttachment, modelinfo->GetModelName( pRenderable->GetModel() ) ); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- Vector GetTracerOrigin( const CEffectData &data ) { Vector vecStart = data.m_vStart; QAngle vecAngles; int iAttachment = data.m_nAttachmentIndex;; // Attachment? if ( data.m_fFlags & TRACER_FLAG_USEATTACHMENT ) { C_BaseViewModel *pViewModel = NULL; // If the entity specified is a weapon being carried by this player, use the viewmodel instead IClientRenderable *pRenderable = data.GetRenderable(); if ( !pRenderable ) return vecStart; C_BaseEntity *pEnt = data.GetEntity(); // This check should probably be for all multiplayer games, investigate later #if defined( HL2MP ) || defined( TF_CLIENT_DLL ) || defined( TF_CLASSIC_CLIENT ) if ( pEnt && pEnt->IsDormant() ) return vecStart; #endif C_BaseCombatWeapon *pWpn = dynamic_cast<C_BaseCombatWeapon *>( pEnt ); if ( pWpn && pWpn->ShouldDrawUsingViewModel() ) { C_BasePlayer *player = ToBasePlayer( pWpn->GetOwner() ); // Use GetRenderedWeaponModel() instead? pViewModel = player ? player->GetViewModel( 0 ) : NULL; if ( pViewModel ) { // Get the viewmodel and use it instead pRenderable = pViewModel; } } // Get the attachment origin if ( !pRenderable->GetAttachment( iAttachment, vecStart, vecAngles ) ) { DevMsg( "GetTracerOrigin: Couldn't find attachment %d on model %s\n", iAttachment, modelinfo->GetModelName( pRenderable->GetModel() ) ); } } return vecStart; }
//----------------------------------------------------------------------------- // Purpose: // Input : &data - //----------------------------------------------------------------------------- void CrosshairLoadCallback2( const CEffectData &data ) { IClientRenderable *pRenderable = data.GetRenderable( ); if ( !pRenderable ) return; Vector position; QAngle angles; // If we found the attachment, emit sparks there if ( pRenderable->GetAttachment( data.m_nAttachmentIndex, position, angles ) ) { FX_ElectricSpark( position, 1.0f, 1.0f, NULL ); } }
//----------------------------------------------------------------------------- // Purpose: // Input : entityIndex - // attachmentIndex - // *origin - // *angles - // Output : Returns true on success, false on failure. //----------------------------------------------------------------------------- bool FX_GetAttachmentTransform( ClientEntityHandle_t hEntity, int attachmentIndex, Vector *origin, QAngle *angles ) { // Validate our input if ( ( hEntity == INVALID_EHANDLE_INDEX ) || ( attachmentIndex < 1 ) ) { if ( origin != NULL ) { *origin = vec3_origin; } if ( angles != NULL ) { *angles = QAngle(0,0,0); } return false; } // Get the actual entity IClientRenderable *pRenderable = ClientEntityList().GetClientRenderableFromHandle( hEntity ); if ( pRenderable ) { Vector attachOrigin; QAngle attachAngles; // Find the attachment's matrix pRenderable->GetAttachment( attachmentIndex, attachOrigin, attachAngles ); if ( origin != NULL ) { *origin = attachOrigin; } if ( angles != NULL ) { *angles = attachAngles; } return true; } return false; }
//----------------------------------------------------------------------------- // Old-style muzzle flashes //----------------------------------------------------------------------------- void MuzzleFlashCallback( const CEffectData &data ) { Vector vecOrigin = data.m_vOrigin; QAngle vecAngles = data.m_vAngles; if ( data.entindex() > 0 ) { IClientRenderable *pRenderable = data.GetRenderable(); if ( !pRenderable ) return; if ( data.m_nAttachmentIndex ) { //FIXME: We also need to allocate these particles into an attachment space setup pRenderable->GetAttachment( data.m_nAttachmentIndex, vecOrigin, vecAngles ); } else { vecOrigin = pRenderable->GetRenderOrigin(); vecAngles = pRenderable->GetRenderAngles(); } } tempents->MuzzleFlash( vecOrigin, vecAngles, data.m_fFlags & (~MUZZLEFLASH_FIRSTPERSON), data.m_hEntity, (data.m_fFlags & MUZZLEFLASH_FIRSTPERSON) != 0 ); }
//----------------------------------------------------------------------------- // Purpose: Create the matrix by which we'll transform the particle's local // space into world space, via the attachment's transform //----------------------------------------------------------------------------- void CLocalSpaceEmitter::SetupTransformMatrix( void ) { IClientRenderable *pRenderable = ClientEntityList().GetClientRenderableFromHandle( m_hEntity ); if ( pRenderable ) { matrix3x4_t mat; if ( pRenderable->GetAttachment( m_nAttachment, mat ) == false ) { // This attachment is bogus! Assert(0); } // Tell the particle effect so it knows Vector origin; MatrixGetColumn( mat, 3, origin ); m_ParticleEffect.SetLocalSpaceTransform( mat ); SetSortOrigin( origin ); C_BaseEntity *pEnt = pRenderable->GetIClientUnknown()->GetBaseEntity(); if ( pEnt ) { Vector vWorldMins, vWorldMaxs; float scale = pEnt->CollisionProp()->BoundingRadius(); vWorldMins[0] = origin[0] - scale; vWorldMins[1] = origin[1] - scale; vWorldMins[2] = origin[2] - scale; vWorldMaxs[0] = origin[0] + scale; vWorldMaxs[1] = origin[1] + scale; vWorldMaxs[2] = origin[2] + scale; GetBinding().SetBBox( vWorldMins, vWorldMaxs, true ); } } // We preapply the local transform because we need to squash it for viewmodel FOV. m_ParticleEffect.SetAutoApplyLocalTransform( false ); }