//----------------------------------------------------------------------------- // 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 CViewRender::Render( vrect_t *rect ) { VPROF_BUDGET( "CViewRender::Render", "CViewRender::Render" ); m_bAllowViewAccess = true; CUtlVector< vgui::Panel * > roots; VGui_GetPanelList( roots ); // Stub out the material system if necessary. CMatStubHandler matStub; engine->EngineStats_BeginFrame(); // Assume normal vis m_bForceNoVis = false; float flViewportScale = mat_viewportscale.GetFloat(); vrect_t engineRect = *rect; // The tool framework wants to adjust the entire 3d viewport, not the per-split screen one from below ToolFramework_AdjustEngineViewport( engineRect.x, engineRect.y, engineRect.width, engineRect.height ); IterateRemoteSplitScreenViewSlots_Push( true ); FOR_EACH_VALID_SPLITSCREEN_PLAYER( hh ) { ACTIVE_SPLITSCREEN_PLAYER_GUARD_VGUI( hh ); CViewSetup &view = GetView( hh ); float engineAspectRatio = engine->GetScreenAspectRatio( view.width, view.height ); Assert( s_DbgSetupOrigin[ hh ] == view.origin ); Assert( s_DbgSetupAngles[ hh ] == view.angles ); // Using this API gives us a chance to "inset" the 3d views as needed for splitscreen int insetX, insetY; VGui_GetEngineRenderBounds( hh, view.x, view.y, view.width, view.height, insetX, insetY ); float aspectRatio = engineAspectRatio * 0.75f; // / (4/3) view.fov = ScaleFOVByWidthRatio( view.fov, aspectRatio ); view.fovViewmodel = ScaleFOVByWidthRatio( view.fovViewmodel, aspectRatio ); // Let the client mode hook stuff. GetClientMode()->PreRender( &view ); GetClientMode()->AdjustEngineViewport( view.x, view.y, view.width, view.height ); view.width *= flViewportScale; view.height *= flViewportScale; if ( IsX360() ) { // view must be compliant to resolve restrictions view.width = AlignValue( view.width, GPU_RESOLVE_ALIGNMENT ); view.height = AlignValue( view.height, GPU_RESOLVE_ALIGNMENT ); } view.m_flAspectRatio = ( engineAspectRatio > 0.0f ) ? engineAspectRatio : ( (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; } // Determine if we should draw view model ( client mode override ) bool drawViewModel = GetClientMode()->ShouldDrawViewModel(); // Apply any player specific overrides C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); if ( pPlayer ) { // Override view model if necessary if ( !pPlayer->m_Local.m_bDrawViewmodel ) { drawViewModel = false; } } if ( cl_leveloverview.GetFloat() > 0 ) { SetUpOverView(); nClearFlags |= VIEW_CLEAR_COLOR; drawViewModel = false; } render->SetMainView( view.origin, view.angles ); int flags = (pPlayer == NULL) ? 0 : RENDERVIEW_DRAWHUD; if ( drawViewModel ) { flags |= RENDERVIEW_DRAWVIEWMODEL; } // This is the hook for per-split screen player views C_BaseEntity::PreRenderEntities( hh ); if ( ( ss_debug_draw_player.GetInt() < 0 ) || ( hh == ss_debug_draw_player.GetInt() ) ) { CViewSetup hudViewSetup; VGui_GetHudBounds( hh, hudViewSetup.x, hudViewSetup.y, hudViewSetup.width, hudViewSetup.height ); RenderView( view, hudViewSetup, nClearFlags, flags ); } GetClientMode()->PostRender(); } IterateRemoteSplitScreenViewSlots_Pop(); engine->EngineStats_EndFrame(); #if !defined( _X360 ) // Stop stubbing the material system so we can see the budget panel matStub.End(); #endif // Render the new-style embedded UI // TODO: when embedded UI will be used for HUD, we will need it to maintain // a separate screen for HUD and a separate screen stack for pause menu & main menu. // for now only render embedded UI in pause menu & main menu #if defined( GAMEUI_UISYSTEM2_ENABLED ) && 0 BaseModUI::CBaseModPanel *pBaseModPanel = BaseModUI::CBaseModPanel::GetSingletonPtr(); // render the new-style embedded UI only if base mod panel is not visible (game-hud) // otherwise base mod panel will render the embedded UI on top of video/productscreen if ( !pBaseModPanel || !pBaseModPanel->IsVisible() ) { Rect_t uiViewport; uiViewport.x = rect->x; uiViewport.y = rect->y; uiViewport.width = rect->width; uiViewport.height = rect->height; g_pGameUIGameSystem->Render( uiViewport, gpGlobals->curtime ); } #endif // Draw all of the UI stuff "fullscreen" if ( true ) // For PIXEVENT { #if PIX_ENABLE { CMatRenderContextPtr pRenderContext( materials ); PIXEVENT( pRenderContext, "VGui UI" ); } #endif 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 ); { // The engine here is trying to access CurrentView() etc. which is bogus ACTIVE_SPLITSCREEN_PLAYER_GUARD( 0 ); render->PopView( GetFrustum() ); } } m_bAllowViewAccess = false; }
//----------------------------------------------------------------------------- // Purpose: Render current view into specified rectangle // Input : *rect - //----------------------------------------------------------------------------- void CViewRender::Render( vrect_t *rect ) { Assert(s_DbgSetupOrigin == m_View.origin); Assert(s_DbgSetupAngles == m_View.angles); VPROF_BUDGET( "CViewRender::Render", "CViewRender::Render" ); vrect_t vr = *rect; // Stub out the material system if necessary. CMatStubHandler matStub; bool drawViewModel; engine->EngineStats_BeginFrame(); // Assume normal vis m_bForceNoVis = false; float aspectRatio = engine->GetScreenAspectRatio() * 0.75f; // / (4/3) m_View.fov = ScaleFOVByWidthRatio( m_View.fov, aspectRatio ); m_View.fovViewmodel = ScaleFOVByWidthRatio( m_View.fovViewmodel, aspectRatio ); // Let the client mode hook stuff. g_pClientMode->PreRender(&m_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(); float engineAspectRatio = engine->GetScreenAspectRatio(); m_View.x = vr.x; m_View.y = vr.y; m_View.width = vr.width * flViewportScale; m_View.height = vr.height * flViewportScale; m_View.m_flAspectRatio = ( engineAspectRatio > 0.0f ) ? engineAspectRatio : ( (float)m_View.width / (float)m_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; } // Determine if we should draw view model ( client mode override ) drawViewModel = g_pClientMode->ShouldDrawViewModel(); if ( cl_leveloverview.GetFloat() > 0 ) { SetUpOverView(); nClearFlags |= VIEW_CLEAR_COLOR; drawViewModel = false; } // Apply any player specific overrides C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); if ( pPlayer ) { // Override view model if necessary if ( !pPlayer->m_Local.m_bDrawViewmodel ) { drawViewModel = false; } } ApplyHeadShake(&m_View); // (torbensko) render->SetMainView( m_View.origin, m_View.angles ); int flags = RENDERVIEW_DRAWHUD; if ( drawViewModel ) { flags |= RENDERVIEW_DRAWVIEWMODEL; } RenderView( m_View, nClearFlags, flags ); g_pClientMode->PostRender(); engine->EngineStats_EndFrame(); #if !defined( _X360 ) // Stop stubbing the material system so we can see the budget panel matStub.End(); #endif CViewSetup view2d; // Draw all of the UI stuff "fullscreen" 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 ); render->PopView( GetFrustum() ); }
//----------------------------------------------------------------------------- // Purpose: Render current view into specified rectangle // Input : *rect - //----------------------------------------------------------------------------- void CViewRender::Render( vrect_t *rect ) { /*static*/ std::vector<smCoord3f> view_head_pos; /*static*/ std::vector<smRotEuler> view_head_rot; static float learnt_x = 0.0; static float learnt_y = 0.0; static float learnt_z = fa_default_depth; static float learnt_xRot = fa_default_pitch; static float learnt_yRot = 0.0; static float learnt_zRot = 0.0; int i = 0; fa_fov_min = ( fov_desired.GetInt() + fov_fapi_window_adj_amount.GetInt() ); Assert(s_DbgSetupOrigin == m_View.origin); Assert(s_DbgSetupAngles == m_View.angles); VPROF_BUDGET( "CViewRender::Render", "CViewRender::Render" ); vrect_t vr = *rect; // Stub out the material system if necessary. CMatStubHandler matStub; bool drawViewModel; engine->EngineStats_BeginFrame(); // Assume normal vis m_bForceNoVis = false; C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); // IMPORTANT: Please acknowledge the author Torben Sko ([email protected], torbensko.com/software/head_tracking), // if you: // 1.1 Use or replicate any of the code pertaining to the utilisation of the head tracking data. // 1.2 Use any of the custom assets, including the modified crossbow and the human // character model. float aspectRatio = engine->GetScreenAspectRatio() * 0.75f; // / (4/3) if(pPlayer && pPlayer->IsAlive() && face_api.m_bFaceAPIHasCamera) { int head_pos_size = 0; if(!fa_paused) { // Warning: this code does not take parellel operations into account if(head_confidence > 0.0f) { view_head_pos.push_back(latest_head_pos); view_head_rot.push_back(latest_head_rot); } // Restore to a neutral position on loss of the head by // scaling down the last recieved head position static float lost_time = 0.0f; if(fa_lost) { if(head_confidence == 0.0f && view_head_pos.size() > 0) { if(lost_time == 0.0f) { lost_time = engine->Time(); } else if(engine->Time() > lost_time + fa_lost_pause) { smCoord3f previous_offset = view_head_pos.back(); previous_offset.x *= fa_lost_scale; previous_offset.y *= fa_lost_scale; previous_offset.z = ((previous_offset.z - learnt_z) * fa_lost_scale) + learnt_z; smRotEuler previous_rotation = view_head_rot.back(); previous_rotation.x_rads = ((previous_rotation.x_rads - learnt_xRot) * fa_lost_scale) + learnt_xRot; previous_rotation.y_rads *= fa_lost_scale; previous_rotation.z_rads *= fa_lost_scale; view_head_pos.push_back(previous_offset); view_head_rot.push_back(previous_rotation); } } else { if(lost_time > 0.0f) { /*char log[40]; sprintf(log, "lost the head for %f seconds", engine->Time() - lost_time); record(log);*/ lost_time = 0.0f; } } } // Use a while statement in case the user has decreased the // smoothing rate since last time head_pos_size = view_head_pos.size(); while( head_pos_size > fa_smoothing ) { view_head_pos.erase(view_head_pos.begin()); view_head_rot.erase(view_head_rot.begin()); } } x = 0.0f; y = 0.0f; z = 0.0f; float xRot = 0.0f; float yRot = 0.0f; float zRot = 0.0f; // Compute the smoothed head movements head_pos_size = view_head_pos.size(); if(head_pos_size > 0) { for(i = 0; i < head_pos_size; i++) { x += view_head_pos[i].x; y += view_head_pos[i].y; z += view_head_pos[i].z; xRot += view_head_rot[i].x_rads; yRot += view_head_rot[i].y_rads; zRot += view_head_rot[i].z_rads; } x /= view_head_pos.size(); y /= view_head_pos.size(); z /= view_head_pos.size(); xRot /= view_head_pos.size(); yRot /= view_head_pos.size(); zRot /= view_head_pos.size(); } // Corrects the arching that occurs when moving towards the camera if(fa_arcCorrection) y += (z - fa_default_depth) * fa_arcCorrection_scale; // Show the head data //if(fa_show_preHeadData) DevMsg(" pre: pos\tx:%f\ty:%f\tz:%f\n rot\tx:%f\ty:%f\tz:%f\n", x, y, z, xRot, yRot, zRot); // IMPORTANT: Please acknowledge the author Torben Sko ([email protected], torbensko.com/software/head_tracking), // if you: // 1.1 Use or replicate any of the code pertaining to the utilisation of the head tracking data. // 1.2 Use any of the custom assets, including the modified crossbow and the human // character model. // Learns the player's neutral position static bool reset_learning = false; if(!fa_learning) { if(reset_learning) { learnt_x = 0.0f; learnt_y = 0.0f; learnt_z = fa_default_depth; learnt_xRot = fa_default_pitch; learnt_yRot = 0.0f; learnt_zRot = 0.0f; reset_learning = true; } } else if(fa_learning && head_confidence > 0.0f && !fa_paused) { float diff, change; diff = learnt_x - x; (diff != 0.0f) ? change = (0.0000001 * fa_learning_influence) / diff : change = 0.0f; (fabs(change) < fabs(diff)) ? learnt_x -= change : learnt_x = x; x -= learnt_x; diff = learnt_y - y; (diff != 0.0f) ? change = (0.0000001 * fa_learning_influence) / diff : change = 0.0f; (fabs(change) < fabs(diff)) ? learnt_y -= change : learnt_y = y; y -= learnt_y; diff = learnt_z - z; (diff != 0.0f) ? change = (0.0000001 * fa_learning_influence) / diff : change = 0.0f; (fabs(change) < fabs(diff)) ? learnt_z -= change : learnt_z = z; z = fa_default_depth + (z - learnt_z); diff = learnt_xRot - xRot; (diff != 0.0f) ? change = (0.0000001 * fa_learning_influence) / diff : change = 0.0f; (fabs(change) < fabs(diff)) ? learnt_xRot -= change : learnt_xRot = xRot; xRot = fa_default_pitch + (xRot - learnt_xRot); diff = learnt_yRot - yRot; (diff != 0.0f) ? change = (0.0000001 * fa_learning_influence) / diff : change = 0.0f; (fabs(change) < fabs(diff)) ? learnt_yRot -= change : learnt_yRot = yRot; yRot -= learnt_yRot; diff = learnt_zRot - zRot; (diff != 0.0f) ? change = (0.0000001 * fa_learning_influence) / diff : change = 0.0f; (fabs(change) < fabs(diff)) ? learnt_zRot -= change : learnt_zRot = zRot; zRot -= learnt_zRot; reset_learning = true; } // IMPORTANT: Please acknowledge the author Torben Sko ([email protected], torbensko.com/software/head_tracking), // if you: // 1.1 Use or replicate any of the code pertaining to the utilisation of the head tracking data. // 1.2 Use any of the custom assets, including the modified crossbow and the human // character model. // Resets the tracker on low confidence static float reset_time = 0.0f; static float waiting_for_reset = 0.0f; if(fa_confidenceMinimum) { if(waiting_for_reset > 0.0f) { if(head_confidence > 0.0f) { /*char log[40]; sprintf(log, "Reset FaceAPI engine and regained head after %f seconds", engine->Time() - waiting_for_reset); record(log);*/ waiting_for_reset = 0.0f; } } else if(head_confidence < fa_confidenceMinimum_threshold && learnt_x <= fabs(fa_confidenceMinimum_widthRange) && learnt_zRot <= fabs(fa_confidenceMinimum_yollRange)) { if(reset_time == 0.0f) { reset_time = engine->Time() + fa_confidenceMinimum_timeout; } else if(engine->Time() > reset_time) { //char logMsg[256]; reset_time = 0.0f; face_api.reset(); waiting_for_reset = engine->Time(); // The learnt values were probably wrong, so reset them learnt_x = 0.0f; learnt_y = 0.0f; learnt_z = fa_default_depth; learnt_xRot = fa_default_pitch; learnt_yRot = 0.0f; learnt_zRot = 0.0f; /*sprintf(logMsg, "confidence droped below %.2f%% for %.2f seconds, whilst (learnt) head.width <= |%.2f| and (learnt) head.roll <= |%.2f|", fa_confidenceMinimum_threshold, fa_confidenceMinimum_timeout, fa_confidenceMinimum_widthRange, fa_confidenceMinimum_yollRange); record(logMsg);*/ } } else { reset_time = 0.0f; } } // IMPORTANT: Please acknowledge the author Torben Sko ([email protected], torbensko.com/software/head_tracking), // if you: // 1.1 Use or replicate any of the code pertaining to the utilisation of the head tracking data. // 1.2 Use any of the custom assets, including the modified crossbow and the human // character model. if(faceapi_mode.GetInt() > 1 && !engine->IsPaused()) { // alters the fov based user's head position float forward = fa_fov_depthScale * (z + fa_fov_depthOffset); float head_fov = fa_fov_min + (1 - fa_fov_influence) * default_fov.GetFloat() + fa_fov_influence * (2 * radToDeg(atan((fa_fov_screenWidth / 2) / (forward)))); m_View.fov = ScaleFOVByWidthRatio( head_fov, aspectRatio ); m_View.fovViewmodel = m_View.fov * fa_fov_modelViewScale; // rotate the camera based on the user's head offsets m_View.angles[YAW] += fa_camRotByHeadOff_globalScale * fa_camRotByHeadOff_yawScale * radToDeg(atan(x / z)); m_View.angles[PITCH] += fa_camRotByHeadOff_globalScale * fa_camRotByHeadOff_pitchScale * radToDeg(atan(y / z)); // offset the camera based on the user's head offsets float depth, height, width; depth = fa_camOffByHeadOff_depthScale * fa_camOffByHeadOff_globalScale * (z - fa_default_depth); m_View.origin.x -= depth * cos(degToRad(m_View.angles[YAW])); m_View.origin.y -= depth * sin(degToRad(m_View.angles[YAW])); width = fa_camOffByHeadOff_widthScale * fa_camOffByHeadOff_globalScale * x; m_View.origin.y -= width * cos(degToRad(m_View.angles[YAW])); m_View.origin.x += width * sin(degToRad(m_View.angles[YAW])); height = fa_camOffByHeadOff_heightScale * fa_camOffByHeadOff_globalScale * y; m_View.origin.z += height; // Alters the vanishing point based on the user's head offset offHor = -fa_vanish_depth * (x / z); offVert = -fa_vanish_depth * (y / z); m_View.m_bOffCenter = true; m_View.m_flOffCenterTop = 1.0f - offVert; m_View.m_flOffCenterBottom = 0.0f - offVert; m_View.m_flOffCenterLeft = 0.0f - offHor; m_View.m_flOffCenterRight = 1.0f - offHor; } else { m_View.fov = ScaleFOVByWidthRatio( m_View.fov, aspectRatio ); m_View.fovViewmodel = ScaleFOVByWidthRatio( m_View.fovViewmodel, aspectRatio ); m_View.m_bOffCenter = false; offHor = 0.0f; offVert = 0.0f; } // Show the head data //if(fa_show_postHeadData) DevMsg(" post: pos\tx:%f\ty:%f\tz:%f\n rot\tx:%f\ty:%f\tz:%f\n", x, y, z, xRot, yRot, zRot); // Show the learnt head data //if(fa_show_learntHeadData) DevMsg("learnt: pos\tx:%f\ty:%f\tz:%f\n rot\tx:%f\ty:%f\tz:%f\n", learnt_x, learnt_y, learnt_z, learnt_xRot, learnt_yRot, learnt_zRot); // IMPORTANT: Please acknowledge the author Torben Sko ([email protected], torbensko.com/software/head_tracking), // if you: // 1.1 Use or replicate any of the code pertaining to the utilisation of the head tracking data. // 1.2 Use any of the custom assets, including the modified crossbow and the human // character model. if((faceapi_mode.GetInt() == 1 || faceapi_mode.GetInt() == 3) && !engine->IsPaused()) { //float offPeer = 0.0f; float rollPeer = 0.0f; //float yawPeer = 0.0f; /*if(fa_peering_off) if(x > fa_peering_offStart) offPeer = (x - fa_peering_offStart) / (fa_peering_offEnd - fa_peering_offStart); else if(x < -fa_peering_offStart) offPeer = (x + fa_peering_offStart) / (fa_peering_offEnd - fa_peering_offStart);*/ if(fa_peering_roll) if(zRot > fa_peering_rollStart) rollPeer = -(zRot - fa_peering_rollStart) / (fa_peering_rollEnd - fa_peering_rollStart); else if(zRot < -fa_peering_rollStart) rollPeer = -(zRot + fa_peering_rollStart) / (fa_peering_rollEnd - fa_peering_rollStart); /*if(fa_peering_yaw) if(yRot > fa_peering_yawStart) yawPeer = -(yRot - fa_peering_yawStart) / (fa_peering_yawEnd - fa_peering_yawStart); else if(yRot < -fa_peering_yawStart) yawPeer = -(yRot + fa_peering_yawStart) / (fa_peering_yawEnd - fa_peering_yawStart);*/ float peer = /*offPeer + */rollPeer /*+ yawPeer*/; if(peer > 1.0f) peer = 1.0f; if(peer < -1.0f) peer = -1.0f; if(peer != 0.0f) { peer = pow(fabs(peer), fa_peering_ease) * (fabs(peer) / peer); QAngle angles = pPlayer->GetViewModel()->GetAbsAngles(); angles[PITCH] += fabs(peer) * fa_peering_gunTilt; pPlayer->GetViewModel()->SetAbsAngles(angles); m_View.angles[ROLL] += peer * fa_peering_headTilt; Vector eyes, eye_offset; eyes = pPlayer->EyePosition(); float hor_move = peer * fa_peering_size; eye_offset.y = -hor_move * cos(degToRad(m_View.angles[YAW])); eye_offset.x = hor_move * sin(degToRad(m_View.angles[YAW])); eye_offset.z = 0.0f; // Don't allow peering through walls trace_t tr; UTIL_TraceHull(eyes, eyes + eye_offset, PEER_HULL_MIN, PEER_HULL_MAX, MASK_SOLID, pPlayer, COLLISION_GROUP_NONE, &tr); eye_offset.z = -fabs(peer) * fa_peering_headLower; m_View.origin += eye_offset * tr.fraction; static float peer_right = 0.0f; if(peer_right == 0.0f && peer == 1.0f) { peer_right = engine->Time(); } else if(peer_right != 0.0f && peer != 1.0f) { /*char log[40]; sprintf(log, "peered right for %f seconds", engine->Time() - peer_right); record(log);*/ peer_right = 0.0f; } static float peer_left = 0.0f; if(peer_left == 0.0f && peer == -1.0f) { peer_left = engine->Time(); } else if(peer_left != 0.0f && peer != -1.0f) { /*char log[40]; sprintf(log, "peered left for %f seconds", engine->Time() - peer_left); record(log);*/ peer_left = 0.0f; } } } // IMPORTANT: Please acknowledge the author Torben Sko ([email protected], torbensko.com/software/head_tracking), // if you: // 1.1 Use or replicate any of the code pertaining to the utilisation of the head tracking data. // 1.2 Use any of the custom assets, including the modified crossbow and the human // character model. rotate_x = 0.0f; rotate_y = 0.0f; if(fa_plyRotByHeadRot) { if(fabs(yRot) > fa_plyRotByHeadRot_yawMin) { float n_yRot = (fabs(yRot) - fa_plyRotByHeadRot_yawMin) / (fa_plyRotByHeadRot_yawMax - fa_plyRotByHeadRot_yawMin); if(n_yRot > 1.0f) n_yRot = 1.0f; if(n_yRot > 0.0f) n_yRot = pow(n_yRot, fa_plyRotByHeadRot_ease); rotate_x = n_yRot * fa_plyRotByHeadRot_yawSpeed * (yRot / fabs(yRot)); } float off_xRot = xRot - learnt_xRot; if(fabs(off_xRot) > fa_plyRotByHeadRot_pitchMin) { float n_xRot = (fabs(off_xRot) - fa_plyRotByHeadRot_pitchMin) / (fa_plyRotByHeadRot_pitchMax - fa_plyRotByHeadRot_pitchMin); if(n_xRot > 1.0f) n_xRot = 1.0f; if(n_xRot > 0.0f) n_xRot = pow(n_xRot, fa_plyRotByHeadRot_ease); rotate_y = n_xRot * fa_plyRotByHeadRot_pitchSpeed * (off_xRot / fabs(off_xRot)); } } } else { m_View.fov = ScaleFOVByWidthRatio( m_View.fov, aspectRatio ); m_View.fovViewmodel = ScaleFOVByWidthRatio( m_View.fovViewmodel, aspectRatio ); } //m_View.fov = ScaleFOVByWidthRatio( m_View.fov, aspectRatio ); //m_View.fovViewmodel = ScaleFOVByWidthRatio( m_View.fovViewmodel, aspectRatio ); // Let the client mode hook stuff. g_pClientMode->PreRender(&m_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(); float engineAspectRatio = engine->GetScreenAspectRatio(); m_View.x = vr.x; m_View.y = vr.y; m_View.width = vr.width * flViewportScale; m_View.height = vr.height * flViewportScale; m_View.m_flAspectRatio = ( engineAspectRatio > 0.0f ) ? engineAspectRatio : ( (float)m_View.width / (float)m_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; } // Determine if we should draw view model ( client mode override ) drawViewModel = g_pClientMode->ShouldDrawViewModel(); if ( cl_leveloverview.GetFloat() > 0 ) { SetUpOverView(); nClearFlags |= VIEW_CLEAR_COLOR; drawViewModel = false; } // Apply any player specific overrides //C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); if ( pPlayer ) { // Override view model if necessary if ( !pPlayer->m_Local.m_bDrawViewmodel ) { drawViewModel = false; } } if(fa_weapon) drawViewModel = false; render->SetMainView( m_View.origin, m_View.angles ); int flags = RENDERVIEW_DRAWHUD; if ( drawViewModel ) { flags |= RENDERVIEW_DRAWVIEWMODEL; } RenderView( m_View, nClearFlags, flags ); g_pClientMode->PostRender(); engine->EngineStats_EndFrame(); #if !defined( _X360 ) // Stop stubbing the material system so we can see the budget panel matStub.End(); #endif CViewSetup view2d; // Draw all of the UI stuff "fullscreen" 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 ); render->PopView( GetFrustum() ); }