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

214 lines
4.7 KiB
C
Raw Normal View History

2009-11-23 22:00:00 +01:00
//=======================================================================
// Copyright XashXT Group 2009 <20>
// cl_view.c - player rendering positioning
//=======================================================================
2007-06-21 22:00:00 +02:00
2008-06-09 22:00:00 +02:00
#include "common.h"
2007-06-21 22:00:00 +02:00
#include "client.h"
2008-11-25 22:00:00 +01:00
#include "const.h"
2010-08-15 22:00:00 +02:00
#include "entity_types.h"
2007-06-21 22:00:00 +02:00
/*
====================
V_ClearScene
Specifies the model that will be used as the world
====================
*/
2008-08-02 22:00:00 +02:00
void V_ClearScene( void )
2007-06-21 22:00:00 +02:00
{
2010-07-18 22:00:00 +02:00
if( re ) re->ClearScene();
2007-06-21 22:00:00 +02:00
}
2010-11-15 22:00:00 +01:00
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;
}
2007-06-21 22:00:00 +02:00
/*
2009-01-22 22:00:00 +01:00
===============
V_SetupRefDef
2007-06-21 22:00:00 +02:00
2009-01-22 22:00:00 +01:00
update refdef values each frame
===============
2007-06-21 22:00:00 +02:00
*/
2009-01-22 22:00:00 +01:00
void V_SetupRefDef( void )
2007-06-21 22:00:00 +02:00
{
2010-08-07 22:00:00 +02:00
cl_entity_t *clent;
2009-01-22 22:00:00 +01:00
2009-11-26 22:00:00 +01:00
clent = CL_GetLocalPlayer ();
2009-01-23 22:00:00 +01:00
2010-11-15 22:00:00 +01:00
VectorCopy( cl.frame.local.client.punchangle, cl.refdef.punchangle );
clgame.viewent.curstate.modelindex = cl.frame.local.client.viewmodel;
2010-08-20 22:00:00 +02:00
2009-01-22 22:00:00 +01:00
cl.refdef.movevars = &clgame.movevars;
2010-11-15 22:00:00 +01:00
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;
2010-08-20 22:00:00 +02:00
cl.refdef.max_entities = clgame.maxEntities;
cl.refdef.maxclients = cl.maxclients;
2010-07-23 22:00:00 +02:00
cl.refdef.time = cl_time();
2010-10-09 22:00:00 +02:00
cl.refdef.frametime = cl.time - cl.oldtime;
2009-01-22 22:00:00 +01:00
cl.refdef.demoplayback = cls.demoplayback;
2010-06-20 22:00:00 +02:00
cl.refdef.smoothing = cl_smooth->integer;
2010-11-15 22:00:00 +01:00
cl.refdef.waterlevel = cl.frame.local.client.waterlevel;
cl.refdef.viewsize = 120; // FIXME if you can
cl.refdef.hardware = true; // always true
2009-01-23 22:00:00 +01:00
cl.refdef.nextView = 0;
2009-01-22 22:00:00 +01:00
2010-08-20 22:00:00 +02:00
// 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;
2010-11-15 22:00:00 +01:00
// 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] );
2009-01-22 22:00:00 +01:00
// calculate the origin
2010-03-14 22:00:00 +01:00
if( CL_IsPredicted( ) && !cl.refdef.demoplayback )
2009-01-22 22:00:00 +01:00
{
// use predicted values
2010-02-10 22:00:00 +01:00
float backlerp = 1.0f - cl.lerpFrac;
2010-06-20 22:00:00 +02:00
int i;
2009-01-22 22:00:00 +01:00
for( i = 0; i < 3; i++ )
2009-12-05 22:00:00 +01:00
{
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
{
2010-08-07 22:00:00 +02:00
VectorCopy( clent->origin, cl.refdef.simorg );
2010-11-15 22:00:00 +01:00
VectorCopy( cl.frame.local.client.view_ofs, cl.refdef.viewheight );
VectorCopy( cl.frame.local.client.velocity, cl.refdef.simvel );
2007-06-21 22:00:00 +02:00
}
}
/*
2009-01-22 22:00:00 +01:00
===============
V_ApplyRefDef
2007-06-21 22:00:00 +02:00
2009-01-22 22:00:00 +01:00
apply pre-calculated values
===============
2007-06-21 22:00:00 +02:00
*/
2009-01-23 22:00:00 +01:00
void V_AddViewModel( void )
2007-06-21 22:00:00 +02:00
{
2009-09-28 22:00:00 +02:00
if( cl.refdef.nextView ) return; // add viewmodel only at firstperson pass
2010-11-15 22:00:00 +01:00
if( !cl.frame.valid || cl.refdef.paused || cl.thirdperson ) return;
2010-02-23 22:00:00 +01:00
2010-11-15 22:00:00 +01:00
CL_AddVisibleEntity( &clgame.viewent, ET_VIEWENTITY );
2007-06-21 22:00:00 +02:00
}
/*
2009-01-22 22:00:00 +01:00
===============
V_CalcRefDef
sets cl.refdef view values
===============
2007-06-21 22:00:00 +02:00
*/
2009-01-22 22:00:00 +01:00
void V_CalcRefDef( void )
2007-06-21 22:00:00 +02:00
{
2009-01-23 22:00:00 +01:00
do
{
2009-06-24 22:00:00 +02:00
clgame.dllFuncs.pfnCalcRefdef( &cl.refdef );
2009-01-23 22:00:00 +01:00
V_AddViewModel();
2010-11-15 22:00:00 +01:00
re->RenderFrame( &cl.refdef, true );
2009-01-23 22:00:00 +01:00
} while( cl.refdef.nextView );
2007-06-21 22:00:00 +02:00
}
//============================================================================
/*
==================
V_RenderView
==================
*/
2007-11-05 22:00:00 +01:00
void V_RenderView( void )
2007-06-21 22:00:00 +02:00
{
2008-08-03 22:00:00 +02:00
if( !cl.video_prepped ) return; // still loading
2007-06-21 22:00:00 +02:00
2010-07-13 22:00:00 +02:00
if( cl.frame.valid && ( cl.force_refdef || !cl.refdef.paused ))
2007-06-21 22:00:00 +02:00
{
2009-09-28 22:00:00 +02:00
cl.force_refdef = false;
2007-06-21 22:00:00 +02:00
2009-09-28 22:00:00 +02:00
V_ClearScene ();
CL_AddEntities ();
V_SetupRefDef ();
}
2007-06-21 22:00:00 +02:00
2009-01-25 22:00:00 +01:00
V_CalcRefDef ();
2007-06-21 22:00:00 +02:00
}
2007-11-06 22:00:00 +01:00
/*
==================
V_PreRender
==================
*/
2010-10-26 22:00:00 +02:00
qboolean V_PreRender( void )
2007-11-06 22:00:00 +01:00
{
2010-10-26 22:00:00 +02:00
qboolean clearScene = true;
static qboolean oldState;
2010-03-30 22:00:00 +02:00
2008-05-18 22:00:00 +02:00
// too early
2008-08-02 22:00:00 +02:00
if( !re ) return false;
2009-07-17 22:00:00 +02:00
2010-02-07 22:00:00 +01:00
if( host.state == HOST_NOFOCUS )
return false;
if( host.state == HOST_SLEEP )
return false;
2010-07-17 22:00:00 +02:00
if( cl.refdef.paused || cls.changelevel )
2010-03-30 22:00:00 +02:00
clearScene = false;
re->BeginFrame( clearScene );
2010-04-12 22:00:00 +02:00
2010-07-17 22:00:00 +02:00
if( !oldState && cls.changelevel )
2010-04-12 22:00:00 +02:00
{
// fire once
CL_DrawHUD( CL_CHANGELEVEL );
re->EndFrame();
}
2010-07-17 22:00:00 +02:00
oldState = cls.changelevel;
2010-04-12 22:00:00 +02:00
2010-07-17 22:00:00 +02:00
if( cls.changelevel )
return false;
return true;
2007-11-06 22:00:00 +01:00
}
/*
==================
V_PostRender
==================
*/
void V_PostRender( void )
{
2009-09-23 22:00:00 +02:00
if( cls.scrshot_action == scrshot_inactive )
{
SCR_RSpeeds();
2010-07-26 22:00:00 +02:00
SCR_NetSpeeds();
2009-09-23 22:00:00 +02:00
SCR_DrawFPS();
2010-10-09 22:00:00 +02:00
UI_UpdateMenu( host.realtime );
2009-09-23 22:00:00 +02:00
Con_DrawConsole();
2010-10-09 22:00:00 +02:00
S_ExtraUpdate();
2009-09-23 22:00:00 +02:00
}
2010-07-23 22:00:00 +02:00
2009-12-11 22:00:00 +01:00
SCR_MakeScreenShot();
2007-11-06 22:00:00 +01:00
re->EndFrame();
2008-07-17 22:00:00 +02:00
}