//------------------------------------------------------------------------------ void C_BeamSpotLight::SpotlightCreate(void) { m_vSpotlightTargetPos = SpotlightCurrentPos(); { //C_Beam *beam = CBeam::BeamCreate( "sprites/spotlight.vmt", m_flSpotlightGoalWidth ); C_Beam *beam = C_Beam::BeamCreate( "sprites/glow_test02.vmt", m_flSpotlightGoalWidth ); // Beam only exists client side ClientEntityList().AddNonNetworkableEntity( beam ); m_hSpotlight = beam; } // Set the temporary spawnflag on the beam so it doesn't save (we'll recreate it on restore) m_hSpotlight->SetHDRColorScale( m_flHDRColorScale ); const color24 c = GetRenderColor(); m_hSpotlight->SetColor( c.r, c.g, c.b ); m_hSpotlight->SetHaloTexture(m_nHaloIndex); m_hSpotlight->SetHaloScale(60); m_hSpotlight->SetEndWidth(m_flSpotlightGoalWidth); m_hSpotlight->SetBeamFlags( (FBEAM_SHADEOUT|FBEAM_NOTILE) ); m_hSpotlight->SetBrightness( 64 ); m_hSpotlight->SetNoise( 0 ); m_hSpotlight->PointsInit( GetAbsOrigin(), m_vSpotlightTargetPos ); }
//----------------------------------------------------------------------------- // Computes render info for a spotlight //----------------------------------------------------------------------------- void C_BeamSpotLight::ComputeRenderInfo() { // Fade out spotlight end if past MAX length. if ( m_flSpotlightCurLength > 2*m_flSpotlightMaxLength ) { SetRenderAlpha( 0 ); m_hSpotlight->SetFadeLength( m_flSpotlightMaxLength ); } else if ( m_flSpotlightCurLength > m_flSpotlightMaxLength ) { SetRenderAlpha( (1-((m_flSpotlightCurLength-m_flSpotlightMaxLength)/m_flSpotlightMaxLength)) ); m_hSpotlight->SetFadeLength( m_flSpotlightMaxLength ); } else { SetRenderAlpha( 1.0 ); m_hSpotlight->SetFadeLength( m_flSpotlightCurLength ); } // Adjust end width to keep beam width constant float flNewWidth = m_flSpotlightGoalWidth * (m_flSpotlightCurLength / m_flSpotlightMaxLength); flNewWidth = clamp(flNewWidth, 0, MAX_BEAM_WIDTH ); m_hSpotlight->SetEndWidth(flNewWidth); if ( m_bHasDynamicLight ) { // <<TODO>> - magic number 1.8 depends on sprite size m_flLightScale = 1.8*flNewWidth; if ( m_flLightScale > 0 ) { const color24 c = GetRenderColor(); float a = GetRenderAlpha() / 255.0f; ColorRGBExp32 color; color.r = c.r * a; color.g = c.g * a; color.b = c.b * a; color.exponent = 0; if ( color.r == 0 && color.g == 0 && color.b == 0 ) return; // Deal with the environment light if ( !m_pDynamicLight || (m_pDynamicLight->key != index) ) { m_pDynamicLight = effects->CL_AllocDlight( index ); assert (m_pDynamicLight); } //m_pDynamicLight->flags = DLIGHT_NO_MODEL_ILLUMINATION; m_pDynamicLight->radius = m_flLightScale*3.0f; m_pDynamicLight->origin = GetAbsOrigin() + Vector(0,0,5); m_pDynamicLight->die = gpGlobals->curtime + 0.05f; m_pDynamicLight->color = color; } } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CSprite::GetToolRecordingState( KeyValues *msg ) { if ( !ToolsEnabled() ) return; VPROF_BUDGET( "CSprite::GetToolRecordingState", VPROF_BUDGETGROUP_TOOLS ); BaseClass::GetToolRecordingState( msg ); // Use attachment point if ( m_hAttachedToEntity ) { C_BaseEntity *ent = m_hAttachedToEntity->GetBaseEntity(); if ( ent ) { BaseEntityRecordingState_t *pState = (BaseEntityRecordingState_t*)msg->GetPtr( "baseentity" ); // override position if we're driven by an attachment QAngle temp; pState->m_vecRenderOrigin = GetAbsOrigin(); ent->GetAttachment( m_nAttachment, pState->m_vecRenderOrigin, temp ); // override viewmodel if we're driven by an attachment bool bViewModel = ToBaseViewModel( ent ) != NULL; msg->SetInt( "viewmodel", bViewModel ); } } float renderscale = GetRenderScale(); if ( m_bWorldSpaceScale ) { CEngineSprite *psprite = ( CEngineSprite * )modelinfo->GetModelExtraData( GetModel() ); float flMinSize = MIN( psprite->GetWidth(), psprite->GetHeight() ); renderscale /= flMinSize; } color24 c = GetRenderColor(); // sprite params static SpriteRecordingState_t state; state.m_flRenderScale = renderscale; state.m_flFrame = m_flFrame; state.m_flProxyRadius = m_flGlowProxySize; state.m_nRenderMode = GetRenderMode(); state.m_nRenderFX = GetRenderFX() ? true : false; state.m_Color.SetColor( c.r, c.g, c.b, GetRenderBrightness() ); msg->SetPtr( "sprite", &state ); }
//----------------------------------------------------------------------------- // Make a model look as though it's burning. //----------------------------------------------------------------------------- void CAnimating::Scorch( int rate, int floor ) { color32 color = GetRenderColor(); if( color.r > floor ) color.r -= rate; if( color.g > floor ) color.g -= rate; if( color.b > floor ) color.b -= rate; SetRenderColor( color.r, color.g, color.b ); }
// Fade the projectile out over time before making it disappear void CDODSmokeGrenade::Think_Fade() { m_bFading = true; SetNextThink( gpGlobals->curtime ); color32 c = GetRenderColor(); c.a -= 1; SetRenderColor( c.r, c.b, c.g, c.a ); if ( !c.a ) { SetModelName( NULL_STRING );//invisible SetNextThink( gpGlobals->curtime + 10 ); SetThink( &CDODSmokeGrenade::Think_Remove ); // Spit out smoke for 10 seconds. SetSolid( SOLID_NONE ); } }
// Fade the projectile out over time before making it disappear void CSmokeGrenadeProjectile::Think_Fade() { SetNextThink( gpGlobals->curtime ); color32 c = GetRenderColor(); c.a -= 1; SetRenderColor( c.r, c.b, c.g, c.a ); if ( !c.a ) { TheBots->RemoveGrenade( this ); SetModelName( NULL_STRING );//invisible SetNextThink( gpGlobals->curtime + 20 ); SetThink( &CSmokeGrenadeProjectile::Think_Remove ); // Spit out smoke for 10 seconds. SetSolid( SOLID_NONE ); } }
//----------------------------------------------------------------------------- void C_LowViolenceHostageDeathModel::ClientThink( void ) { if ( m_flFadeOutStart > gpGlobals->curtime ) { return; } int iAlpha = GetRenderColor().a; iAlpha = max( iAlpha - ( g_ragdoll_fadespeed.GetInt() * gpGlobals->frametime ), 0 ); SetRenderMode( kRenderTransAlpha ); SetRenderColorA( iAlpha ); if ( iAlpha == 0 ) { Release(); } }
//========================================================= // RunAI //========================================================= void CNPC_HAssassin::RunAI( void ) { BaseClass::RunAI(); // always visible if moving // always visible is not on hard if (g_iSkillLevel != SKILL_HARD || GetEnemy() == NULL || m_lifeState == LIFE_DEAD || GetActivity() == ACT_RUN || GetActivity() == ACT_WALK || !(GetFlags() & FL_ONGROUND)) m_iTargetRanderamt = 255; else m_iTargetRanderamt = 20; CPASAttenuationFilter filter( this ); if ( GetRenderColor().a > m_iTargetRanderamt) { if ( GetRenderColor().a == 255) { EmitSound( filter, entindex(), "HAssassin.Beamsound" ); } SetRenderColorA( max( GetRenderColor().a - 50, m_iTargetRanderamt ) ); m_nRenderMode = kRenderTransTexture; } else if ( GetRenderColor().a < m_iTargetRanderamt) { SetRenderColorA ( min( GetRenderColor().a + 50, m_iTargetRanderamt ) ); if (GetRenderColor().a == 255) m_nRenderMode = kRenderNormal; } if ( GetActivity() == ACT_RUN || GetActivity() == ACT_WALK) { static int iStep = 0; iStep = ! iStep; if (iStep) { EmitSound( filter, entindex(), "HAssassin.Footstep" ); } } }
void CFighter::Render(void) { CCamera* Game_Camera = CCamera::GetInstance(); ///////////////////////////////////////////////////////////////// // BUG FIX // Reference Bug # 33 / 56 // BUG FIX START ///////////////////////////////////////////////////////////////// AnimationManager::GetInstance()->Render(GetPosX() - Game_Camera->GetPosX(), GetPosY() - Game_Camera->GetPosY(), IsFlipped(), *GetAnimInfo(), GetRenderColor()); /////////////////////////////////////////////////////////////////////////// // BUG FIX END Reference # 33 / 56 ////////////////////////////////////////////////////////////////////////// CEnemy::Render(); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- int CSpriteTrail::DrawModel( int flags, const RenderableInstance_t &instance ) { VPROF_BUDGET( "CSpriteTrail::DrawModel", VPROF_BUDGETGROUP_PARTICLE_RENDERING ); // Must have at least one point if ( m_nStepCount < 1 ) return 1; //See if we should draw if ( !IsVisible() || ( m_bReadyToDraw == false ) ) return 0; CEngineSprite *pSprite = Draw_SetSpriteTexture( GetModel(), m_flFrame, GetRenderMode() ); if ( pSprite == NULL ) return 0; // Specify all the segments. CMatRenderContextPtr pRenderContext( g_pMaterialSystem ); CBeamSegDraw segDraw; segDraw.Start( pRenderContext, m_nStepCount + 1, pSprite->GetMaterial( GetRenderMode() ) ); // Setup the first point, always emanating from the attachment point TrailPoint_t *pLast = GetTrailPoint( m_nStepCount-1 ); TrailPoint_t currentPoint; currentPoint.m_flDieTime = gpGlobals->curtime + m_flLifeTime; ComputeScreenPosition( ¤tPoint.m_vecScreenPos ); currentPoint.m_flTexCoord = pLast->m_flTexCoord + currentPoint.m_vecScreenPos.DistTo(pLast->m_vecScreenPos) * m_flTextureRes; currentPoint.m_flWidthVariance = 0.0f; #if SCREEN_SPACE_TRAILS VMatrix viewMatrix; materials->GetMatrix( MATERIAL_VIEW, &viewMatrix ); viewMatrix = viewMatrix.InverseTR(); #endif TrailPoint_t *pPrevPoint = NULL; float flTailAlphaDist = m_flMinFadeLength; for ( int i = 0; i <= m_nStepCount; ++i ) { // This makes it so that we're always drawing to the current location TrailPoint_t *pPoint = (i != m_nStepCount) ? GetTrailPoint(i) : ¤tPoint; float flLifePerc = (pPoint->m_flDieTime - gpGlobals->curtime) / m_flLifeTime; flLifePerc = clamp( flLifePerc, 0.0f, 1.0f ); color24 c = GetRenderColor(); BeamSeg_t curSeg; curSeg.m_color.r = c.r; curSeg.m_color.g = c.g; curSeg.m_color.b = c.b; float flAlphaFade = flLifePerc; if ( flTailAlphaDist > 0.0f ) { if ( pPrevPoint ) { float flDist = pPoint->m_vecScreenPos.DistTo( pPrevPoint->m_vecScreenPos ); flTailAlphaDist -= flDist; } if ( flTailAlphaDist > 0.0f ) { float flTailFade = Lerp( (m_flMinFadeLength - flTailAlphaDist) / m_flMinFadeLength, 0.0f, 1.0f ); if ( flTailFade < flAlphaFade ) { flAlphaFade = flTailFade; } } } curSeg.m_color.a = GetRenderBrightness() * flAlphaFade; #if SCREEN_SPACE_TRAILS curSeg.m_vPos = viewMatrix * pPoint->m_vecScreenPos; #else curSeg.m_vPos = pPoint->m_vecScreenPos; #endif if ( m_flEndWidth >= 0.0f ) { curSeg.m_flWidth = Lerp( flLifePerc, m_flEndWidth.Get(), m_flStartWidth.Get() ); } else { curSeg.m_flWidth = m_flStartWidth.Get(); } curSeg.m_flWidth += pPoint->m_flWidthVariance; if ( curSeg.m_flWidth < 0.0f ) { curSeg.m_flWidth = 0.0f; } curSeg.m_flTexCoord = pPoint->m_flTexCoord; segDraw.NextSeg( &curSeg ); // See if we're done with this bad boy if ( pPoint->m_flDieTime <= gpGlobals->curtime ) { // Push this back onto the top for use ++m_nFirstStep; --i; --m_nStepCount; } pPrevPoint = pPoint; } segDraw.End(); return 1; }
void C_Sun::OnDataChanged( DataUpdateType_t updateType ) { BaseClass::OnDataChanged( updateType ); // We have to do special setup on our colors because we're tinting an additive material. // If we don't have at least one component at full strength, the luminosity of the material // will change and that will cause the material to become more translucent This would be incorrect // for the sun, which should always be completely opaque at its core. Here, we renormalize the // components to make sure only hue is altered. color24 c = GetRenderColor(); float maxComponent = MAX( c.r, MAX( c.g, c.b ) ); Vector vOverlayColor; Vector vMainColor; // Re-normalize the color ranges if ( maxComponent <= 0.0f ) { // This is an error, set to pure white vMainColor.Init( 1.0f, 1.0f, 1.0f ); } else { vMainColor.x = c.r / maxComponent; vMainColor.y = c.g / maxComponent; vMainColor.z = c.b / maxComponent; } // If we're non-zero, use the value (otherwise use the value we calculated above) if ( m_clrOverlay.r != 0 || m_clrOverlay.g != 0 || m_clrOverlay.b != 0 ) { // Get our overlay color vOverlayColor.x = m_clrOverlay.r / 255.0f; vOverlayColor.y = m_clrOverlay.g / 255.0f; vOverlayColor.z = m_clrOverlay.b / 255.0f; } else { vOverlayColor = vMainColor; } // // Setup the core overlay // m_Overlay.m_vDirection = m_vDirection; m_Overlay.m_nSprites = 1; m_Overlay.m_Sprites[0].m_vColor = vMainColor; m_Overlay.m_Sprites[0].m_flHorzSize = m_nSize; m_Overlay.m_Sprites[0].m_flVertSize = m_nSize; const model_t* pModel = (m_nMaterial != 0) ? modelinfo->GetModel( m_nMaterial ) : NULL; const char *pModelName = pModel ? modelinfo->GetModelName( pModel ) : ""; m_Overlay.m_Sprites[0].m_pMaterial = materials->FindMaterial( pModelName, TEXTURE_GROUP_OTHER ); m_Overlay.m_flProxyRadius = 0.05f; // about 1/20th of the screen // // Setup the external glow overlay // m_GlowOverlay.m_vDirection = m_vDirection; m_GlowOverlay.m_nSprites = 1; m_GlowOverlay.m_Sprites[0].m_vColor = vOverlayColor; m_GlowOverlay.m_Sprites[0].m_flHorzSize = m_nOverlaySize; m_GlowOverlay.m_Sprites[0].m_flVertSize = m_nOverlaySize; pModel = (m_nOverlayMaterial != 0) ? modelinfo->GetModel( m_nOverlayMaterial ) : NULL; pModelName = pModel ? modelinfo->GetModelName( pModel ) : ""; m_GlowOverlay.m_Sprites[0].m_pMaterial = materials->FindMaterial( pModelName, TEXTURE_GROUP_OTHER ); // This texture will fade away as the dot between camera and sun changes m_GlowOverlay.SetModulateByDot(); m_GlowOverlay.m_flProxyRadius = 0.05f; // about 1/20th of the screen // Either activate or deactivate. if ( m_bOn ) { m_Overlay.Activate(); m_GlowOverlay.Activate(); } else { m_Overlay.Deactivate(); m_GlowOverlay.Deactivate(); } }
void C_SDKRagdoll::ClientThink( void ) { SetNextClientThink( CLIENT_THINK_ALWAYS ); if ( m_bFadingOut == true ) { int iAlpha = GetRenderColor().a; int iFadeSpeed = 600.0f; iAlpha = max( iAlpha - ( iFadeSpeed * gpGlobals->frametime ), 0 ); SetRenderMode( kRenderTransAlpha ); SetRenderColorA( iAlpha ); if ( iAlpha == 0 ) { Release(); } return; } for( int iClient = 1; iClient <= gpGlobals->maxClients; ++iClient ) { C_SDKPlayer *pEnt = static_cast< C_SDKPlayer *> ( UTIL_PlayerByIndex( iClient ) ); if(!pEnt || !pEnt->IsPlayer()) continue; if ( m_hPlayer == NULL ) continue; if ( pEnt->entindex() == m_hPlayer->entindex() ) continue; if ( pEnt->GetHealth() <= 0 ) continue; #if defined ( SDK_USE_PRONE ) if ( pEnt->m_Shared.IsProne() == false ) continue; #endif Vector vTargetOrigin = pEnt->GetAbsOrigin(); Vector vMyOrigin = GetAbsOrigin(); Vector vDir = vTargetOrigin - vMyOrigin; if ( vDir.Length() > cl_ragdoll_pronecheck_distance.GetInt() ) continue; SetNextClientThink( CLIENT_THINK_ALWAYS ); m_bFadingOut = true; return; } //Tony; this is kind of silly, because.. whats the point of fading out? // if the player is looking at us, delay the fade if ( IsRagdollVisible() ) { StartFadeOut( 5.0 ); return; } if ( m_fDeathTime > gpGlobals->curtime ) return; Release(); // Die }
//----------------------------------------------------------------------------- // Purpose: Render the weapon. Draw the Viewmodel if the weapon's being carried // by this player, otherwise draw the worldmodel. //----------------------------------------------------------------------------- int C_BaseViewModel::DrawModel( int flags, const RenderableInstance_t &instance ) { if ( !m_bReadyToDraw ) return 0; if ( flags & STUDIO_RENDER ) { // Determine blending amount and tell engine float blend = (float)( instance.m_nAlpha / 255.0f ); // Totally gone if ( blend <= 0.0f ) return 0; // Tell engine render->SetBlend( blend ); float color[3]; GetColorModulation( color ); render->SetColorModulation( color ); } CMatRenderContextPtr pRenderContext( materials ); if ( ShouldFlipViewModel() ) pRenderContext->CullMode( MATERIAL_CULLMODE_CW ); int ret = 0; C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); C_BaseCombatWeapon *pWeapon = GetOwningWeapon(); // If the local player's overriding the viewmodel rendering, let him do it if ( pPlayer && pPlayer->IsOverridingViewmodel() ) { ret = pPlayer->DrawOverriddenViewmodel( this, flags, instance ); } else if ( pWeapon && pWeapon->IsOverridingViewmodel() ) { ret = pWeapon->DrawOverriddenViewmodel( this, flags, instance ); } else { ret = BaseClass::DrawModel( flags, instance ); } pRenderContext->CullMode( MATERIAL_CULLMODE_CCW ); // Now that we've rendered, reset the animation restart flag if ( flags & STUDIO_RENDER ) { if ( m_nOldAnimationParity != m_nAnimationParity ) { m_nOldAnimationParity = m_nAnimationParity; } // Tell the weapon itself that we've rendered, in case it wants to do something if ( pWeapon ) { pWeapon->ViewModelDrawn( this ); } if ( vm_debug.GetBool() ) { MDLCACHE_CRITICAL_SECTION(); int line = 16; CStudioHdr *hdr = GetModelPtr(); engine->Con_NPrintf( line++, "%s: %s(%d), cycle: %.2f cyclerate: %.2f playbackrate: %.2f\n", (hdr)?hdr->pszName():"(null)", GetSequenceName( GetSequence() ), GetSequence(), GetCycle(), GetSequenceCycleRate( hdr, GetSequence() ), GetPlaybackRate() ); if ( hdr ) { for( int i=0; i < hdr->GetNumPoseParameters(); ++i ) { const mstudioposeparamdesc_t &Pose = hdr->pPoseParameter( i ); engine->Con_NPrintf( line++, "pose_param %s: %f", Pose.pszName(), GetPoseParameter( i ) ); } } // Determine blending amount and tell engine float blend = (float)( instance.m_nAlpha / 255.0f ); float color[3]; GetColorModulation( color ); engine->Con_NPrintf( line++, "blend=%f, color=%f,%f,%f", blend, color[0], color[1], color[2] ); engine->Con_NPrintf( line++, "GetRenderMode()=%d", GetRenderMode() ); engine->Con_NPrintf( line++, "m_nRenderFX=0x%8.8X", GetRenderFX() ); color24 c = GetRenderColor(); unsigned char a = GetRenderAlpha(); engine->Con_NPrintf( line++, "rendercolor=%d,%d,%d,%d", c.r, c.g, c.b, a ); engine->Con_NPrintf( line++, "origin=%f, %f, %f", GetRenderOrigin().x, GetRenderOrigin().y, GetRenderOrigin().z ); engine->Con_NPrintf( line++, "angles=%f, %f, %f", GetRenderAngles()[0], GetRenderAngles()[1], GetRenderAngles()[2] ); if ( IsEffectActive( EF_NODRAW ) ) { engine->Con_NPrintf( line++, "EF_NODRAW" ); } } } return ret; }
/*virtual*/ void CEarthBoss::Render(void) { CCamera* Game_Camera = CCamera::GetInstance(); AnimationManager::GetInstance()->Render(GetPosX() - Game_Camera->GetPosX(), GetPosY() - Game_Camera->GetPosY(), IsFlipped(), *GetAnimInfo(), GetRenderColor()); CEnemy::Render(); }
void CGrunt::Render(void) { CCamera* Game_Camera = CCamera::GetInstance(); AnimationManager::GetInstance()->Render(GetPosX() - Game_Camera->GetPosX(), GetPosY() - Game_Camera->GetPosY(), m_bFlipped, *GetAnimInfo(), GetRenderColor()); CEnemy::Render(); }