void CSDKMapOverview::DrawCamera() { C_BasePlayer *localPlayer = C_BasePlayer::GetLocalPlayer(); if (!localPlayer) return; if( localPlayer->GetObserverMode() == OBS_MODE_ROAMING ) { // Instead of the programmer-art red dot, we'll draw an icon for when our camera is roaming. int alpha = 255; DrawIconSDK(m_cameraIconFree, m_cameraIconFree, localPlayer->GetAbsOrigin(), m_flIconSize * 3.0f, localPlayer->EyeAngles()[YAW], alpha); } else if( localPlayer->GetObserverMode() == OBS_MODE_IN_EYE ) { if( localPlayer->GetObserverTarget() ) { // Fade it if it is on top of a player dot. And don't rotate it. int alpha = 255 * 0.5f; DrawIconSDK(m_cameraIconFirst, m_cameraIconFirst, localPlayer->GetObserverTarget()->GetAbsOrigin(), m_flIconSize * 1.5f, GetViewAngle(), alpha); } } else if( localPlayer->GetObserverMode() == OBS_MODE_CHASE ) { if( localPlayer->GetObserverTarget() ) { // Or Draw the third-camera a little bigger. (Needs room to be off the dot being followed) int alpha = 255; DrawIconSDK(m_cameraIconThird, m_cameraIconThird, localPlayer->GetObserverTarget()->GetAbsOrigin(), m_flIconSize * 3.0f, localPlayer->EyeAngles()[YAW], alpha); } } }
//========================================================= //========================================================= C_BasePlayer * C_GameInstructor::GetLocalPlayer() { C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer(); // If we're not a developer, don't do the special spectator hook ups if ( !developer.GetBool() ) return pLocalPlayer; // If there is no local player and we're not spectating, just return that if ( !pLocalPlayer || pLocalPlayer->GetTeamNumber() != TEAM_SPECTATOR ) return pLocalPlayer; // We're purely a spectator let's get lessons of the person we're spectating C_BasePlayer *pSpectatedPlayer = NULL; if ( pLocalPlayer->GetObserverMode() == OBS_MODE_IN_EYE || pLocalPlayer->GetObserverMode() == OBS_MODE_CHASE ) pSpectatedPlayer = ToBasePlayer( pLocalPlayer->GetObserverTarget() ); if ( m_hLastSpectatedPlayer != pSpectatedPlayer ) { // We're spectating someone new! Close all the stale lessons! m_bSpectatedPlayerChanged = true; m_hLastSpectatedPlayer = pSpectatedPlayer; } return pSpectatedPlayer; }
//----------------------------------------------------------------------------- // Purpose: Save CPU cycles by letting the HUD system early cull // costly traversal. Called per frame, return true if thinking and // painting need to occur. //----------------------------------------------------------------------------- bool CHudCrosshair::ShouldDraw( void ) { bool bNeedsDraw; C_BasePlayer* pPlayer = C_BasePlayer::GetLocalPlayer(); if ( !pPlayer ) return false; // draw a crosshair only if alive or spectating in eye if ( IsXbox() ) { bNeedsDraw = m_pCrosshair && !engine->IsDrawingLoadingImage() && !engine->IsPaused() && !pPlayer->IsSuitEquipped() && g_pClientMode->ShouldDrawCrosshair() && !( pPlayer->GetFlags() & FL_FROZEN ) && ( pPlayer->entindex() == render->GetViewEntity() ) && ( pPlayer->IsAlive() || ( pPlayer->GetObserverMode() == OBS_MODE_IN_EYE ) || ( cl_observercrosshair.GetBool() && pPlayer->GetObserverMode() == OBS_MODE_ROAMING ) ); } else { bNeedsDraw = m_pCrosshair && crosshair.GetInt() && !engine->IsDrawingLoadingImage() && !engine->IsPaused() && g_pClientMode->ShouldDrawCrosshair() && !( pPlayer->GetFlags() & FL_FROZEN ) && ( pPlayer->entindex() == render->GetViewEntity() ) && ( pPlayer->IsAlive() || ( pPlayer->GetObserverMode() == OBS_MODE_IN_EYE ) || ( cl_observercrosshair.GetBool() && pPlayer->GetObserverMode() == OBS_MODE_ROAMING ) ); } return ( bNeedsDraw && CHudElement::ShouldDraw() ); }
//----------------------------------------------------------------------------- // Purpose: Save CPU cycles by letting the HUD system early cull // costly traversal. Called per frame, return true if thinking and // painting need to occur. //----------------------------------------------------------------------------- bool CHudCrosshair::ShouldDraw( void ) { bool bNeedsDraw; if ( m_bHideCrosshair ) return false; C_BasePlayer* pPlayer = C_BasePlayer::GetLocalPlayer(); if ( !pPlayer ) return false; C_BaseCombatWeapon *pWeapon = pPlayer->GetActiveWeapon(); if ( pWeapon && !pWeapon->ShouldDrawCrosshair() ) return false; #ifdef PORTAL C_Portal_Player *portalPlayer = ToPortalPlayer(pPlayer); if ( portalPlayer && portalPlayer->IsSuppressingCrosshair() ) return false; #endif // PORTAL /* disabled to avoid assuming it's an HL2 player. // suppress crosshair in zoom. if ( pPlayer->m_HL2Local.m_bZooming ) return false; */ // draw a crosshair only if alive or spectating in eye if ( IsX360() ) { bNeedsDraw = m_pCrosshair && !engine->IsDrawingLoadingImage() && !engine->IsPaused() && ( !pPlayer->IsSuitEquipped() || g_pGameRules->IsMultiplayer() ) && g_pClientMode->ShouldDrawCrosshair() && !( pPlayer->GetFlags() & FL_FROZEN ) && ( pPlayer->entindex() == render->GetViewEntity() ) && ( pPlayer->IsAlive() || ( pPlayer->GetObserverMode() == OBS_MODE_IN_EYE ) || ( cl_observercrosshair.GetBool() && pPlayer->GetObserverMode() == OBS_MODE_ROAMING ) ); } else { bNeedsDraw = m_pCrosshair && crosshair.GetInt() && !engine->IsDrawingLoadingImage() && !engine->IsPaused() && g_pClientMode->ShouldDrawCrosshair() && !( pPlayer->GetFlags() & FL_FROZEN ) && ( pPlayer->entindex() == render->GetViewEntity() ) && !pPlayer->IsInVGuiInputMode() && ( pPlayer->IsAlive() || ( pPlayer->GetObserverMode() == OBS_MODE_IN_EYE ) || ( cl_observercrosshair.GetBool() && pPlayer->GetObserverMode() == OBS_MODE_ROAMING ) ); } return ( bNeedsDraw && CHudElement::ShouldDraw() ); }
//----------------------------------------------------------------------------- // Purpose: A basic version (doesn't taken into account the "holding after // screenshot" bit like TF does, but is good enough for hud_freezecamhide. //----------------------------------------------------------------------------- static bool IsTakingAFreezecamScreenshot() { C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); bool bInFreezeCam = ( pPlayer && pPlayer->GetObserverMode() == OBS_MODE_FREEZECAM ); return ( bInFreezeCam && engine->IsTakingScreenshot() ); }
//----------------------------------------------------------------------------- // Purpose: Render the weapon. Draw the Viewmodel if the weapon's being carried // by this player, otherwise draw the worldmodel. //----------------------------------------------------------------------------- int C_BaseCombatWeapon::DrawModel( int flags ) { VPROF_BUDGET( "C_BaseCombatWeapon::DrawModel", VPROF_BUDGETGROUP_MODEL_RENDERING ); if ( !m_bReadyToDraw ) return 0; if ( !IsVisible() ) return 0; // check if local player chases owner of this weapon in first person C_BasePlayer *localplayer = C_BasePlayer::GetLocalPlayer(); if ( localplayer && localplayer->IsObserver() && GetOwner() ) { // don't draw weapon if chasing this guy as spectator // we don't check that in ShouldDraw() since this may change // without notification if ( localplayer->GetObserverMode() == OBS_MODE_IN_EYE && localplayer->GetObserverTarget() == GetOwner() ) return false; } return BaseClass::DrawModel( flags ); }
void CSDKSpectatorGUI::Update() { BaseClass::Update(); C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer(); if( pLocalPlayer ) { m_nLastSpecMode = pLocalPlayer->GetObserverMode(); m_nLastSpecTarget = pLocalPlayer->GetObserverTarget(); } m_nLastPhaseID = ClassicGameRules()->GetCurrentPhaseID (); if (m_nLastPhaseID == PHASE_BUILD) { wcscpy (m_PhaseText, L"Build Phase"); } else if (m_nLastPhaseID == PHASE_COMBAT) { wcscpy (m_PhaseText, L"Combat Phase"); } UpdateTimer(); UpdateSpectatorPlayerList(); if ( pLocalPlayer ) { ResizeControls(); } }
//----------------------------------------------------------------------------- // Purpose: Save CPU cycles by letting the HUD system early cull // costly traversal. Called per frame, return true if thinking and // painting need to occur. //----------------------------------------------------------------------------- bool CDAHudCrosshair::ShouldDraw( void ) { // OnThink isn't called when the thing isn't visible so force it to update. CalculateCrosshair(); bool bNeedsDraw; if ( m_bHideCrosshair ) return false; C_BasePlayer* pPlayer = C_BasePlayer::GetLocalPlayer(); if ( !pPlayer ) return false; C_BaseCombatWeapon *pWeapon = pPlayer->GetActiveWeapon(); if ( pWeapon && !pWeapon->ShouldDrawCrosshair() ) return false; ConVarRef cl_observercrosshair("cl_observercrosshair"); // draw a crosshair only if alive or spectating in eye if ( IsX360() ) { bNeedsDraw = m_pCrosshair && !engine->IsDrawingLoadingImage() && !engine->IsPaused() && ( !pPlayer->IsSuitEquipped() || g_pGameRules->IsMultiplayer() ) && g_pClientMode->ShouldDrawCrosshair() && !( pPlayer->GetFlags() & FL_FROZEN ) && ( pPlayer->entindex() == render->GetViewEntity() ) && ( pPlayer->IsAlive() || ( pPlayer->GetObserverMode() == OBS_MODE_IN_EYE ) || ( cl_observercrosshair.GetBool() && pPlayer->GetObserverMode() == OBS_MODE_ROAMING ) ); } else { bNeedsDraw = m_pCrosshair && da_crosshair.GetInt() && !engine->IsDrawingLoadingImage() && !engine->IsPaused() && g_pClientMode->ShouldDrawCrosshair() && !( pPlayer->GetFlags() & FL_FROZEN ) && ( pPlayer->entindex() == render->GetViewEntity() ) && !pPlayer->IsInVGuiInputMode() && ( pPlayer->IsAlive() || ( pPlayer->GetObserverMode() == OBS_MODE_IN_EYE ) || ( cl_observercrosshair.GetBool() && pPlayer->GetObserverMode() == OBS_MODE_ROAMING ) ); } return ( bNeedsDraw && CHudElement::ShouldDraw() ); }
int GetSpectatorMode( void ) { C_BasePlayer * player = C_BasePlayer::GetLocalPlayer(); if ( player ) return player->GetObserverMode(); else return OBS_MODE_NONE; // game not started yet }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CTFHudObjectiveStatus::Think() { if ( !TeamplayRoundBasedRules() ) return; SetVisiblePanels(); // check for an active timer and turn the time panel on or off if we need to if ( m_pTimePanel ) { // Don't draw in freezecam, or when the game's not running C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); bool bDisplayTimer = !( pPlayer && pPlayer->GetObserverMode() == OBS_MODE_FREEZECAM ); if ( bDisplayTimer ) { // is the time panel still pointing at an active timer? int iCurrentTimer = m_pTimePanel->GetTimerIndex(); CTeamRoundTimer *pTimer = dynamic_cast< CTeamRoundTimer* >( ClientEntityList().GetEnt( iCurrentTimer ) ); if ( pTimer && !pTimer->IsDormant() && !pTimer->IsDisabled() && pTimer->ShowInHud() ) { // the current timer is fine, make sure the panel is visible bDisplayTimer = true; } else if ( ObjectiveResource() ) { // check for a different timer int iActiveTimer = ObjectiveResource()->GetTimerToShowInHUD(); pTimer = dynamic_cast< CTeamRoundTimer* >( ClientEntityList().GetEnt( iActiveTimer ) ); bDisplayTimer = ( iActiveTimer != 0 && pTimer && !pTimer->IsDormant() && pTimer->ShowInHud() ); if ( bDisplayTimer ) m_pTimePanel->SetTimerIndex( iActiveTimer ); } } if ( bDisplayTimer ) { if ( !m_pTimePanel->IsVisible() ) { m_pTimePanel->SetVisible( true ); // If our spectator GUI is visible, invalidate its layout so that it moves the reinforcement label if ( g_pSpectatorGUI ) { g_pSpectatorGUI->InvalidateLayout(); } } } else if ( m_pTimePanel->IsVisible() ) { m_pTimePanel->SetVisible( false ); } } }
int C_HLTVCamera::GetMode() { if ( m_iCameraMan > 0 ) { C_BasePlayer *pCameraMan = UTIL_PlayerByIndex( m_iCameraMan ); if ( pCameraMan ) return pCameraMan->GetObserverMode(); } return m_nCameraMode; }
void CHL2MPSpectatorGUI::Update() { BaseClass::Update(); C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer(); if( pLocalPlayer ) { m_nLastSpecMode = pLocalPlayer->GetObserverMode(); m_nLastSpecTarget = pLocalPlayer->GetObserverTarget(); } }
bool IsTakingAFreezecamScreenshot( void ) { // Don't draw in freezecam, or when the game's not running C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); bool bInFreezeCam = ( pPlayer && pPlayer->GetObserverMode() == OBS_MODE_FREEZECAM ); if ( bInFreezeCam == true && engine->IsTakingScreenshot() ) return true; CTFFreezePanel *pPanel = GET_HUDELEMENT( CTFFreezePanel ); if ( pPanel ) { if ( pPanel->IsHoldingAfterScreenShot() ) return true; } return false; }
void CSDKSpectatorGUI::Update() { BaseClass::Update(); C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer(); if( pLocalPlayer ) { m_nLastSpecMode = pLocalPlayer->GetObserverMode(); m_nLastSpecTarget = pLocalPlayer->GetObserverTarget(); } UpdateTimer(); UpdateSpectatorPlayerList(); if ( pLocalPlayer ) { ResizeControls(); } }
//---------------------------------------------------------------------------- // Hooks into the fast path render system //---------------------------------------------------------------------------- IClientModelRenderable* C_BaseCombatWeapon::GetClientModelRenderable() { if ( !m_bReadyToDraw ) return 0; // check if local player chases owner of this weapon in first person C_BasePlayer *localplayer = C_BasePlayer::GetLocalPlayer(); if ( localplayer && localplayer->IsObserver() && GetOwner() ) { // don't draw weapon if chasing this guy as spectator // we don't check that in ShouldDraw() since this may change // without notification if ( localplayer->GetObserverMode() == OBS_MODE_IN_EYE && localplayer->GetObserverTarget() == GetOwner() ) return NULL; } if ( !BaseClass::GetClientModelRenderable() ) return NULL; EnsureCorrectRenderingModel(); return this; }
//----------------------------------------------------------------------------- // Purpose: Render current view into specified rectangle // Input : *rect - is computed by CVideoMode_Common::GetClientViewRect() //----------------------------------------------------------------------------- void CViewRender::Render( vrect_t *rect ) { Assert(s_DbgSetupOrigin == m_View.origin); Assert(s_DbgSetupAngles == m_View.angles); VPROF_BUDGET( "CViewRender::Render", "CViewRender::Render" ); tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); vrect_t vr = *rect; // Stub out the material system if necessary. CMatStubHandler matStub; engine->EngineStats_BeginFrame(); // Assume normal vis m_bForceNoVis = false; C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); // Set for console commands, etc. render->SetMainView ( m_View.origin, m_View.angles ); for( StereoEye_t eEye = GetFirstEye(); eEye <= GetLastEye(); eEye = (StereoEye_t)(eEye+1) ) { CViewSetup &view = GetView( eEye ); #if 0 && defined( CSTRIKE_DLL ) const bool bPlayingBackReplay = g_pEngineClientReplay && g_pEngineClientReplay->IsPlayingReplayDemo(); if ( pPlayer && !bPlayingBackReplay ) { C_BasePlayer *pViewTarget = pPlayer; if ( pPlayer->IsObserver() && pPlayer->GetObserverMode() == OBS_MODE_IN_EYE ) { pViewTarget = dynamic_cast<C_BasePlayer*>( pPlayer->GetObserverTarget() ); } if ( pViewTarget ) { float targetFOV = (float)pViewTarget->m_iFOV; if ( targetFOV == 0 ) { // FOV of 0 means use the default FOV targetFOV = g_pGameRules->DefaultFOV(); } float deltaFOV = view.fov - m_flLastFOV; float FOVDirection = targetFOV - pViewTarget->m_iFOVStart; // Clamp FOV changes to stop FOV oscillation if ( ( deltaFOV < 0.0f && FOVDirection > 0.0f ) || ( deltaFOV > 0.0f && FOVDirection < 0.0f ) ) { view.fov = m_flLastFOV; } // Catch case where FOV overshoots its target FOV if ( ( view.fov < targetFOV && FOVDirection <= 0.0f ) || ( view.fov > targetFOV && FOVDirection >= 0.0f ) ) { view.fov = targetFOV; } m_flLastFOV = view.fov; } } #endif static ConVarRef sv_restrict_aspect_ratio_fov( "sv_restrict_aspect_ratio_fov" ); float aspectRatio = engine->GetScreenAspectRatio() * 0.75f; // / (4/3) float limitedAspectRatio = aspectRatio; if ( ( sv_restrict_aspect_ratio_fov.GetInt() > 0 && engine->IsWindowedMode() && gpGlobals->maxClients > 1 ) || sv_restrict_aspect_ratio_fov.GetInt() == 2 ) { limitedAspectRatio = MIN( aspectRatio, 1.85f * 0.75f ); // cap out the FOV advantage at a 1.85:1 ratio (about the widest any legit user should be) } view.fov = ScaleFOVByWidthRatio( view.fov, limitedAspectRatio ); view.fovViewmodel = ScaleFOVByWidthRatio( view.fovViewmodel, aspectRatio ); // Let the client mode hook stuff. g_pClientMode->PreRender(&view); g_pClientMode->AdjustEngineViewport( vr.x, vr.y, vr.width, vr.height ); ToolFramework_AdjustEngineViewport( vr.x, vr.y, vr.width, vr.height ); float flViewportScale = mat_viewportscale.GetFloat(); view.m_nUnscaledX = vr.x; view.m_nUnscaledY = vr.y; view.m_nUnscaledWidth = vr.width; view.m_nUnscaledHeight = vr.height; switch( eEye ) { case STEREO_EYE_MONO: { #if 0 // Good test mode for debugging viewports that are not full-size. view.width = vr.width * flViewportScale * 0.75f; view.height = vr.height * flViewportScale * 0.75f; view.x = vr.x + view.width * 0.10f; view.y = vr.y + view.height * 0.20f; #else view.x = vr.x * flViewportScale; view.y = vr.y * flViewportScale; view.width = vr.width * flViewportScale; view.height = vr.height * flViewportScale; #endif float engineAspectRatio = engine->GetScreenAspectRatio(); view.m_flAspectRatio = ( engineAspectRatio > 0.0f ) ? engineAspectRatio : ( (float)view.width / (float)view.height ); } break; case STEREO_EYE_RIGHT: case STEREO_EYE_LEFT: { g_pSourceVR->GetViewportBounds( (ISourceVirtualReality::VREye)(eEye - 1 ), &view.x, &view.y, &view.width, &view.height ); view.m_nUnscaledWidth = view.width; view.m_nUnscaledHeight = view.height; view.m_nUnscaledX = view.x; view.m_nUnscaledY = view.y; } break; default: Assert ( false ); break; } // if we still don't have an aspect ratio, compute it from the view size if( view.m_flAspectRatio <= 0.f ) view.m_flAspectRatio = (float)view.width / (float)view.height; int nClearFlags = VIEW_CLEAR_DEPTH | VIEW_CLEAR_STENCIL; if( gl_clear_randomcolor.GetBool() ) { CMatRenderContextPtr pRenderContext( materials ); pRenderContext->ClearColor3ub( rand()%256, rand()%256, rand()%256 ); pRenderContext->ClearBuffers( true, false, false ); pRenderContext->Release(); } else if ( gl_clear.GetBool() ) { nClearFlags |= VIEW_CLEAR_COLOR; } else if ( IsPosix() ) { MaterialAdapterInfo_t adapterInfo; materials->GetDisplayAdapterInfo( materials->GetCurrentAdapter(), adapterInfo ); // On Posix, on ATI, we always clear color if we're antialiasing if ( adapterInfo.m_VendorID == 0x1002 ) { if ( g_pMaterialSystem->GetCurrentConfigForVideoCard().m_nAASamples > 0 ) { nClearFlags |= VIEW_CLEAR_COLOR; } } } // Determine if we should draw view model ( client mode override ) bool drawViewModel = g_pClientMode->ShouldDrawViewModel(); if ( cl_leveloverview.GetFloat() > 0 ) { SetUpOverView(); nClearFlags |= VIEW_CLEAR_COLOR; drawViewModel = false; } // Apply any player specific overrides if ( pPlayer ) { // Override view model if necessary if ( !pPlayer->m_Local.m_bDrawViewmodel ) { drawViewModel = false; } } int flags = 0; if( eEye == STEREO_EYE_MONO || eEye == STEREO_EYE_LEFT || ( g_ClientVirtualReality.ShouldRenderHUDInWorld() ) ) { flags = RENDERVIEW_DRAWHUD; } if ( drawViewModel ) { flags |= RENDERVIEW_DRAWVIEWMODEL; } if( eEye == STEREO_EYE_RIGHT ) { // we should use the monitor view from the left eye for both eyes flags |= RENDERVIEW_SUPPRESSMONITORRENDERING; } RenderView( view, nClearFlags, flags ); if ( UseVR() ) { bool bDoUndistort = ! engine->IsTakingScreenshot(); if ( bDoUndistort ) { g_ClientVirtualReality.PostProcessFrame( eEye ); } // logic here all cloned from code in viewrender.cpp around RenderHUDQuad: // figure out if we really want to draw the HUD based on freeze cam bool bInFreezeCam = ( pPlayer && pPlayer->GetObserverMode() == OBS_MODE_FREEZECAM ); // draw the HUD after the view model so its "I'm closer" depth queues work right. if( !bInFreezeCam && g_ClientVirtualReality.ShouldRenderHUDInWorld() ) { // TODO - a bit of a shonky test - basically trying to catch the main menu, the briefing screen, the loadout screen, etc. bool bTranslucent = !g_pMatSystemSurface->IsCursorVisible(); g_ClientVirtualReality.OverlayHUDQuadWithUndistort( view, bDoUndistort, g_pClientMode->ShouldBlackoutAroundHUD(), bTranslucent ); } } } // TODO: should these be inside or outside the stereo eye stuff? g_pClientMode->PostRender(); engine->EngineStats_EndFrame(); #if !defined( _X360 ) // Stop stubbing the material system so we can see the budget panel matStub.End(); #endif // Draw all of the UI stuff "fullscreen" // (this is not health, ammo, etc. Nor is it pre-game briefing interface stuff - this is the stuff that appears when you hit Esc in-game) // In stereo mode this is rendered inside of RenderView so it goes into the render target if( !g_ClientVirtualReality.ShouldRenderHUDInWorld() ) { CViewSetup view2d; view2d.x = rect->x; view2d.y = rect->y; view2d.width = rect->width; view2d.height = rect->height; render->Push2DView( view2d, 0, NULL, GetFrustum() ); render->VGui_Paint( PAINT_UIPANELS | PAINT_CURSOR ); render->PopView( GetFrustum() ); } }
void CBasePlayerAnimState::Update( float eyeYaw, float eyePitch ) { VPROF( "CBasePlayerAnimState::Update" ); // Clear animation overlays because we're about to completely reconstruct them. ClearAnimationLayers(); // Some mods don't want to update the player's animation state if they're dead and ragdolled. if ( !ShouldUpdateAnimState() ) { ClearAnimationState(); return; } CStudioHdr *pStudioHdr = GetOuter()->GetModelPtr(); // Store these. All the calculations are based on them. m_flEyeYaw = AngleNormalize( eyeYaw ); m_flEyePitch = AngleNormalize( eyePitch ); // Compute sequences for all the layers. ComputeSequences( pStudioHdr ); // Compute all the pose params. ComputePoseParam_BodyPitch( pStudioHdr ); // Look up/down. ComputePoseParam_BodyYaw(); // Torso rotation. ComputePoseParam_MoveYaw( pStudioHdr ); // What direction his legs are running in. ComputePlaybackRate(); #ifdef CLIENT_DLL if ( cl_showanimstate.GetInt() == m_pOuter->entindex() ) { DebugShowAnimStateFull( 5 ); } else if ( cl_showanimstate.GetInt() == -2 ) { C_BasePlayer *targetPlayer = C_BasePlayer::GetLocalPlayer(); if( targetPlayer && ( targetPlayer->GetObserverMode() == OBS_MODE_IN_EYE || targetPlayer->GetObserverMode() == OBS_MODE_CHASE ) ) { C_BaseEntity *target = targetPlayer->GetObserverTarget(); if( target && target->IsPlayer() ) { targetPlayer = ToBasePlayer( target ); } } if ( m_pOuter == targetPlayer ) { DebugShowAnimStateFull( 6 ); } } #else if ( sv_showanimstate.GetInt() == m_pOuter->entindex() ) { DebugShowAnimState( 20 ); } #endif }
void CHudCrosshair::GetDrawPosition ( float *pX, float *pY, bool *pbBehindCamera, QAngle angleCrosshairOffset ) { QAngle curViewAngles = CurrentViewAngles(); Vector curViewOrigin = CurrentViewOrigin(); int vx, vy, vw, vh; vgui::surface()->GetFullscreenViewport( vx, vy, vw, vh ); float screenWidth = vw; float screenHeight = vh; float x = screenWidth / 2; float y = screenHeight / 2; bool bBehindCamera = false; C_BasePlayer* pPlayer = C_BasePlayer::GetLocalPlayer(); if ( ( pPlayer != NULL ) && ( pPlayer->GetObserverMode()==OBS_MODE_NONE ) ) { bool bUseOffset = false; Vector vecStart; Vector vecEnd; if ( UseVR() ) { // These are the correct values to use, but they lag the high-speed view data... vecStart = pPlayer->Weapon_ShootPosition(); Vector vecAimDirection = pPlayer->GetAutoaimVector( 1.0f ); // ...so in some aim modes, they get zapped by something completely up-to-date. g_ClientVirtualReality.OverrideWeaponHudAimVectors ( &vecStart, &vecAimDirection ); vecEnd = vecStart + vecAimDirection * MAX_TRACE_LENGTH; bUseOffset = true; } #ifdef SIXENSE // TODO: actually test this Sixsense code interaction with things like HMDs & stereo. if ( g_pSixenseInput->IsEnabled() && !UseVR() ) { // Never autoaim a predicted weapon (for now) vecStart = pPlayer->Weapon_ShootPosition(); Vector aimVector; AngleVectors( CurrentViewAngles() - g_pSixenseInput->GetViewAngleOffset(), &aimVector ); // calculate where the bullet would go so we can draw the cross appropriately vecEnd = vecStart + aimVector * MAX_TRACE_LENGTH; bUseOffset = true; } #endif if ( bUseOffset ) { trace_t tr; UTIL_TraceLine( vecStart, vecEnd, MASK_SHOT, pPlayer, COLLISION_GROUP_NONE, &tr ); Vector screen; screen.Init(); bBehindCamera = ScreenTransform(tr.endpos, screen) != 0; x = 0.5f * ( 1.0f + screen[0] ) * screenWidth + 0.5f; y = 0.5f * ( 1.0f - screen[1] ) * screenHeight + 0.5f; } } // MattB - angleCrosshairOffset is the autoaim angle. // if we're not using autoaim, just draw in the middle of the // screen if ( angleCrosshairOffset != vec3_angle ) { QAngle angles; Vector forward; Vector point, screen; // this code is wrong angles = curViewAngles + angleCrosshairOffset; AngleVectors( angles, &forward ); VectorAdd( curViewOrigin, forward, point ); ScreenTransform( point, screen ); x += 0.5f * screen[0] * screenWidth + 0.5f; y += 0.5f * screen[1] * screenHeight + 0.5f; } *pX = x; *pY = y; *pbBehindCamera = bBehindCamera; }
//----------------------------------------------------------------------------- // Rendering //----------------------------------------------------------------------------- int CNewParticleEffect::DrawModel( int flags ) { VPROF_BUDGET( "CNewParticleEffect::DrawModel", VPROF_BUDGETGROUP_PARTICLE_RENDERING ); if ( r_DrawParticles.GetBool() == false ) return 0; #ifdef C17 // City17: DX7? Don't draw. if (engine->GetDXSupportLevel() < 80) return 0; #endif if ( !g_pClientMode->ShouldDrawParticles() || !ParticleMgr()->ShouldRenderParticleSystems() ) return 0; if ( ( flags & ( STUDIO_SHADOWDEPTHTEXTURE | STUDIO_SSAODEPTHTEXTURE ) ) != 0 ) { return 0; } // do distance cull check here. We do it here instead of in particles so we can easily only do // it for root objects, not bothering to cull children individually CMatRenderContextPtr pRenderContext( materials ); Vector vecCamera; pRenderContext->GetWorldSpaceCameraPosition( &vecCamera ); if ( CalcSqrDistanceToAABB( m_MinBounds, m_MaxBounds, vecCamera ) > ( m_pDef->m_flMaxDrawDistance * m_pDef->m_flMaxDrawDistance ) ) { if ( !IsRetail() && ( g_cl_particle_show_bbox || ( g_cl_particle_show_bbox_cost != 0 ) ) ) { DebugDrawBbox ( true ); } // Still need to make sure we set this or they won't follow their attachemnt points. m_flNextSleepTime = Max ( m_flNextSleepTime, ( g_pParticleSystemMgr->GetLastSimulationTime() + m_pDef->m_flNoDrawTimeToGoToSleep )); return 0; } if ( flags & STUDIO_TRANSPARENCY ) { int viewentity = render->GetViewEntity(); C_BaseEntity *pCameraObject = cl_entitylist->GetEnt( viewentity ); // apply logic that lets you skip rendering a system if the camera is attached to its entity if ( pCameraObject && ( m_pDef->m_nSkipRenderControlPoint != -1 ) && ( m_pDef->m_nSkipRenderControlPoint <= m_nHighestCP ) ) { C_BaseEntity *pEntity = (EHANDLE)GetControlPointEntity( m_pDef->m_nSkipRenderControlPoint ); if ( pEntity ) { // If we're in thirdperson, we still see it if ( !input->CAM_IsThirdPerson() ) { if ( pEntity == pCameraObject ) return 0; C_BaseEntity *pRootMove = pEntity->GetRootMoveParent(); if ( pRootMove == pCameraObject ) return 0; // If we're spectating in-eyes of the camera object, we don't see it C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); if ( pPlayer == pCameraObject ) { C_BaseEntity *pObTarget = pPlayer->GetObserverTarget(); if ( pPlayer->GetObserverMode() == OBS_MODE_IN_EYE && (pObTarget == pEntity || pRootMove == pObTarget ) ) return 0; } } } } pRenderContext->MatrixMode( MATERIAL_MODEL ); pRenderContext->PushMatrix(); pRenderContext->LoadIdentity(); Render( pRenderContext, IsTwoPass(), pCameraObject ); pRenderContext->MatrixMode( MATERIAL_MODEL ); pRenderContext->PopMatrix(); } else { g_pParticleSystemMgr->AddToRenderCache( this ); } if ( !IsRetail() ) { CParticleMgr *pMgr = ParticleMgr(); if ( pMgr->m_bStatsRunning ) { pMgr->StatsNewParticleEffectDrawn ( this ); } if ( g_cl_particle_show_bbox || ( g_cl_particle_show_bbox_cost != 0 ) ) { DebugDrawBbox ( false ); } } return 1; }
void CGERadar::WorldToRadar( CGERadarContact *contact ) { // If we are out of range don't bother if ( !IsContactInRange( contact ) ) return; C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer(); if ( !pLocalPlayer ) return; Vector vContact = GetContactPosition(contact); float x_diff = vContact.x - pLocalPlayer->GetAbsOrigin().x; float y_diff = vContact.y - pLocalPlayer->GetAbsOrigin().y; // Supply epsilon values to avoid divide-by-zero if(x_diff == 0.0f ) x_diff = 0.001f; if(y_diff == 0.0f ) y_diff = 0.001f; float fRadarRadius = m_flRadarDiameter * 0.500f; float fRange = GetRadarRange(); float fScale = fRange >= 1.000f ? fRadarRadius / fRange : 0.000f; float dist = min( GetContactRange( vContact ), fRange ); float flOffset = atan(y_diff/x_diff); float flPlayerY; // If we're in first person spectate mode we should use the rotation of whoever we're spectating. if (pLocalPlayer->IsObserver() && pLocalPlayer->GetObserverTarget() && pLocalPlayer->GetObserverMode() == OBS_MODE_IN_EYE) flPlayerY = (pLocalPlayer->GetLocalAngles().y * M_PI) * 0.0055555f; else flPlayerY = (pLocalPlayer->LocalEyeAngles().y * M_PI) * 0.0055555f; // Always add because atan will return neg angle w/ neg coeff if ( x_diff < 0 ) flOffset += M_PI; else flOffset += M_TWOPI; flOffset = flPlayerY - flOffset; // Transform relative to radar source float xnew_diff = dist * sin(flOffset); float ynew_diff = -dist * cos(flOffset); // Scale the dot's position to match radar scale xnew_diff *= fScale; ynew_diff *= fScale; // Make sure we never leave our radar circle! contact->m_vScaledPos.x = fRadarRadius + xnew_diff + m_iSideBuff; contact->m_vScaledPos.y = fRadarRadius + ynew_diff + m_iSideBuff; contact->m_vScaledPos.z = vContact.z - pLocalPlayer->GetAbsOrigin().z; // Figure out our alpha modulation if ( !contact->m_bAlwaysVisible && dist > fRange * 0.8f ) contact->m_flAlphaMod = RemapValClamped( dist, fRange * 0.8f, fRange, 1.0, 0 ); else contact->m_flAlphaMod = 1.0f; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CTFHudKothTimeStatus::Think( void ) { if ( !TFGameRules() ) return; // check for an active timer and turn the time panel on or off if we need to if ( m_pBlueKothTimer && m_pRedKothTimer ) { // Don't draw in freezecam, or when the game's not running C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); bool bDisplayTimers = !( pPlayer && pPlayer->GetObserverMode() == OBS_MODE_FREEZECAM ); if ( bDisplayTimers ) { bool bDisplayBlueTimer = false; bool bDisplayRedTimer = false; bool bDisplayGreenTimer = false; bool bDisplayYellowTimer = false; // is the time panel still pointing at an active timer? CTeamRoundTimer *pTimer = dynamic_cast< CTeamRoundTimer* >( ClientEntityList().GetEnt( m_pBlueKothTimer->GetTimerIndex() ) ); // Check for the current active timer (used for the pulsating HUD animation) CTFHudTimeStatus *pActiveKothTimerPanel = NULL; if ( !pTimer ) { pTimer = TFGameRules()->GetBlueKothRoundTimer(); if ( pTimer && m_pBlueKothTimer->GetTimerIndex() != pTimer->index ) m_pBlueKothTimer->SetTimerIndex( pTimer->index ); } if ( pTimer && !pTimer->IsDormant() && !pTimer->IsDisabled() ) { // the current timer is fine, make sure the panel is visible bDisplayBlueTimer = true; if ( !pTimer->IsTimerPaused() ) pActiveKothTimerPanel = m_pBlueKothTimer; } // And now let's check the other timer // is the time panel still pointing at an active timer? pTimer = dynamic_cast< CTeamRoundTimer* >( ClientEntityList().GetEnt( m_pRedKothTimer->GetTimerIndex() ) ); if ( !pTimer ) { pTimer = TFGameRules()->GetRedKothRoundTimer(); if ( pTimer && m_pRedKothTimer->GetTimerIndex() != pTimer->index ) m_pRedKothTimer->SetTimerIndex( pTimer->index ); } if ( pTimer && !pTimer->IsDormant() && !pTimer->IsDisabled() ) { // the current timer is fine, make sure the panel is visible bDisplayRedTimer = true; if ( !pTimer->IsTimerPaused() ) pActiveKothTimerPanel = m_pRedKothTimer; } if ( TFGameRules()->IsFourTeamGame() ) { // Check GRN timer pTimer = dynamic_cast< CTeamRoundTimer* >( ClientEntityList().GetEnt( m_pGreenKothTimer->GetTimerIndex() ) ); if ( !pTimer ) { pTimer = TFGameRules()->GetGreenKothRoundTimer(); if ( pTimer ) m_pGreenKothTimer->SetTimerIndex( pTimer->index ); } if ( pTimer && !pTimer->IsDormant() && !pTimer->IsDisabled() ) { // the current timer is fine, make sure the panel is visible bDisplayGreenTimer = true; if ( !pTimer->IsTimerPaused() ) pActiveKothTimerPanel = m_pGreenKothTimer; } // Check YLW timer pTimer = dynamic_cast< CTeamRoundTimer* >( ClientEntityList().GetEnt( m_pYellowKothTimer->GetTimerIndex() ) ); if ( !pTimer ) { pTimer = TFGameRules()->GetYellowKothRoundTimer(); if ( pTimer ) m_pYellowKothTimer->SetTimerIndex( pTimer->index ); } if ( pTimer && !pTimer->IsDormant() && !pTimer->IsDisabled() ) { // the current timer is fine, make sure the panel is visible bDisplayYellowTimer = true; if ( !pTimer->IsTimerPaused() ) pActiveKothTimerPanel = m_pYellowKothTimer; } } if ( !m_pBlueKothTimer->IsVisible() || !m_pRedKothTimer->IsVisible() ) { m_pBlueKothTimer->SetVisible( true ); // bDisplayBlueTimer m_pRedKothTimer->SetVisible( true ); // bDisplayRedTimer // If our spectator GUI is visible, invalidate its layout so that it moves the reinforcement label if ( g_pSpectatorGUI ) { g_pSpectatorGUI->InvalidateLayout(); } } if ( TFGameRules()->IsFourTeamGame() ) { if ( !m_pGreenKothTimer->IsVisible() || !m_pYellowKothTimer->IsVisible() ) { m_pGreenKothTimer->SetVisible( true ); m_pYellowKothTimer->SetVisible( true ); // If our spectator GUI is visible, invalidate its layout so that it moves the reinforcement label if ( g_pSpectatorGUI ) { g_pSpectatorGUI->InvalidateLayout(); } } } else { m_pGreenKothTimer->SetVisible( false ); m_pYellowKothTimer->SetVisible( false ); } // Set overtime panels active on our active panel (if needed) if ( m_pActiveKothTimerPanel ) m_pActiveKothTimerPanel->SetExtraTimePanels(); // Do NOT put a null check here, otherwise the white active timer BG will linger around after a round end if ( pActiveKothTimerPanel != m_pActiveKothTimerPanel ) { m_pActiveKothTimerPanel = pActiveKothTimerPanel; UpdateActiveTeam(); } } else { m_pBlueKothTimer->SetVisible( false ); m_pRedKothTimer->SetVisible( false ); m_pGreenKothTimer->SetVisible( false ); m_pYellowKothTimer->SetVisible( false ); m_pActiveTimerBG->SetVisible( false ); } } }