2007-06-21 22:00:00 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 1997-2001 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
// cl_view.c -- player rendering positioning
|
|
|
|
|
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"
|
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
|
|
|
{
|
2008-08-29 22:00:00 +02:00
|
|
|
re->ClearScene();
|
2007-06-21 22:00:00 +02:00
|
|
|
}
|
|
|
|
|
2007-11-06 22:00:00 +01:00
|
|
|
/*
|
2009-01-22 22:00:00 +01:00
|
|
|
====================
|
|
|
|
V_CalcFov
|
|
|
|
====================
|
2007-11-06 22:00:00 +01:00
|
|
|
*/
|
2009-01-22 22:00:00 +01:00
|
|
|
float V_CalcFov( float fov_x, float width, float height )
|
2007-11-06 22:00:00 +01:00
|
|
|
{
|
2009-01-22 22:00:00 +01:00
|
|
|
float fov_y, x, rad = 360.0f * M_PI;
|
|
|
|
|
|
|
|
// check to avoid division by zero
|
|
|
|
if( fov_x == 0 ) Host_Error( "V_CalcFov: null fov!\n" );
|
|
|
|
|
|
|
|
// make sure that fov in-range
|
|
|
|
fov_x = bound( 1, fov_x, 179 );
|
|
|
|
x = width / tan( fov_x / rad );
|
|
|
|
fov_y = atan2( height, x );
|
|
|
|
fov_y = (fov_y * rad);
|
|
|
|
|
|
|
|
return fov_y;
|
2007-11-06 22:00:00 +01:00
|
|
|
}
|
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
|
|
|
{
|
2009-01-22 22:00:00 +01:00
|
|
|
int i;
|
2009-02-03 22:00:00 +01:00
|
|
|
float backlerp;
|
2009-01-22 22:00:00 +01:00
|
|
|
frame_t *oldframe;
|
|
|
|
entity_state_t *ps, *ops;
|
2009-01-23 22:00:00 +01:00
|
|
|
edict_t *clent;
|
2009-01-22 22:00:00 +01:00
|
|
|
|
|
|
|
// find the previous frame to interpolate from
|
|
|
|
ps = &cl.frame.ps;
|
|
|
|
i = (cl.frame.serverframe - 1) & UPDATE_MASK;
|
|
|
|
oldframe = &cl.frames[i];
|
|
|
|
if( oldframe->serverframe != cl.frame.serverframe-1 || !oldframe->valid )
|
|
|
|
oldframe = &cl.frame; // previous frame was dropped or invalid
|
|
|
|
ops = &oldframe->ps;
|
|
|
|
|
2009-01-23 22:00:00 +01:00
|
|
|
clent = EDICT_NUM( cl.playernum + 1 );
|
|
|
|
|
2009-01-22 22:00:00 +01:00
|
|
|
// see if the player entity was teleported this frame
|
|
|
|
if( ps->ed_flags & ESF_NO_PREDICTION )
|
|
|
|
ops = ps; // don't interpolate
|
|
|
|
|
2009-01-23 22:00:00 +01:00
|
|
|
// UNDONE: temporary place for detect waterlevel
|
|
|
|
CL_CheckWater( clent );
|
|
|
|
|
2009-01-22 22:00:00 +01:00
|
|
|
// interpolate field of view
|
|
|
|
cl.data.fov = ops->fov + cl.refdef.lerpfrac * ( ps->fov - ops->fov );
|
|
|
|
|
|
|
|
VectorCopy( ps->velocity, cl.refdef.velocity );
|
|
|
|
VectorCopy( ps->origin, cl.refdef.origin );
|
|
|
|
VectorCopy( ops->origin, cl.refdef.prev.origin );
|
|
|
|
VectorCopy( ps->angles, cl.refdef.angles );
|
|
|
|
VectorCopy( ops->angles, cl.refdef.prev.angles );
|
|
|
|
VectorCopy( ps->viewoffset, cl.refdef.viewheight );
|
|
|
|
VectorCopy( ops->viewoffset, cl.refdef.prev.viewheight );
|
|
|
|
VectorCopy( ps->punch_angles, cl.refdef.punchangle );
|
|
|
|
VectorCopy( ops->punch_angles, cl.refdef.prev.punchangle );
|
2009-01-23 22:00:00 +01:00
|
|
|
VectorCopy( cl.predicted_angles, cl.refdef.cl_viewangles );
|
2009-01-22 22:00:00 +01:00
|
|
|
|
|
|
|
cl.refdef.movevars = &clgame.movevars;
|
|
|
|
|
|
|
|
if( ps->flags & FL_ONGROUND )
|
|
|
|
cl.refdef.onground = EDICT_NUM( ps->groundent );
|
|
|
|
else cl.refdef.onground = NULL;
|
2009-01-23 22:00:00 +01:00
|
|
|
cl.refdef.areabits = cl.frame.areabits;
|
2009-01-22 22:00:00 +01:00
|
|
|
cl.refdef.clientnum = cl.playernum; // not a entity num
|
|
|
|
cl.refdef.viewmodel = ps->viewmodel;
|
|
|
|
cl.refdef.health = ps->health;
|
|
|
|
cl.refdef.num_entities = clgame.numEntities;
|
|
|
|
cl.refdef.max_entities = clgame.maxEntities;
|
|
|
|
cl.refdef.max_clients = clgame.maxClients;
|
2009-02-03 22:00:00 +01:00
|
|
|
cl.refdef.oldtime = cl.oldtime;
|
|
|
|
cl.refdef.time = cl.time; // cl.time for right lerping
|
|
|
|
cl.refdef.frametime = host.frametime;
|
2009-01-22 22:00:00 +01:00
|
|
|
cl.refdef.demoplayback = cls.demoplayback;
|
|
|
|
cl.refdef.demorecord = cls.demorecording;
|
|
|
|
cl.refdef.paused = cl_paused->integer;
|
|
|
|
cl.refdef.predicting = cl_predict->integer;
|
2009-01-23 22:00:00 +01:00
|
|
|
cl.refdef.waterlevel = clent->v.waterlevel;
|
|
|
|
cl.refdef.nextView = 0;
|
2009-01-22 22:00:00 +01:00
|
|
|
|
|
|
|
// calculate the origin
|
|
|
|
if( cl.refdef.predicting && !cl.refdef.demoplayback )
|
|
|
|
{
|
|
|
|
// use predicted values
|
|
|
|
int delta;
|
|
|
|
|
2009-02-03 22:00:00 +01:00
|
|
|
backlerp = 1.0 - cl.refdef.lerpfrac;
|
2009-01-22 22:00:00 +01:00
|
|
|
for( i = 0; i < 3; i++ )
|
|
|
|
{
|
|
|
|
cl.refdef.vieworg[i] = cl.predicted_origin[i] + ops->viewoffset[i]
|
|
|
|
+ cl.refdef.lerpfrac * (ps->viewoffset[i] - ops->viewoffset[i]) - backlerp * cl.prediction_error[i];
|
|
|
|
}
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2009-01-22 22:00:00 +01:00
|
|
|
// smooth out stair climbing
|
2009-02-03 22:00:00 +01:00
|
|
|
delta = host.realtime - cl.predicted_step_time;
|
|
|
|
if( delta < host.frametime ) cl.refdef.vieworg[2] -= cl.predicted_step * (host.frametime - delta) * 0.01f;
|
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-01-23 22:00:00 +01:00
|
|
|
if( !cl.viewent.v.modelindex || cl.refdef.nextView ) return;
|
|
|
|
re->AddRefEntity( &cl.viewent, ED_VIEWMODEL, cl.refdef.lerpfrac );
|
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
|
|
|
|
{
|
|
|
|
cls.dllFuncs.pfnCalcRefdef( &cl.refdef );
|
|
|
|
V_AddViewModel();
|
2009-01-25 22:00:00 +01:00
|
|
|
re->RenderFrame( &cl.refdef );
|
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
|
|
|
|
2009-01-25 22:00:00 +01:00
|
|
|
if( !cl.frame.valid )
|
2007-06-21 22:00:00 +02:00
|
|
|
{
|
2009-01-25 22:00:00 +01:00
|
|
|
SCR_FillRect( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, g_color_table[0] );
|
|
|
|
return;
|
|
|
|
}
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2009-01-25 22:00:00 +01:00
|
|
|
V_ClearScene ();
|
|
|
|
CL_AddEntities ();
|
2007-06-21 22:00:00 +02:00
|
|
|
|
2009-01-25 22:00:00 +01:00
|
|
|
V_SetupRefDef ();
|
|
|
|
V_CalcRefDef ();
|
2007-06-21 22:00:00 +02:00
|
|
|
}
|
|
|
|
|
2007-11-06 22:00:00 +01:00
|
|
|
/*
|
|
|
|
==================
|
|
|
|
V_PreRender
|
|
|
|
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
bool V_PreRender( void )
|
|
|
|
{
|
2008-05-18 22:00:00 +02:00
|
|
|
// too early
|
2008-08-02 22:00:00 +02:00
|
|
|
if( !re ) return false;
|
2007-11-06 22:00:00 +01:00
|
|
|
|
2008-10-19 22:00:00 +02:00
|
|
|
re->BeginFrame();
|
2007-11-06 22:00:00 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
V_PostRender
|
|
|
|
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
void V_PostRender( void )
|
|
|
|
{
|
2008-12-26 22:00:00 +01:00
|
|
|
SCR_DrawNet();
|
|
|
|
SCR_DrawFPS();
|
2008-06-28 22:00:00 +02:00
|
|
|
UI_Draw();
|
2008-06-30 22:00:00 +02:00
|
|
|
Con_DrawConsole();
|
2007-11-06 22:00:00 +01:00
|
|
|
re->EndFrame();
|
2008-07-17 22:00:00 +02:00
|
|
|
}
|