This repository has been archived on 2022-06-27. You can view files and clone it, but cannot push or open issues or pull requests.
Xash3DArchive/engine/client/cl_view.c
2022-06-27 01:15:11 +03:00

216 lines
4.7 KiB
C

//=======================================================================
// Copyright XashXT Group 2009 ©
// cl_view.c - player rendering positioning
//=======================================================================
#include "common.h"
#include "client.h"
#include "const.h"
#include "entity_types.h"
#include "gl_local.h"
/*
====================
V_ClearScene
Specifies the model that will be used as the world
====================
*/
void V_ClearScene( void )
{
R_ClearScene();
}
float V_CalcFov( float fov_x, float width, float height )
{
float x, half_fov_y;
// check to avoid division by zero
if( fov_x < 1 || fov_x > 179 )
{
MsgDev( D_ERROR, "V_CalcFov: invalid fov %g!\n", fov_x );
fov_x = 90;
}
x = width / com.tan( DEG2RAD( fov_x ) * 0.5f );
half_fov_y = atan( height / x );
return RAD2DEG( half_fov_y ) * 2;
}
/*
===============
V_SetupRefDef
update refdef values each frame
===============
*/
void V_SetupRefDef( void )
{
cl_entity_t *clent;
clent = CL_GetLocalPlayer ();
VectorCopy( cl.frame.local.client.punchangle, cl.refdef.punchangle );
clgame.viewent.curstate.modelindex = cl.frame.local.client.viewmodel;
cl.refdef.movevars = &clgame.movevars;
cl.refdef.onground = ( cl.frame.local.client.flags & FL_ONGROUND ) ? 1 : 0;
cl.refdef.health = cl.frame.local.client.health;
cl.refdef.playernum = cl.playernum;
cl.refdef.max_entities = clgame.maxEntities;
cl.refdef.maxclients = cl.maxclients;
cl.refdef.time = cl_time();
cl.refdef.frametime = cl.time - cl.oldtime;
cl.refdef.demoplayback = cls.demoplayback;
cl.refdef.smoothing = cl_smooth->integer;
cl.refdef.waterlevel = cl.frame.local.client.waterlevel;
cl.refdef.viewsize = 120; // FIXME if you can
cl.refdef.hardware = true; // always true
cl.refdef.nextView = 0;
// setup default viewport
cl.refdef.viewport[0] = cl.refdef.viewport[1] = 0;
cl.refdef.viewport[2] = scr_width->integer;
cl.refdef.viewport[3] = scr_height->integer;
// calc FOV
cl.refdef.fov_x = cl.data.fov; // this is a final fov value
cl.refdef.fov_y = V_CalcFov( cl.refdef.fov_x, cl.refdef.viewport[2], cl.refdef.viewport[3] );
// calculate the origin
if( CL_IsPredicted( ) && !cl.refdef.demoplayback )
{
// use predicted values
float backlerp = 1.0f - cl.lerpFrac;
int i;
for( i = 0; i < 3; i++ )
{
cl.refdef.simorg[i] = cl.predicted_origin[i] - backlerp * cl.prediction_error[i];
cl.refdef.viewheight[i] = cl.predicted_viewofs[i] - backlerp * cl.prediction_error[i];
}
VectorCopy( cl.predicted_velocity, cl.refdef.simvel );
}
else
{
VectorCopy( clent->origin, cl.refdef.simorg );
VectorCopy( cl.frame.local.client.view_ofs, cl.refdef.viewheight );
VectorCopy( cl.frame.local.client.velocity, cl.refdef.simvel );
}
}
/*
===============
V_ApplyRefDef
apply pre-calculated values
===============
*/
void V_AddViewModel( void )
{
if( cl.refdef.nextView ) return; // add viewmodel only at firstperson pass
if( !cl.frame.valid || cl.refdef.paused || cl.thirdperson ) return;
CL_AddVisibleEntity( &clgame.viewent, ET_VIEWENTITY );
}
/*
===============
V_CalcRefDef
sets cl.refdef view values
===============
*/
void V_CalcRefDef( void )
{
do
{
clgame.dllFuncs.pfnCalcRefdef( &cl.refdef );
V_AddViewModel();
R_RenderFrame( &cl.refdef, true );
} while( cl.refdef.nextView );
}
//============================================================================
/*
==================
V_RenderView
==================
*/
void V_RenderView( void )
{
if( !cl.video_prepped ) return; // still loading
if( cl.frame.valid && ( cl.force_refdef || !cl.refdef.paused ))
{
cl.force_refdef = false;
V_ClearScene ();
CL_AddEntities ();
V_SetupRefDef ();
}
V_CalcRefDef ();
}
/*
==================
V_PreRender
==================
*/
qboolean V_PreRender( void )
{
qboolean clearScene = true;
static qboolean oldState;
// too early
if( !glw_state.initialized )
return false;
if( host.state == HOST_NOFOCUS )
return false;
if( host.state == HOST_SLEEP )
return false;
if( cl.refdef.paused || cls.changelevel )
clearScene = false;
R_BeginFrame( clearScene );
if( !oldState && cls.changelevel )
{
// fire once
CL_DrawHUD( CL_CHANGELEVEL );
R_EndFrame();
}
oldState = cls.changelevel;
if( cls.changelevel )
return false;
return true;
}
/*
==================
V_PostRender
==================
*/
void V_PostRender( void )
{
if( cls.scrshot_action == scrshot_inactive )
{
SCR_RSpeeds();
SCR_NetSpeeds();
SCR_DrawFPS();
UI_UpdateMenu( host.realtime );
Con_DrawConsole();
S_ExtraUpdate();
}
SCR_MakeScreenShot();
R_EndFrame();
}