//----------------------------------------------------------------------------- // Sets up the view parameters //----------------------------------------------------------------------------- void CViewRender::SetUpView() { VPROF("CViewRender::SetUpView"); // Initialize view structure with default values float farZ = GetZFar(); m_View.zFar = farZ; m_View.zFarViewmodel = farZ; // UNDONE: Make this farther out? // closest point of approach seems to be view center to top of crouched box m_View.zNear = GetZNear(); m_View.zNearViewmodel = 1; m_View.fov = default_fov.GetFloat(); m_View.m_bOrtho = false; // Enable spatial partition access to edicts partition->SuppressLists( PARTITION_ALL_CLIENT_EDICTS, false ); C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); if ( engine->IsHLTV() ) { HLTVCamera()->CalcView( m_View.origin, m_View.angles, m_View.fov ); } else { // FIXME: Are there multiple views? If so, then what? // FIXME: What happens when there's no player? if (pPlayer) { pPlayer->CalcView( m_View.origin, m_View.angles, m_View.zNear, m_View.zFar, m_View.fov ); // If we are looking through another entities eyes, then override the angles/origin for m_View int viewentity = render->GetViewEntity(); if ( !g_nKillCamMode && (pPlayer->entindex() != viewentity) ) { C_BaseEntity *ve = cl_entitylist->GetEnt( viewentity ); if ( ve ) { VectorCopy( ve->GetAbsOrigin(), m_View.origin ); VectorCopy( ve->GetAbsAngles(), m_View.angles ); } } pPlayer->CalcViewModelView( m_View.origin, m_View.angles ); } // Even if the engine is paused need to override the view // for keeping the camera control during pause. g_pClientMode->OverrideView( &m_View ); } // give the toolsystem a chance to override the view ToolFramework_SetupEngineView( m_View.origin, m_View.angles, m_View.fov ); if ( engine->IsPlayingDemo() ) { if ( cl_demoviewoverride.GetFloat() > 0.0f ) { // Retreive view angles from engine ( could have been set in IN_AdjustAngles above ) CalcDemoViewOverride( m_View.origin, m_View.angles ); } else { s_DemoView = m_View.origin; s_DemoAngle = m_View.angles; } } //Find the offset our current FOV is from the default value float flFOVOffset = default_fov.GetFloat() - m_View.fov; //Adjust the viewmodel's FOV to move with any FOV offsets on the viewer's end m_View.fovViewmodel = g_pClientMode->GetViewModelFOV() - flFOVOffset; // Disable spatical partition access partition->SuppressLists( PARTITION_ALL_CLIENT_EDICTS, true ); // Enable access to all model bones C_BaseAnimating::PopBoneAccess( "OnRenderStart->CViewRender::SetUpView" ); // pops the (true, false) bone access set in OnRenderStart C_BaseAnimating::PushAllowBoneAccess( true, true, "CViewRender::SetUpView->OnRenderEnd" ); // pop is in OnRenderEnd() // Compute the world->main camera transform ComputeCameraVariables( m_View.origin, m_View.angles, &g_vecVForward, &g_vecVRight, &g_vecVUp, &g_matCamInverse ); // set up the hearing origin... AudioState_t audioState; audioState.m_Origin = m_View.origin; audioState.m_Angles = m_View.angles; audioState.m_bIsUnderwater = pPlayer && pPlayer->AudioStateIsUnderwater( m_View.origin ); ToolFramework_SetupAudioState( audioState ); m_View.origin = audioState.m_Origin; m_View.angles = audioState.m_Angles; engine->SetAudioState( audioState ); g_vecPrevRenderOrigin = g_vecRenderOrigin; g_vecPrevRenderAngles = g_vecRenderAngles; g_vecRenderOrigin = m_View.origin; g_vecRenderAngles = m_View.angles; #ifdef _DEBUG s_DbgSetupOrigin = m_View.origin; s_DbgSetupAngles = m_View.angles; #endif }
//----------------------------------------------------------------------------- // Sets up the view parameters //----------------------------------------------------------------------------- void CViewRender::SetUpViews() { VPROF("CViewRender::SetUpViews"); // Initialize view structure with default values float farZ = GetZFar(); // Set up the mono/middle view. CViewSetup &view = m_View; view.zFar = farZ; view.zFarViewmodel = farZ; // UNDONE: Make this farther out? // closest point of approach seems to be view center to top of crouched box view.zNear = GetZNear(); view.zNearViewmodel = 1; view.fov = default_fov.GetFloat(); view.m_bOrtho = false; view.m_bViewToProjectionOverride = false; view.m_eStereoEye = STEREO_EYE_MONO; // Enable spatial partition access to edicts partition->SuppressLists( PARTITION_ALL_CLIENT_EDICTS, false ); C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); // You in-view weapon aim. bool bCalcViewModelView = false; Vector ViewModelOrigin; QAngle ViewModelAngles; if ( engine->IsHLTV() ) { HLTVCamera()->CalcView( view.origin, view.angles, view.fov ); } #if defined( REPLAY_ENABLED ) else if ( g_pEngineClientReplay->IsPlayingReplayDemo() ) { ReplayCamera()->CalcView( view.origin, view.angles, view.fov ); } #endif else { // FIXME: Are there multiple views? If so, then what? // FIXME: What happens when there's no player? if (pPlayer) { pPlayer->CalcView( view.origin, view.angles, view.zNear, view.zFar, view.fov ); // If we are looking through another entities eyes, then override the angles/origin for view int viewentity = render->GetViewEntity(); if ( !g_nKillCamMode && (pPlayer->entindex() != viewentity) ) { C_BaseEntity *ve = cl_entitylist->GetEnt( viewentity ); if ( ve ) { VectorCopy( ve->GetAbsOrigin(), view.origin ); VectorCopy( ve->GetAbsAngles(), view.angles ); } } // There is a viewmodel. bCalcViewModelView = true; ViewModelOrigin = view.origin; ViewModelAngles = view.angles; } else { view.origin.Init(); view.angles.Init(); } // Even if the engine is paused need to override the view // for keeping the camera control during pause. g_pClientMode->OverrideView( &view ); } // give the toolsystem a chance to override the view ToolFramework_SetupEngineView( view.origin, view.angles, view.fov ); if ( engine->IsPlayingDemo() ) { if ( cl_demoviewoverride.GetFloat() > 0.0f ) { // Retreive view angles from engine ( could have been set in IN_AdjustAngles above ) CalcDemoViewOverride( view.origin, view.angles ); } else { s_DemoView = view.origin; s_DemoAngle = view.angles; } } //Find the offset our current FOV is from the default value float fDefaultFov = default_fov.GetFloat(); float flFOVOffset = fDefaultFov - view.fov; //Adjust the viewmodel's FOV to move with any FOV offsets on the viewer's end view.fovViewmodel = g_pClientMode->GetViewModelFOV() - flFOVOffset; if ( UseVR() ) { // Let the headtracking read the status of the HMD, etc. // This call can go almost anywhere, but it needs to know the player FOV for sniper weapon zoom, etc if ( flFOVOffset == 0.0f ) { g_ClientVirtualReality.ProcessCurrentTrackingState ( 0.0f ); } else { g_ClientVirtualReality.ProcessCurrentTrackingState ( view.fov ); } HeadtrackMovementMode_t hmmOverrideMode = g_pClientMode->ShouldOverrideHeadtrackControl(); g_ClientVirtualReality.OverrideView( &m_View, &ViewModelOrigin, &ViewModelAngles, hmmOverrideMode ); // left and right stereo views should default to being the same as the mono/middle view m_ViewLeft = m_View; m_ViewRight = m_View; m_ViewLeft.m_eStereoEye = STEREO_EYE_LEFT; m_ViewRight.m_eStereoEye = STEREO_EYE_RIGHT; g_ClientVirtualReality.OverrideStereoView( &m_View, &m_ViewLeft, &m_ViewRight ); } else { // left and right stereo views should default to being the same as the mono/middle view m_ViewLeft = m_View; m_ViewRight = m_View; m_ViewLeft.m_eStereoEye = STEREO_EYE_LEFT; m_ViewRight.m_eStereoEye = STEREO_EYE_RIGHT; } if ( bCalcViewModelView ) { Assert ( pPlayer != NULL ); pPlayer->CalcViewModelView ( ViewModelOrigin, ViewModelAngles ); } // Disable spatial partition access partition->SuppressLists( PARTITION_ALL_CLIENT_EDICTS, true ); // Enable access to all model bones C_BaseAnimating::PopBoneAccess( "OnRenderStart->CViewRender::SetUpView" ); // pops the (true, false) bone access set in OnRenderStart C_BaseAnimating::PushAllowBoneAccess( true, true, "CViewRender::SetUpView->OnRenderEnd" ); // pop is in OnRenderEnd() // Compute the world->main camera transform // This is only done for the main "middle-eye" view, not for the various other views. ComputeCameraVariables( view.origin, view.angles, &g_vecVForward, &g_vecVRight, &g_vecVUp, &g_matCamInverse ); // set up the hearing origin... AudioState_t audioState; audioState.m_Origin = view.origin; audioState.m_Angles = view.angles; audioState.m_bIsUnderwater = pPlayer && pPlayer->AudioStateIsUnderwater( view.origin ); ToolFramework_SetupAudioState( audioState ); // TomF: I wonder when the audio tools modify this, if ever... Assert ( view.origin == audioState.m_Origin ); Assert ( view.angles == audioState.m_Angles ); view.origin = audioState.m_Origin; view.angles = audioState.m_Angles; engine->SetAudioState( audioState ); g_vecPrevRenderOrigin = g_vecRenderOrigin; g_vecPrevRenderAngles = g_vecRenderAngles; g_vecRenderOrigin = view.origin; g_vecRenderAngles = view.angles; #ifdef DBGFLAG_ASSERT s_DbgSetupOrigin = view.origin; s_DbgSetupAngles = view.angles; #endif }
//----------------------------------------------------------------------------- // Sets up the view parameters //----------------------------------------------------------------------------- void CViewRender::SetUpView() { ASSERT_LOCAL_PLAYER_RESOLVABLE(); int nSlot = GET_ACTIVE_SPLITSCREEN_SLOT(); m_bAllowViewAccess = true; VPROF("CViewRender::SetUpView"); // Initialize view structure with default values float farZ = GetZFar(); CViewSetup &view = GetView(); view.zFar = farZ; view.zFarViewmodel = farZ; // UNDONE: Make this farther out? // closest point of approach seems to be view center to top of crouched box view.zNear = GetZNear(); view.zNearViewmodel = 1; view.fov = default_fov.GetFloat(); view.m_bOrtho = false; // Enable spatial partition access to edicts partition->SuppressLists( PARTITION_ALL_CLIENT_EDICTS, false ); C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); bool bNoViewEnt = false; if( pPlayer == NULL ) { pPlayer = GetSplitScreenViewPlayer( nSlot ); bNoViewEnt = true; } if ( g_bEngineIsHLTV ) { HLTVCamera()->CalcView( view.origin, view.angles, view.fov ); } #if defined( REPLAY_ENABLED ) else if ( engine->IsReplay() ) { ReplayCamera()->CalcView( view.origin, view.angles, view.fov ); } #endif else { // FIXME: Are there multiple views? If so, then what? // FIXME: What happens when there's no player? if (pPlayer) { pPlayer->CalcView( view.origin, view.angles, view.zNear, view.zFar, view.fov ); // If we are looking through another entities eyes, then override the angles/origin for GetView() int viewentity = render->GetViewEntity(); if ( !bNoViewEnt && !g_nKillCamMode && (pPlayer->entindex() != viewentity) ) { C_BaseEntity *ve = cl_entitylist->GetEnt( viewentity ); if ( ve ) { VectorCopy( ve->GetAbsOrigin(), view.origin ); VectorCopy( ve->GetAbsAngles(), view.angles ); } } pPlayer->CalcViewModelView( view.origin, view.angles ); // Is this the proper place for this code? if ( cl_camera_follow_bone_index.GetInt() >= -1 && input->CAM_IsThirdPerson() ) { VectorCopy( g_cameraFollowPos, view.origin ); } } // Even if the engine is paused need to override the view // for keeping the camera control during pause. GetClientMode()->OverrideView( &GetView() ); } // give the toolsystem a chance to override the view ToolFramework_SetupEngineView( view.origin, view.angles, view.fov ); if ( engine->IsPlayingDemo() ) { if ( cl_demoviewoverride.GetFloat() > 0.0f ) { // Retreive view angles from engine ( could have been set in IN_AdjustAngles above ) CalcDemoViewOverride( view.origin, view.angles ); } else { s_DemoView = view.origin; s_DemoAngle = view.angles; } } // Disable spatial partition access partition->SuppressLists( PARTITION_ALL_CLIENT_EDICTS, true ); //Find the offset our current FOV is from the default value float flFOVOffset = default_fov.GetFloat() - view.fov; //Adjust the viewmodel's FOV to move with any FOV offsets on the viewer's end view.fovViewmodel = GetClientMode()->GetViewModelFOV() - flFOVOffset; // Compute the world->main camera transform ComputeCameraVariables( view.origin, view.angles, &g_vecVForward[ nSlot ], &g_vecVRight[ nSlot ], &g_vecVUp[ nSlot ], &g_matCamInverse[ nSlot ] ); // set up the hearing origin... AudioState_t audioState; audioState.m_Origin = view.origin; audioState.m_Angles = view.angles; audioState.m_bIsUnderwater = pPlayer && pPlayer->AudioStateIsUnderwater( view.origin ); ToolFramework_SetupAudioState( audioState ); view.origin = audioState.m_Origin; view.angles = audioState.m_Angles; GetClientMode()->OverrideAudioState( &audioState ); engine->SetAudioState( audioState ); g_vecPrevRenderOrigin[ nSlot ] = g_vecRenderOrigin[ nSlot ]; g_vecPrevRenderAngles[ nSlot ] = g_vecRenderAngles[ nSlot ]; g_vecRenderOrigin[ nSlot ] = view.origin; g_vecRenderAngles[ nSlot ] = view.angles; #ifdef DBGFLAG_ASSERT s_DbgSetupOrigin[ nSlot ] = view.origin; s_DbgSetupAngles[ nSlot ] = view.angles; #endif m_bAllowViewAccess = false; }