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

218 lines
5.1 KiB
C
Raw Normal View History

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"
/*
====================
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-02 22:00:00 +02:00
re->ClearScene( &cl.refdef );
2007-06-21 22:00:00 +02:00
}
2007-11-06 22:00:00 +01:00
/*
=================
void V_CalcRect( void )
Sets scr_vrect, the coordinates of the rendered window
=================
*/
void V_CalcRect( void )
{
2007-11-18 22:00:00 +01:00
scr_vrect.width = scr_width->integer;
2007-11-06 22:00:00 +01:00
scr_vrect.width &= ~7;
2007-11-18 22:00:00 +01:00
scr_vrect.height = scr_height->integer;
2007-11-06 22:00:00 +01:00
scr_vrect.height &= ~1;
scr_vrect.y = scr_vrect.x = 0;
}
2007-06-21 22:00:00 +02:00
/*
================
V_TestEntities
If cl_testentities is set, create 32 player models
================
*/
2008-08-02 22:00:00 +02:00
void V_TestEntities( void )
2007-06-21 22:00:00 +02:00
{
2008-07-17 22:00:00 +02:00
int i, j;
2007-06-21 22:00:00 +02:00
float f, r;
2008-08-02 22:00:00 +02:00
entity_state_t ent;
2007-06-21 22:00:00 +02:00
2008-08-02 22:00:00 +02:00
memset( &ent, 0, sizeof(entity_state_t));
cl.refdef.num_entities = 0;
2007-06-21 22:00:00 +02:00
2008-08-02 22:00:00 +02:00
for( i = 0; i < 32; i++ )
2007-06-21 22:00:00 +02:00
{
2008-07-17 22:00:00 +02:00
r = 64 * ((i%4) - 1.5 );
2007-06-21 22:00:00 +02:00
f = 64 * (i/4) + 128;
2008-07-17 22:00:00 +02:00
for( j = 0; j < 3; j++ )
2008-08-02 22:00:00 +02:00
ent.origin[j] = cl.refdef.vieworg[j] + cl.v_forward[j] * f + cl.v_right[j] * r;
ent.model.controller[0] = ent.model.controller[1] = 90.0f;
ent.model.controller[2] = ent.model.controller[3] = 180.0f;
ent.model.index = cl.frame.ps.model.index;
re->AddRefEntity( &cl.refdef, &ent, NULL, 1.0f );
2007-06-21 22:00:00 +02:00
}
}
/*
================
V_TestLights
If cl_testlights is set, create 32 lights models
================
*/
2008-08-02 22:00:00 +02:00
void V_TestLights( void )
2007-06-21 22:00:00 +02:00
{
2008-08-02 22:00:00 +02:00
int i, j;
2007-06-21 22:00:00 +02:00
float f, r;
2008-08-02 22:00:00 +02:00
cdlight_t dl;
2007-06-21 22:00:00 +02:00
2008-08-02 22:00:00 +02:00
cl.refdef.num_dlights = 0;
memset( &dl, 0, sizeof(cdlight_t));
2007-06-21 22:00:00 +02:00
2008-08-02 22:00:00 +02:00
for( i = 0; i < 32; i++ )
2007-06-21 22:00:00 +02:00
{
r = 64 * ( (i%4) - 1.5 );
f = 64 * (i/4) + 128;
2008-08-02 22:00:00 +02:00
for( j = 0; j < 3; j++ )
dl.origin[j] = cl.refdef.vieworg[j] + cl.v_forward[j] * f + cl.v_right[j] * r;
dl.color[0] = ((i%6)+1) & 1;
dl.color[1] = (((i%6)+1) & 2)>>1;
dl.color[2] = (((i%6)+1) & 4)>>2;
dl.radius = 200;
re->AddDynLight( &cl.refdef, dl.origin, dl.color, dl.radius );
2007-06-21 22:00:00 +02:00
}
}
/*
====================
2008-06-28 22:00:00 +02:00
V_CalcFov
2007-06-21 22:00:00 +02:00
====================
*/
2008-06-28 22:00:00 +02:00
float V_CalcFov( float fov_x, float width, float height )
2007-06-21 22:00:00 +02:00
{
2008-01-12 22:00:00 +01:00
float fov_y, x, rad = 360.0f * M_PI;
2007-06-21 22:00:00 +02:00
2008-08-02 22:00:00 +02:00
// check to avoid division by zero
if( fov_x == 0 ) Host_Error( "V_CalcFov: null fov!\n" );
// make sure that fov in-range
2008-01-12 22:00:00 +01:00
fov_x = bound( 1, fov_x, 179 );
x = width / tan( fov_x / rad );
fov_y = atan2( height, x );
fov_y = (fov_y * rad);
2007-06-21 22:00:00 +02:00
2008-01-12 22:00:00 +01:00
return fov_y;
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...
if ( cl.frame.valid && (cl.force_refdef || !cl_paused->value) )
{
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
// v_forward, etc.
2008-07-11 22:00:00 +02:00
CL_VM_Begin();
2007-06-21 22:00:00 +02:00
CL_AddEntities ();
2008-08-02 22:00:00 +02:00
if( cl_testentities->value ) V_TestEntities();
if( cl_testlights->value ) V_TestLights();
if( cl_testblend->value)
2007-06-21 22:00:00 +02:00
{
cl.refdef.blend[0] = 1;
cl.refdef.blend[1] = 0.5;
cl.refdef.blend[2] = 0.25;
2008-08-02 22:00:00 +02:00
cl.refdef.blend[3] = 0.8;
2007-06-21 22:00:00 +02:00
}
// never let it sit exactly on a node line, because a water plane can
// dissapear when viewed with the eye exactly on it.
2008-08-01 22:00:00 +02:00
// the server protocol only specifies to 1/16 pixel, so add 1/32 in each axis
cl.refdef.vieworg[0] += 1.0 / 32;
cl.refdef.vieworg[1] += 1.0 / 32;
cl.refdef.vieworg[2] += 1.0 / 32;
2007-06-21 22:00:00 +02:00
2008-08-02 22:00:00 +02:00
Mem_Copy( &cl.refdef.rect, &scr_vrect, sizeof(vrect_t));
cl.refdef.areabits = cl.frame.areabits;
cl.refdef.rdflags = cl.frame.ps.renderfx;
cl.refdef.fov_y = V_CalcFov( cl.refdef.fov_x, cl.refdef.rect.width, cl.refdef.rect.height );
2008-08-05 22:00:00 +02:00
cl.refdef.time = cl.time * 0.001f; // cl.time for right lerping
cl.refdef.oldtime = cl.oldtime * 0.001f;
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
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-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
}