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;
|
|
|
|
float lerp, backlerp;
|
|
|
|
frame_t *oldframe;
|
|
|
|
entity_state_t *ps, *ops;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
// see if the player entity was teleported this frame
|
|
|
|
if( ps->ed_flags & ESF_NO_PREDICTION )
|
|
|
|
ops = ps; // don't interpolate
|
|
|
|
lerp = cl.refdef.lerpfrac;
|
|
|
|
|
|
|
|
if( cl.time > cl.frame.servertime )
|
|
|
|
{
|
|
|
|
if( cl_showclamp->integer )
|
|
|
|
MsgDev( D_NOTE, "cl_highclamp %i\n", cl.time - cl.frame.servertime );
|
|
|
|
cl.time = cl.frame.servertime;
|
|
|
|
cl.refdef.lerpfrac = 1.0f;
|
|
|
|
}
|
|
|
|
else if( cl.time < cl.frame.servertime - Host_FrameTime())
|
|
|
|
{
|
|
|
|
if( cl_showclamp->integer )
|
|
|
|
MsgDev( D_NOTE, "cl_lowclamp %i\n", cl.frame.servertime - Host_FrameTime() - cl.time );
|
|
|
|
cl.time = cl.frame.servertime - Host_FrameTime();
|
|
|
|
cl.refdef.lerpfrac = 0.0f;
|
|
|
|
}
|
|
|
|
else cl.refdef.lerpfrac = 1.0 - (cl.frame.servertime - cl.time) * 0.01f;
|
|
|
|
|
|
|
|
// 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 );
|
|
|
|
|
|
|
|
cl.refdef.movevars = &clgame.movevars;
|
|
|
|
|
|
|
|
if( ps->flags & FL_ONGROUND )
|
|
|
|
cl.refdef.onground = EDICT_NUM( ps->groundent );
|
|
|
|
else cl.refdef.onground = NULL;
|
|
|
|
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;
|
|
|
|
cl.refdef.oldtime = (cl.oldtime * 0.001f);
|
|
|
|
cl.refdef.time = (cl.time * 0.001f); // cl.time for right lerping
|
|
|
|
cl.refdef.frametime = cls.frametime;
|
|
|
|
cl.refdef.demoplayback = cls.demoplayback;
|
|
|
|
cl.refdef.demorecord = cls.demorecording;
|
|
|
|
cl.refdef.paused = cl_paused->integer;
|
|
|
|
cl.refdef.predicting = cl_predict->integer;
|
|
|
|
|
|
|
|
// invalid values
|
|
|
|
cl.refdef.waterlevel = 0; // FIXME: calc it again
|
|
|
|
cl.refdef.smoothing = 0; // FIXME: detect right settings
|
|
|
|
cl.refdef.viewentity = NULL; // remove ???
|
|
|
|
VectorClear( cl.refdef.crosshairangle );
|
|
|
|
|
|
|
|
// calculate the origin
|
|
|
|
if( cl.refdef.predicting && !cl.refdef.demoplayback )
|
|
|
|
{
|
|
|
|
// use predicted values
|
|
|
|
int delta;
|
|
|
|
|
|
|
|
backlerp = 1.0 - lerp;
|
|
|
|
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
|
|
|
|
delta = cls.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
|
|
|
// in-game use predicted values
|
|
|
|
for( i = 0; i < 3; i++ ) cl.refdef.viewangles[i] = cl.predicted_angles[i];
|
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-22 22:00:00 +01:00
|
|
|
void V_ApplyRefDef( void )
|
2007-06-21 22:00:00 +02:00
|
|
|
{
|
2009-01-22 22:00:00 +01:00
|
|
|
cl.refdef.areabits = cl.frame.areabits;
|
|
|
|
cl.refdef.fov_y = V_CalcFov( cl.refdef.fov_x, cl.refdef.viewport[2], cl.refdef.viewport[3] );
|
2008-08-02 22:00:00 +02:00
|
|
|
|
2009-01-22 22:00:00 +01:00
|
|
|
if( cl.frame.ps.renderfx == kRenderFxUnderwater )
|
|
|
|
{
|
|
|
|
float f = com.sin( cl.time * 0.001 * 0.4 * (M_PI * 2.7));
|
|
|
|
cl.refdef.fov_x += f;
|
|
|
|
cl.refdef.fov_y -= f;
|
|
|
|
}
|
|
|
|
if( cl.viewent.v.modelindex )
|
|
|
|
{
|
|
|
|
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-22 22:00:00 +01:00
|
|
|
cls.dllFuncs.pfnCalcRefdef( &cl.refdef );
|
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
|
|
|
|
|
|
|
// an invalid frame will just use the exact previous refdef
|
|
|
|
// we can't use the old frame if the video mode has changed, though...
|
2009-01-22 22:00:00 +01:00
|
|
|
if( cl.frame.valid && (cl.force_refdef || !cl_paused->value ))
|
2007-06-21 22:00:00 +02:00
|
|
|
{
|
|
|
|
cl.force_refdef = false;
|
2008-08-02 22:00:00 +02:00
|
|
|
V_ClearScene();
|
2007-06-21 22:00:00 +02:00
|
|
|
|
|
|
|
// build a refresh entity list and calc cl.sim*
|
|
|
|
// this also calls CL_CalcViewValues which loads
|
2008-12-26 22:00:00 +01:00
|
|
|
// refdef.forward, etc.
|
2007-06-21 22:00:00 +02:00
|
|
|
CL_AddEntities ();
|
|
|
|
|
2009-01-22 22:00:00 +01:00
|
|
|
V_SetupRefDef ();
|
|
|
|
V_CalcRefDef ();
|
|
|
|
V_ApplyRefDef ();
|
2007-06-21 22:00:00 +02:00
|
|
|
}
|
2008-08-02 22:00:00 +02:00
|
|
|
re->RenderFrame( &cl.refdef );
|
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-13 22:00:00 +01:00
|
|
|
SCR_FillRect( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, g_color_table[0] );
|
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
|
|
|
}
|