//----------------------------------------------------------------------------- // Purpose: // Input : //----------------------------------------------------------------------------- void CViewModelInvisProxy::OnBind( C_BaseEntity *pEnt ) { if ( !m_pPercentInvisible ) return; if ( !pEnt ) return; C_BaseViewModel *pVM = dynamic_cast<C_BaseViewModel *>( pEnt ); if ( !pVM ) { m_pPercentInvisible->SetFloatValue( 0.0f ); return; } C_TFPlayer *pPlayer = ToTFPlayer( pVM->GetOwner() ); if ( !pPlayer ) { m_pPercentInvisible->SetFloatValue( 0.0f ); return; } float flPercentInvisible = pPlayer->GetPercentInvisible(); // remap from 0.22 to 0.5 // but drop to 0.0 if we're not invis at all float flWeaponInvis = ( flPercentInvisible < 0.01 ) ? 0.0 : RemapVal( flPercentInvisible, 0.0, 1.0, tf_vm_min_invis.GetFloat(), tf_vm_max_invis.GetFloat() ); m_pPercentInvisible->SetFloatValue( flWeaponInvis ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CWarsWeapon::GetShootOriginAndDirection( Vector &vShootOrigin, Vector &vShootDirection) { CBaseEntity *pOwner = GetOwner(); if( !pOwner ) return; CUnitBase *pUnit = pOwner->MyUnitPointer(); if( !pUnit ) return; #if 0 #ifdef CLIENT_DLL if( pUnit->GetCommander() && !ShouldDrawLocalPlayer() ) { QAngle vDummy; C_BasePlayer *player = ToBasePlayer( pUnit->GetCommander() ); C_BaseViewModel *vm = player ? player->GetViewModel( 0 ) : NULL; if ( vm ) { int iAttachment = vm->LookupAttachment( "muzzle" ); if ( vm->GetAttachment( iAttachment, vShootOrigin, vDummy ) ) { AngleVectors( QAngle(pUnit->m_fEyePitch, pUnit->m_fEyeYaw, 0.0), &vShootDirection ); return; } } } #endif // CLIENT_DLL #endif // 0 vShootOrigin = pUnit->Weapon_ShootPosition(); AngleVectors( QAngle(pUnit->m_fEyePitch, pUnit->m_fEyeYaw, 0.0), &vShootDirection ); }
bool C_BaseCombatWeapon::GetShootPosition( Vector &vOrigin, QAngle &vAngles ) { // Get the entity because the weapon doesn't have the right angles. C_BaseCombatCharacter *pEnt = ToBaseCombatCharacter( GetOwner() ); if ( pEnt ) { if ( pEnt == C_BasePlayer::GetLocalPlayer() ) { vAngles = pEnt->EyeAngles(); } else { vAngles = pEnt->GetRenderAngles(); } } else { vAngles.Init(); } C_BasePlayer *player = ToBasePlayer( pEnt ); bool bUseViewModel = false; if ( C_BasePlayer::IsLocalPlayer( pEnt ) ) { ACTIVE_SPLITSCREEN_PLAYER_GUARD_ENT( pEnt ); bUseViewModel = !player->ShouldDrawLocalPlayer(); } QAngle vDummy; if ( IsActiveByLocalPlayer() && bUseViewModel ) { C_BaseViewModel *vm = player ? player->GetViewModel( 0 ) : NULL; if ( vm ) { int iAttachment = vm->LookupAttachment( "muzzle" ); if ( vm->GetAttachment( iAttachment, vOrigin, vDummy ) ) { return true; } } } else { // Thirdperson int iAttachment = LookupAttachment( "muzzle" ); if ( GetAttachment( iAttachment, vOrigin, vDummy ) ) { return true; } } vOrigin = GetRenderOrigin(); return false; }
//----------------------------------------------------------------------------- // get owning weapon (for viewmodels) //----------------------------------------------------------------------------- int CClientTools::GetOwningWeaponEntIndex( int entindex ) { C_BaseEntity *pEnt = C_BaseEntity::Instance( entindex ); C_BaseViewModel *pViewModel = dynamic_cast< C_BaseViewModel* >( pEnt ); if ( pViewModel ) { C_BaseCombatWeapon *pWeapon = pViewModel->GetOwningWeapon(); if ( pWeapon ) { return pWeapon->entindex(); } } return -1; }
bool C_BaseCombatWeapon::GetShootPosition( Vector &vOrigin, QAngle &vAngles ) { // Get the entity because the weapon doesn't have the right angles. C_BaseCombatCharacter *pEnt = ToBaseCombatCharacter( GetOwner() ); if ( pEnt ) { if ( pEnt == C_BasePlayer::GetLocalPlayer() ) { vAngles = pEnt->EyeAngles(); } else { vAngles = pEnt->GetRenderAngles(); } } else { vAngles.Init(); } QAngle vDummy; if ( IsActiveByLocalPlayer() && !input->CAM_IsThirdPerson() ) { C_BasePlayer *player = ToBasePlayer( pEnt ); C_BaseViewModel *vm = player ? player->GetViewModel( 0 ) : NULL; if ( vm ) { int iAttachment = vm->LookupAttachment( "muzzle" ); if ( vm->GetAttachment( iAttachment, vOrigin, vDummy ) ) { return true; } } } else { // Thirdperson int iAttachment = LookupAttachment( "muzzle" ); if ( GetAttachment( iAttachment, vOrigin, vDummy ) ) { return true; } } vOrigin = GetRenderOrigin(); return false; }
void C_BloodyTextureProxy::OnBind(void* pC_BaseEntity) { if (!pC_BaseEntity) return; C_BaseEntity *pEntity = BindArgToEntity(pC_BaseEntity); C_BaseViewModel *pViewModel = dynamic_cast<C_BaseViewModel *>(pEntity); if (pViewModel) { C_BasePlayer *pOwner = ToBasePlayer(pViewModel->GetOwner()); if (pOwner) blendFactor->SetFloatValue(pOwner->m_bShouldDrawBloodOverlay ? 1.0f : 0.0f); } if (ToolsEnabled()) ToolFramework_RecordMaterialParams(GetMaterial()); }
void C_HLTVCamera::CalcInEyeCamView( Vector& eyeOrigin, QAngle& eyeAngles, float& fov ) { C_BasePlayer *pPlayer = UTIL_PlayerByIndex( m_iTraget1 ); if ( !pPlayer ) return; if ( !pPlayer->IsAlive() ) { // if dead, show from 3rd person CalcChaseCamView( eyeOrigin, eyeAngles, fov ); return; } m_aCamAngle = pPlayer->EyeAngles(); m_vCamOrigin = pPlayer->GetAbsOrigin(); m_flFOV = pPlayer->GetFOV(); if ( pPlayer->GetFlags() & FL_DUCKING ) { m_vCamOrigin += VEC_DUCK_VIEW; } else { m_vCamOrigin += VEC_VIEW; } eyeOrigin = m_vCamOrigin; eyeAngles = m_aCamAngle; fov = m_flFOV; pPlayer->CalcViewModelView( eyeOrigin, eyeAngles); C_BaseViewModel *pViewModel = pPlayer->GetViewModel( 0 ); if ( pViewModel ) { Assert( pViewModel->GetOwner() == pPlayer ); pViewModel->UpdateVisibility(); } }
//----------------------------------------------------------------------------- // Purpose: // Input : fTimeDelta - //----------------------------------------------------------------------------- void C_ExtinguisherJet::Update( float fTimeDelta ) { if ( m_bEmit == false ) return; C_BasePlayer *player = C_BasePlayer::GetLocalPlayer(); if ( m_bUseMuzzlePoint ) { C_BaseViewModel *vm = player ? player->GetViewModel( 0 ) : NULL; if ( vm ) { int iAttachment = vm->LookupAttachment( "muzzle" ); Vector origin; QAngle angles; vm->GetAttachment( iAttachment, origin, angles ); Assert( !GetMoveParent() ); SetLocalOrigin( origin ); SetLocalAngles( angles ); } } trace_t tr; Vector shotDir, vRight, vUp; AngleVectors( GetAbsAngles(), &shotDir, &vRight, &vUp ); //FIXME: Muzzle point is incorrect on the model! if ( m_bUseMuzzlePoint ) { shotDir.Negate(); } Vector endPoint = GetAbsOrigin() + ( shotDir * 150.0f ); UTIL_TraceLine( GetAbsOrigin(), endPoint, MASK_SHOT, NULL, COLLISION_GROUP_NONE, &tr ); bool hitWall = ( tr.fraction < 1.0f ); //Add normal jet if ( m_pEmitter.IsValid() ) { SimpleParticle *pParticle; m_pEmitter->SetSortOrigin( GetAbsOrigin() ); float tempDelta = fTimeDelta; //FIXME: All particles need to be within this loop while( m_ParticleSpawn.NextEvent( tempDelta ) ) { pParticle = (SimpleParticle *) m_pEmitter->AddParticle( sizeof(SimpleParticle), m_MaterialHandle, GetAbsOrigin() ); if ( pParticle ) { pParticle->m_flDieTime = 0.2f; pParticle->m_flLifetime = 0.0f; pParticle->m_flRoll = random->RandomInt( 0, 360 ); pParticle->m_flRollDelta= random->RandomFloat( -4.0f, 4.0f ); pParticle->m_uchStartSize = 1; pParticle->m_uchEndSize = random->RandomInt( 32, 48 ); pParticle->m_uchStartAlpha = random->RandomInt( 128, 164 ); pParticle->m_uchEndAlpha = 0; int cScale = random->RandomInt( 192, 255 ); pParticle->m_uchColor[0] = cScale; pParticle->m_uchColor[1] = cScale; pParticle->m_uchColor[2] = cScale; Vector dir; QAngle ofsAngles; ofsAngles.Random( -8.0f, 8.0f ); ofsAngles += GetAbsAngles(); AngleVectors( ofsAngles, &dir ); if ( m_bUseMuzzlePoint ) { dir.Negate(); } pParticle->m_vecVelocity = dir * random->RandomInt( 400, 800 ); } //Add muzzle effect pParticle = (SimpleParticle *) m_pEmitter->AddParticle( sizeof(SimpleParticle), m_MaterialHandle, GetAbsOrigin() ); if ( pParticle ) { pParticle->m_flDieTime = 0.1f; pParticle->m_flLifetime = 0.0f; pParticle->m_flRoll = random->RandomInt( 0, 360 ); pParticle->m_flRollDelta= random->RandomFloat( -4.0f, 4.0f ); pParticle->m_uchStartSize = 1; pParticle->m_uchEndSize = random->RandomInt( 8, 16 ); pParticle->m_uchStartAlpha = random->RandomInt( 128, 255 ); pParticle->m_uchEndAlpha = 0; int cScale = random->RandomInt( 192, 255 ); pParticle->m_uchColor[0] = cScale; pParticle->m_uchColor[1] = cScale; pParticle->m_uchColor[2] = cScale; Vector dir; QAngle ofsAngles; ofsAngles.Random( -64.0f, 64.0f ); ofsAngles += GetAbsAngles(); AngleVectors( ofsAngles, &dir ); if ( m_bUseMuzzlePoint ) { dir.Negate(); } pParticle->m_vecVelocity = dir * random->RandomInt( 32, 64 ); } //Add a wall effect if needed if ( hitWall ) { AddExtinguisherDecal( tr ); Vector offDir; offDir.Random( -16.0f, 16.0f ); pParticle = (SimpleParticle *) m_pEmitter->AddParticle( sizeof(SimpleParticle), m_MaterialHandle, ( tr.endpos + ( tr.plane.normal * 8.0f ) ) + offDir ); if ( pParticle ) { pParticle->m_flDieTime = 0.4f; pParticle->m_flLifetime = 0.0f; pParticle->m_flRoll = random->RandomInt( 0, 360 ); pParticle->m_flRollDelta= random->RandomFloat( -2.0f, 2.0f ); pParticle->m_uchStartSize = random->RandomInt( 8, 16 ); pParticle->m_uchEndSize = random->RandomInt( 24, 32 ); pParticle->m_uchStartAlpha = random->RandomInt( 64, 128 ); pParticle->m_uchEndAlpha = 0; int cScale = random->RandomInt( 192, 255 ); pParticle->m_uchColor[0] = cScale; pParticle->m_uchColor[1] = cScale; pParticle->m_uchColor[2] = cScale; Vector rDir; rDir = tr.plane.normal; rDir[0] += random->RandomFloat( -0.9f, 0.9f ); rDir[1] += random->RandomFloat( -0.9f, 0.9f ); rDir[2] += random->RandomFloat( -0.9f, 0.9f ); pParticle->m_vecVelocity = rDir * random->RandomInt( 32, 64 ); } } //Add small ember-like particles if ( random->RandomInt( 0, 1 ) == 0 ) { m_pEmberEmitter->SetSortOrigin( GetAbsOrigin() ); pParticle = (SimpleParticle *) m_pEmberEmitter->AddParticle( sizeof(SimpleParticle), m_pEmberEmitter->GetPMaterial( "particle/particle_smokegrenade" ), GetAbsOrigin() ); assert(pParticle); if ( pParticle ) { pParticle->m_flLifetime = 0.0f; pParticle->m_flDieTime = 1.0f; pParticle->m_flRoll = 0; pParticle->m_flRollDelta = 0; pParticle->m_uchColor[0] = 255; pParticle->m_uchColor[1] = 255; pParticle->m_uchColor[2] = 255; pParticle->m_uchStartAlpha = 255; pParticle->m_uchEndAlpha = 0; pParticle->m_uchStartSize = 1; pParticle->m_uchEndSize = 0; Vector dir; QAngle ofsAngles; ofsAngles.Random( -8.0f, 8.0f ); ofsAngles += GetAbsAngles(); AngleVectors( ofsAngles, &dir ); if ( m_bUseMuzzlePoint ) { dir.Negate(); } pParticle->m_vecVelocity = dir * random->RandomInt( 400, 800 ); } } } } // Inner beam CBeamSegDraw beamDraw; CBeamSeg seg; const int numPoints = 4; Vector beamPoints[numPoints]; beamPoints[0] = GetAbsOrigin(); // Create our beam points int i; for ( i = 0; i < numPoints; i++ ) { beamPoints[i] = GetAbsOrigin() + ( shotDir * (32*i*i) ); beamPoints[i] += vRight * sin( gpGlobals->curtime * 4.0f ) * (2.0f*i); beamPoints[i] += vUp * sin( gpGlobals->curtime * 8.0f ) * (1.0f*i); beamPoints[i] += shotDir * sin( gpGlobals->curtime * (16.0f*i) ) * (1.0f*i); } IMaterial *pMat = materials->FindMaterial( "particle/particle_smokegrenade", NULL ); beamDraw.Start( numPoints, pMat ); //Setup and draw those points for( i = 0; i < numPoints; i++ ) { float t = (float) i / (numPoints - 1); float color = 1.0f * (1.0f - t); seg.m_vColor = Vector( color, color, color ); seg.m_vPos = beamPoints[i]; seg.m_flTexCoord = (float)i/(float)(numPoints-1) - ((gpGlobals->curtime - (int)gpGlobals->curtime) * 4.0f ); seg.m_flWidth = 4.0f + ( (64.0f*t) * (fabs( sin( gpGlobals->curtime * 16.0f ) )) ); seg.m_flAlpha = color; beamDraw.NextSeg( &seg ); } beamDraw.End(); }
//----------------------------------------------------------------------------- // Purpose: // Output : int //----------------------------------------------------------------------------- int C_SpriteRenderer::DrawSprite( IClientEntity *entity, const model_t *model, const Vector& origin, const QAngle& angles, float frame, IClientEntity *attachedto, int attachmentindex, int rendermode, int renderfx, int alpha, int r, int g, int b, float scale, float flHDRColorScale ) { VPROF_BUDGET( "C_SpriteRenderer::DrawSprite", VPROF_BUDGETGROUP_PARTICLE_RENDERING ); if ( !r_drawsprites.GetBool() || !model || modelinfo->GetModelType( model ) != mod_sprite ) return 0; // Get extra data CEngineSprite *psprite = (CEngineSprite *)modelinfo->GetModelExtraData(model); if ( !psprite ) return 0; Vector effect_origin; VectorCopy(origin, effect_origin); // Use attachment point if ( attachedto ) { C_BaseEntity *ent = attachedto->GetBaseEntity(); if ( ent ) { if ( ent->GetBaseAnimating() && ent->GetBaseAnimating()->IsViewModel() && ::input->CAM_IsThirdPersonOverShoulder() ) { C_BaseViewModel *pVm = (C_BaseViewModel*)ent; C_BasePlayer *pOwner = ( pVm->GetOwner() && pVm->GetOwner()->IsPlayer() ) ? (C_BasePlayer*)pVm->GetOwner() : NULL; if ( pOwner && pOwner->GetActiveWeapon() ) return 0; //worldmodels don't have the same attachments, so just get out (crossbow) } // don't draw viewmodel effects in reflections if ( CurrentViewID() == VIEW_REFLECTION ) { int group = ent->GetRenderGroup(); if ( group == RENDER_GROUP_VIEW_MODEL_TRANSLUCENT || group == RENDER_GROUP_VIEW_MODEL_OPAQUE ) return 0; } QAngle temp; ent->GetAttachment(attachmentindex, effect_origin, temp); } } if ( rendermode != kRenderNormal ) { float blend = render->GetBlend(); // kRenderGlow and kRenderWorldGlow have a special blending function if (( rendermode == kRenderGlow ) || ( rendermode == kRenderWorldGlow )) { blend *= GlowBlend( psprite, effect_origin, rendermode, renderfx, alpha, &scale ); // Fade out the sprite depending on distance from the view origin. r *= blend; g *= blend; b *= blend; } render->SetBlend( blend ); if ( blend <= 0.0f ) { return 0; } } // Get orthonormal basis Vector forward, right, up; GetSpriteAxes( (SPRITETYPE)psprite->GetOrientation(), origin, angles, forward, right, up ); // Draw DrawSpriteModel( entity, psprite, effect_origin, scale, frame, rendermode, r, g, b, alpha, forward, right, up, flHDRColorScale ); return 1; }