Portable Half-Life SDK. GoldSource and Xash3D. Crossplatform.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1690 lines
41 KiB

//========= Copyright (c) 1996-2002, Valve LLC, All rights reserved. ============
9 years ago
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
// view/refresh setup functions
#include "hud.h"
#include "cl_util.h"
#include "cvardef.h"
#include "usercmd.h"
#include "const.h"
#include "entity_state.h"
#include "cl_entity.h"
#include "ref_params.h"
#include "in_defs.h" // PITCH YAW ROLL
#include "pm_movevars.h"
#include "pm_shared.h"
#include "pm_defs.h"
#include "event_api.h"
#include "pmtrace.h"
#include "screenfade.h"
#include "shake.h"
#include "hltv.h"
// Spectator Mode
extern "C"
{
9 years ago
float vecNewViewAngles[3];
int iHasNewViewAngles;
float vecNewViewOrigin[3];
int iHasNewViewOrigin;
int iIsSpectator;
9 years ago
}
#ifndef M_PI
#define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h
#endif
#ifndef M_PI_F
#define M_PI_F (float)M_PI
#endif
9 years ago
extern "C"
{
int CL_IsThirdPerson( void );
void CL_CameraOffset( float *ofs );
void DLLEXPORT V_CalcRefdef( struct ref_params_s *pparams );
9 years ago
void PM_ParticleLine( float *start, float *end, int pcolor, float life, float vert );
int PM_GetVisEntInfo( int ent );
int PM_GetPhysEntInfo( int ent );
void InterpolateAngles( float * start, float * end, float * output, float frac );
void NormalizeAngles( float * angles );
float Distance( const float * v1, const float * v2 );
float AngleBetweenVectors( const float * v1, const float * v2 );
9 years ago
9 years ago
float vJumpOrigin[3];
float vJumpAngles[3];
9 years ago
}
9 years ago
void V_DropPunchAngle( float frametime, float *ev_punchangle );
9 years ago
void VectorAngles( const float *forward, float *angles );
#include "r_studioint.h"
#include "com_model.h"
extern engine_studio_api_t IEngineStudio;
/*
The view is allowed to move slightly from it's true position for bobbing,
but if it exceeds 8 pixels linear distance (spherical, not box), the list of
entities sent from the server may not include everything in the pvs, especially
when crossing a water boudnary.
*/
extern cvar_t *cl_forwardspeed;
extern cvar_t *chase_active;
extern cvar_t *scr_ofsx, *scr_ofsy, *scr_ofsz;
extern cvar_t *cl_vsmoothing;
extern cvar_t *cl_viewbob;
extern Vector dead_viewangles;
9 years ago
#define CAM_MODE_RELAX 1
#define CAM_MODE_FOCUS 2
9 years ago
vec3_t v_origin, v_angles, v_cl_angles, v_sim_org, v_lastAngles;
float v_frametime, v_lastDistance;
float v_cameraRelaxAngle = 5.0f;
float v_cameraFocusAngle = 35.0f;
int v_cameraMode = CAM_MODE_FOCUS;
qboolean v_resetCamera = 1;
9 years ago
vec3_t g_ev_punchangle;
9 years ago
cvar_t *scr_ofsx;
cvar_t *scr_ofsy;
cvar_t *scr_ofsz;
cvar_t *v_centermove;
cvar_t *v_centerspeed;
cvar_t *cl_bobcycle;
cvar_t *cl_bob;
cvar_t *cl_bobup;
cvar_t *cl_waterdist;
cvar_t *cl_chasedist;
// These cvars are not registered (so users can't cheat), so set the ->value field directly
// Register these cvars in V_Init() if needed for easy tweaking
cvar_t v_iyaw_cycle = {"v_iyaw_cycle", "2", 0, 2};
cvar_t v_iroll_cycle = {"v_iroll_cycle", "0.5", 0, 0.5};
cvar_t v_ipitch_cycle = {"v_ipitch_cycle", "1", 0, 1};
cvar_t v_iyaw_level = {"v_iyaw_level", "0.3", 0, 0.3};
cvar_t v_iroll_level = {"v_iroll_level", "0.1", 0, 0.1};
cvar_t v_ipitch_level = {"v_ipitch_level", "0.3", 0, 0.3};
float v_idlescale; // used by TFC for concussion grenade effect
//=============================================================================
/*
void V_NormalizeAngles( float *angles )
{
int i;
9 years ago
9 years ago
// Normalize angles
9 years ago
for( i = 0; i < 3; i++ )
9 years ago
{
if( angles[i] > 180.0f )
9 years ago
{
angles[i] -= 360.0f;
9 years ago
}
else if( angles[i] < -180.0f )
9 years ago
{
angles[i] += 360.0f;
9 years ago
}
}
}
===================
V_InterpolateAngles
Interpolate Euler angles.
FIXME: Use Quaternions to avoid discontinuities
Frac is 0.0 to 1.0 ( i.e., should probably be clamped, but doesn't have to be )
===================
void V_InterpolateAngles( float *start, float *end, float *output, float frac )
{
int i;
float ang1, ang2;
float d;
9 years ago
9 years ago
V_NormalizeAngles( start );
V_NormalizeAngles( end );
9 years ago
for( i = 0 ; i < 3 ; i++ )
9 years ago
{
ang1 = start[i];
ang2 = end[i];
d = ang2 - ang1;
if( d > 180.0f )
9 years ago
{
d -= 360.0f;
9 years ago
}
else if( d < -180.0f )
9 years ago
{
d += 360.0f;
9 years ago
}
output[i] = ang1 + d * frac;
}
V_NormalizeAngles( output );
} */
// Quakeworld bob code, this fixes jitters in the mutliplayer since the clock (pparams->time) isn't quite linear
9 years ago
float V_CalcBob( struct ref_params_s *pparams )
9 years ago
{
9 years ago
static double bobtime;
static float bob;
float cycle;
static float lasttime;
9 years ago
vec3_t vel;
9 years ago
if( pparams->onground == -1 ||
9 years ago
pparams->time == lasttime )
{
// just use old value
return bob;
}
lasttime = pparams->time;
bobtime += pparams->frametime;
cycle = bobtime - (int)( bobtime / cl_bobcycle->value ) * cl_bobcycle->value;
cycle /= cl_bobcycle->value;
9 years ago
if( cycle < cl_bobup->value )
9 years ago
{
cycle = M_PI_F * cycle / cl_bobup->value;
9 years ago
}
else
{
cycle = M_PI_F + M_PI_F * ( cycle - cl_bobup->value )/( 1.0f - cl_bobup->value );
9 years ago
}
// bob is proportional to simulated velocity in the xy plane
// (don't count Z, or jumping messes it up)
VectorCopy( pparams->simvel, vel );
vel[2] = 0;
bob = sqrt( vel[0] * vel[0] + vel[1] * vel[1] ) * cl_bob->value;
bob = bob * 0.3f + bob * 0.7f * sin(cycle);
bob = Q_min( bob, 4.0f );
bob = Q_max( bob, -7.0f );
9 years ago
return bob;
}
/*
===============
V_CalcRoll
Used by view and sv_user
===============
*/
9 years ago
float V_CalcRoll( vec3_t angles, vec3_t velocity, float rollangle, float rollspeed )
9 years ago
{
9 years ago
float sign;
float side;
float value;
vec3_t forward, right, up;
AngleVectors( angles, forward, right, up );
side = DotProduct( velocity, right );
sign = side < 0.0f ? -1.0f : 1.0f;
9 years ago
side = fabs( side );
9 years ago
value = rollangle;
9 years ago
if( side < rollspeed )
9 years ago
{
side = side * value / rollspeed;
}
9 years ago
else
9 years ago
{
side = value;
}
return side * sign;
}
typedef struct pitchdrift_s
{
9 years ago
float pitchvel;
int nodrift;
float driftmove;
double laststop;
9 years ago
} pitchdrift_t;
static pitchdrift_t pd;
/*
===============
V_DriftPitch
Moves the client pitch angle towards idealpitch sent by the server.
If the user is adjusting pitch manually, either with lookup/lookdown,
mlook and mouse, or klook and keyboard, pitch drifting is constantly stopped.
===============
*/
/*
==============================================================================
VIEW RENDERING
==============================================================================
*/
/*
==================
V_CalcGunAngle
==================
*/
9 years ago
void V_CalcGunAngle( struct ref_params_s *pparams )
9 years ago
{
cl_entity_t *viewent;
9 years ago
9 years ago
viewent = gEngfuncs.GetViewModel();
9 years ago
if( !viewent )
9 years ago
return;
9 years ago
viewent->angles[YAW] = pparams->viewangles[YAW] + pparams->crosshairangle[YAW];
viewent->angles[PITCH] = -pparams->viewangles[PITCH] + pparams->crosshairangle[PITCH] * 0.25f;
9 years ago
viewent->angles[ROLL] -= v_idlescale * sin( pparams->time * v_iroll_cycle.value ) * v_iroll_level.value;
9 years ago
// don't apply all of the v_ipitch to prevent normally unseen parts of viewmodel from coming into view.
viewent->angles[PITCH] -= v_idlescale * sin( pparams->time * v_ipitch_cycle.value ) * ( v_ipitch_level.value * 0.5f );
9 years ago
viewent->angles[YAW] -= v_idlescale * sin( pparams->time * v_iyaw_cycle.value ) * v_iyaw_level.value;
9 years ago
VectorCopy( viewent->angles, viewent->curstate.angles );
VectorCopy( viewent->angles, viewent->latched.prevangles );
}
/*
==============
V_AddIdle
Idle swaying
==============
*/
9 years ago
void V_AddIdle( struct ref_params_s *pparams )
9 years ago
{
9 years ago
pparams->viewangles[ROLL] += v_idlescale * sin( pparams->time * v_iroll_cycle.value ) * v_iroll_level.value;
pparams->viewangles[PITCH] += v_idlescale * sin( pparams->time * v_ipitch_cycle.value ) * v_ipitch_level.value;
pparams->viewangles[YAW] += v_idlescale * sin( pparams->time * v_iyaw_cycle.value ) * v_iyaw_level.value;
9 years ago
}
/*
==============
V_CalcViewRoll
Roll is induced by movement and damage
==============
*/
9 years ago
void V_CalcViewRoll( struct ref_params_s *pparams )
9 years ago
{
9 years ago
float side;
9 years ago
cl_entity_t *viewentity;
9 years ago
9 years ago
viewentity = gEngfuncs.GetEntityByIndex( pparams->viewentity );
9 years ago
if( !viewentity )
9 years ago
return;
9 years ago
side = V_CalcRoll( viewentity->angles, pparams->simvel, pparams->movevars->rollangle, pparams->movevars->rollspeed );
9 years ago
pparams->viewangles[ROLL] += side;
9 years ago
if( pparams->health <= 0 && ( pparams->viewheight[2] != 0 ) )
9 years ago
{
// only roll the view if the player is dead and the viewheight[2] is nonzero
// this is so deadcam in multiplayer will work.
pparams->viewangles[ROLL] = 80; // dead view angle
return;
}
}
/*
==================
V_CalcIntermissionRefdef
==================
*/
9 years ago
void V_CalcIntermissionRefdef( struct ref_params_s *pparams )
9 years ago
{
cl_entity_t /**ent,*/ *view;
9 years ago
float old;
9 years ago
// ent is the player model ( visible when out of body )
//ent = gEngfuncs.GetLocalPlayer();
9 years ago
9 years ago
// view is the weapon model (only visible from inside body )
view = gEngfuncs.GetViewModel();
9 years ago
VectorCopy( pparams->simorg, pparams->vieworg );
VectorCopy( pparams->cl_viewangles, pparams->viewangles );
9 years ago
view->model = NULL;
// allways idle in intermission
old = v_idlescale;
v_idlescale = 1;
9 years ago
V_AddIdle( pparams );
9 years ago
9 years ago
if( gEngfuncs.IsSpectateOnly() )
9 years ago
{
// in HLTV we must go to 'intermission' position by ourself
VectorCopy( gHUD.m_Spectator.m_cameraOrigin, pparams->vieworg );
VectorCopy( gHUD.m_Spectator.m_cameraAngles, pparams->viewangles );
}
v_idlescale = old;
v_cl_angles = pparams->cl_viewangles;
v_origin = pparams->vieworg;
v_angles = pparams->viewangles;
}
#define ORIGIN_BACKUP 64
#define ORIGIN_MASK ( ORIGIN_BACKUP - 1 )
typedef struct
{
9 years ago
float Origins[ORIGIN_BACKUP][3];
float OriginTime[ORIGIN_BACKUP];
9 years ago
9 years ago
float Angles[ORIGIN_BACKUP][3];
float AngleTime[ORIGIN_BACKUP];
9 years ago
int CurrentOrigin;
int CurrentAngle;
} viewinterp_t;
/*
==================
V_CalcRefdef
==================
*/
9 years ago
void V_CalcNormalRefdef( struct ref_params_s *pparams )
9 years ago
{
9 years ago
cl_entity_t *ent, *view;
int i;
vec3_t angles;
float bob, waterOffset;
static viewinterp_t ViewInterp;
9 years ago
static float oldz = 0;
static float lasttime;
vec3_t camAngles, camForward, camRight, camUp;
cl_entity_t *pwater;
9 years ago
if( gEngfuncs.IsSpectateOnly() )
9 years ago
{
ent = gEngfuncs.GetEntityByIndex( g_iUser2 );
}
else
{
// ent is the player model ( visible when out of body )
ent = gEngfuncs.GetLocalPlayer();
}
9 years ago
// view is the weapon model (only visible from inside body)
9 years ago
view = gEngfuncs.GetViewModel();
// transform the view offset by the model's matrix to get the offset from
// model origin for the view
9 years ago
bob = V_CalcBob( pparams );
9 years ago
// refresh position
9 years ago
VectorCopy( pparams->simorg, pparams->vieworg );
pparams->vieworg[2] += bob ;
9 years ago
VectorAdd( pparams->vieworg, pparams->viewheight, pparams->vieworg );
if( pparams->health <= 0 )
{
VectorCopy( dead_viewangles, pparams->viewangles );
}
else
{
VectorCopy( pparams->cl_viewangles, pparams->viewangles );
}
9 years ago
gEngfuncs.V_CalcShake();
gEngfuncs.V_ApplyShake( pparams->vieworg, pparams->viewangles, 1.0f );
9 years ago
// never let view origin sit exactly on a node line, because a water plane can
// dissapear when viewed with the eye exactly on it.
// FIXME, we send origin at 1/128 now, change this?
// the server protocol only specifies to 1/16 pixel, so add 1/32 in each axis
pparams->vieworg[0] += 1.0f / 32.0f;
pparams->vieworg[1] += 1.0f / 32.0f;
pparams->vieworg[2] += 1.0f / 32.0f;
9 years ago
// Check for problems around water, move the viewer artificially if necessary
// -- this prevents drawing errors in GL due to waves
waterOffset = 0;
9 years ago
if( pparams->waterlevel >= 2 )
9 years ago
{
9 years ago
int contents, waterDist, waterEntity;
vec3_t point;
9 years ago
waterDist = cl_waterdist->value;
9 years ago
if( pparams->hardware )
9 years ago
{
waterEntity = gEngfuncs.PM_WaterEntity( pparams->simorg );
9 years ago
if( waterEntity >= 0 && waterEntity < pparams->max_entities )
9 years ago
{
pwater = gEngfuncs.GetEntityByIndex( waterEntity );
9 years ago
if( pwater && ( pwater->model != NULL ) )
9 years ago
{
waterDist += ( pwater->curstate.scale * 16.0f ); // Add in wave height
9 years ago
}
}
}
else
{
// waterEntity = 0; // Don't need this in software
9 years ago
}
9 years ago
9 years ago
VectorCopy( pparams->vieworg, point );
// Eyes are above water, make sure we're above the waves
9 years ago
if( pparams->waterlevel == 2 )
9 years ago
{
point[2] -= waterDist;
9 years ago
for( i = 0; i < waterDist; i++ )
9 years ago
{
contents = gEngfuncs.PM_PointContents( point, NULL );
9 years ago
if( contents > CONTENTS_WATER )
9 years ago
break;
point[2] += 1;
}
9 years ago
waterOffset = ( point[2] + waterDist ) - pparams->vieworg[2];
9 years ago
}
else
{
// eyes are under water. Make sure we're far enough under
point[2] += waterDist;
9 years ago
for( i = 0; i < waterDist; i++ )
9 years ago
{
contents = gEngfuncs.PM_PointContents( point, NULL );
9 years ago
if( contents <= CONTENTS_WATER )
9 years ago
break;
point[2] -= 1;
}
9 years ago
waterOffset = ( point[2] - waterDist ) - pparams->vieworg[2];
9 years ago
}
}
pparams->vieworg[2] += waterOffset;
9 years ago
V_CalcViewRoll( pparams );
V_AddIdle( pparams );
9 years ago
// offsets
if( pparams->health <= 0 )
{
VectorCopy( dead_viewangles, angles );
}
else
{
VectorCopy( pparams->cl_viewangles, angles );
}
9 years ago
9 years ago
AngleVectors( angles, pparams->forward, pparams->right, pparams->up );
9 years ago
// don't allow cheats in multiplayer
9 years ago
if( pparams->maxclients <= 1 )
9 years ago
{
9 years ago
for( i = 0; i < 3; i++ )
9 years ago
{
pparams->vieworg[i] += scr_ofsx->value*pparams->forward[i] + scr_ofsy->value*pparams->right[i] + scr_ofsz->value*pparams->up[i];
}
}
9 years ago
9 years ago
// Treating cam_ofs[2] as the distance
if( CL_IsThirdPerson() )
{
vec3_t ofs;
ofs[0] = ofs[1] = ofs[2] = 0.0f;
9 years ago
CL_CameraOffset( (float *)&ofs );
VectorCopy( ofs, camAngles );
9 years ago
camAngles[ROLL] = 0;
9 years ago
AngleVectors( camAngles, camForward, camRight, camUp );
9 years ago
for( i = 0; i < 3; i++ )
9 years ago
{
9 years ago
pparams->vieworg[i] += -ofs[2] * camForward[i];
9 years ago
}
}
9 years ago
9 years ago
// Give gun our viewangles
if( pparams->health <= 0 )
{
VectorCopy( dead_viewangles, view->angles );
}
else
{
VectorCopy( pparams->cl_viewangles, view->angles );
}
9 years ago
// set up gun position
9 years ago
V_CalcGunAngle( pparams );
9 years ago
// Use predicted origin as view origin.
9 years ago
VectorCopy( pparams->simorg, view->origin );
view->origin[2] += waterOffset;
9 years ago
VectorAdd( view->origin, pparams->viewheight, view->origin );
// Let the viewmodel shake at about 10% of the amplitude
gEngfuncs.V_ApplyShake( view->origin, view->angles, 0.9f );
9 years ago
9 years ago
for( i = 0; i < 3; i++ )
9 years ago
{
view->origin[i] += bob * 0.4f * pparams->forward[i];
9 years ago
}
view->origin[2] += bob;
// throw in a little tilt.
view->angles[YAW] -= bob * 0.5f;
view->angles[ROLL] -= bob * 1.0f;
view->angles[PITCH] -= bob * 0.3f;
9 years ago
if( cl_viewbob && cl_viewbob->value )
VectorCopy( view->angles, view->curstate.angles );
9 years ago
// pushing the view origin down off of the same X/Z plane as the ent's origin will give the
// gun a very nice 'shifting' effect when the player looks up/down. If there is a problem
// with view model distortion, this may be a cause. (SJB).
view->origin[2] -= 1.0f;
9 years ago
// fudge position around to keep amount of weapon visible
// roughly equal with different FOV
if( pparams->viewsize == 110.0f )
9 years ago
{
view->origin[2] += 1.0f;
9 years ago
}
else if( pparams->viewsize == 100.0f )
9 years ago
{
view->origin[2] += 2.0f;
9 years ago
}
else if( pparams->viewsize == 90.0f )
9 years ago
{
view->origin[2] += 1.0f;
9 years ago
}
else if( pparams->viewsize == 80.0f )
9 years ago
{
view->origin[2] += 0.5f;
9 years ago
}
// Add in the punchangle, if any
9 years ago
VectorAdd( pparams->viewangles, pparams->punchangle, pparams->viewangles );
9 years ago
// Include client side punch, too
VectorAdd( pparams->viewangles, (float *)&g_ev_punchangle, pparams->viewangles );
9 years ago
V_DropPunchAngle( pparams->frametime, (float *)&g_ev_punchangle );
9 years ago
// smooth out stair step ups
#if 1
if( !pparams->smoothing && pparams->onground && pparams->simorg[2] - oldz > 0.0f )
9 years ago
{
float steptime;
9 years ago
9 years ago
steptime = pparams->time - lasttime;
9 years ago
if( steptime < 0 )
//FIXME I_Error( "steptime < 0" );
9 years ago
steptime = 0;
oldz += steptime * 150.0f;
9 years ago
if( oldz > pparams->simorg[2] )
9 years ago
oldz = pparams->simorg[2];
if( pparams->simorg[2] - oldz > 18.0f )
oldz = pparams->simorg[2]- 18.0f;
9 years ago
pparams->vieworg[2] += oldz - pparams->simorg[2];
view->origin[2] += oldz - pparams->simorg[2];
}
else
{
oldz = pparams->simorg[2];
}
#endif
{
static float lastorg[3];
vec3_t delta;
VectorSubtract( pparams->simorg, lastorg, delta );
if( Length( delta ) != 0.0f )
9 years ago
{
9 years ago
VectorCopy( pparams->simorg, ViewInterp.Origins[ViewInterp.CurrentOrigin & ORIGIN_MASK] );
ViewInterp.OriginTime[ViewInterp.CurrentOrigin & ORIGIN_MASK] = pparams->time;
9 years ago
ViewInterp.CurrentOrigin++;
VectorCopy( pparams->simorg, lastorg );
}
}
// Smooth out whole view in multiplayer when on trains, lifts
9 years ago
if( cl_vsmoothing && cl_vsmoothing->value &&
9 years ago
( pparams->smoothing && ( pparams->maxclients > 1 ) ) )
{
int foundidx;
float t;
if( cl_vsmoothing->value < 0.0f )
9 years ago
{
gEngfuncs.Cvar_SetValue( "cl_vsmoothing", 0.0f );
9 years ago
}
t = pparams->time - cl_vsmoothing->value;
9 years ago
for( i = 1; i < ORIGIN_MASK; i++ )
9 years ago
{
foundidx = ViewInterp.CurrentOrigin - 1 - i;
9 years ago
if( ViewInterp.OriginTime[foundidx & ORIGIN_MASK] <= t )
9 years ago
break;
}
if( i < ORIGIN_MASK && ViewInterp.OriginTime[foundidx & ORIGIN_MASK] != 0.0f )
9 years ago
{
// Interpolate
vec3_t delta;
double frac;
double dt;
vec3_t neworg;
9 years ago
dt = ViewInterp.OriginTime[( foundidx + 1 ) & ORIGIN_MASK] - ViewInterp.OriginTime[foundidx & ORIGIN_MASK];
if( dt > 0.0 )
9 years ago
{
9 years ago
frac = ( t - ViewInterp.OriginTime[foundidx & ORIGIN_MASK] ) / dt;
frac = Q_min( 1.0, frac );
9 years ago
VectorSubtract( ViewInterp.Origins[( foundidx + 1 ) & ORIGIN_MASK], ViewInterp.Origins[foundidx & ORIGIN_MASK], delta );
VectorMA( ViewInterp.Origins[foundidx & ORIGIN_MASK], frac, delta, neworg );
9 years ago
// Dont interpolate large changes
if( Length( delta ) < 64.0f )
9 years ago
{
VectorSubtract( neworg, pparams->simorg, delta );
VectorAdd( pparams->simorg, delta, pparams->simorg );
VectorAdd( pparams->vieworg, delta, pparams->vieworg );
VectorAdd( view->origin, delta, view->origin );
}
}
}
}
// Store off v_angles before munging for third person
v_angles = pparams->viewangles;
v_lastAngles = pparams->viewangles;
9 years ago
//v_cl_angles = pparams->cl_viewangles; // keep old user mouse angles !
if( CL_IsThirdPerson() )
9 years ago
{
9 years ago
VectorCopy( camAngles, pparams->viewangles );
float pitch = camAngles[0];
9 years ago
// Normalize angles
if( pitch > 180.0f )
pitch -= 360.0f;
else if( pitch < -180.0f )
pitch += 360.0f;
9 years ago
// Player pitch is inverted
pitch /= -3.0f;
9 years ago
// Slam local player's pitch value
9 years ago
ent->angles[0] = pitch;
ent->curstate.angles[0] = pitch;
ent->prevstate.angles[0] = pitch;
ent->latched.prevangles[0] = pitch;
9 years ago
}
// override all previous settings if the viewent isn't the client
9 years ago
if( pparams->viewentity > pparams->maxclients )
9 years ago
{
cl_entity_t *viewentity;
viewentity = gEngfuncs.GetEntityByIndex( pparams->viewentity );
9 years ago
if( viewentity )
9 years ago
{
VectorCopy( viewentity->origin, pparams->vieworg );
VectorCopy( viewentity->angles, pparams->viewangles );
// Store off overridden viewangles
v_angles = pparams->viewangles;
}
}
lasttime = pparams->time;
v_origin = pparams->vieworg;
}
void V_SmoothInterpolateAngles( float * startAngle, float * endAngle, float * finalAngle, float degreesPerSec )
{
9 years ago
float absd, frac, d, threshhold;
9 years ago
NormalizeAngles( startAngle );
NormalizeAngles( endAngle );
9 years ago
for( int i = 0; i < 3; i++ )
9 years ago
{
d = endAngle[i] - startAngle[i];
9 years ago
if( d > 180.0f )
9 years ago
{
d -= 360.0f;
}
9 years ago
else if( d < -180.0f )
{
9 years ago
d += 360.0f;
}
9 years ago
absd = fabs( d );
9 years ago
9 years ago
if( absd > 0.01f )
9 years ago
{
frac = degreesPerSec * v_frametime;
threshhold= degreesPerSec / 4.0f;
9 years ago
9 years ago
if( absd < threshhold )
9 years ago
{
float h = absd / threshhold;
h *= h;
9 years ago
frac *= h; // slow down last degrees
9 years ago
}
9 years ago
if( frac > absd )
9 years ago
{
finalAngle[i] = endAngle[i];
}
else
{
if( d > 0.0f )
9 years ago
finalAngle[i] = startAngle[i] + frac;
else
finalAngle[i] = startAngle[i] - frac;
}
}
else
{
finalAngle[i] = endAngle[i];
}
}
NormalizeAngles( finalAngle );
}
// Get the origin of the Observer based around the target's position and angles
void V_GetChaseOrigin( float * angles, float * origin, float distance, float * returnvec )
{
9 years ago
vec3_t vecEnd;
vec3_t forward;
vec3_t vecStart;
pmtrace_t *trace;
9 years ago
int maxLoops = 8;
int ignoreent = -1; // first, ignore no entity
9 years ago
cl_entity_t *ent = NULL;
9 years ago
// Trace back from the target using the player's view angles
9 years ago
AngleVectors( angles, forward, NULL, NULL );
VectorScale( forward, -1, forward );
9 years ago
VectorCopy( origin, vecStart );
9 years ago
VectorMA( vecStart, distance , forward, vecEnd );
9 years ago
9 years ago
while( maxLoops > 0 )
9 years ago
{
trace = gEngfuncs.PM_TraceLine( vecStart, vecEnd, PM_TRACELINE_PHYSENTSONLY, 2, ignoreent );
// WARNING! trace->ent is is the number in physent list not the normal entity number
9 years ago
if( trace->ent <= 0)
9 years ago
break; // we hit the world or nothing, stop trace
ent = gEngfuncs.GetEntityByIndex( PM_GetPhysEntInfo( trace->ent ) );
9 years ago
if( ent == NULL )
9 years ago
break;
// hit non-player solid BSP , stop here
9 years ago
if( ent->curstate.solid == SOLID_BSP && !ent->player )
9 years ago
break;
// if close enought to end pos, stop, otherwise continue trace
9 years ago
if( Distance( trace->endpos, vecEnd ) < 1.0f )
9 years ago
{
break;
}
else
{
ignoreent = trace->ent; // ignore last hit entity
9 years ago
VectorCopy( trace->endpos, vecStart );
9 years ago
}
maxLoops--;
9 years ago
}
9 years ago
9 years ago
/* if( ent )
9 years ago
{
9 years ago
gEngfuncs.Con_Printf( "Trace loops %i , entity %i, model %s, solid %i\n",(8-maxLoops),ent->curstate.number, ent->model->name , ent->curstate.solid );
9 years ago
} */
VectorMA( trace->endpos, 4, trace->plane.normal, returnvec );
9 years ago
v_lastDistance = Distance( trace->endpos, origin ); // real distance without offset
9 years ago
}
9 years ago
/*void V_GetDeathCam( cl_entity_t * ent1, cl_entity_t * ent2, float * angle, float * origin )
9 years ago
{
9 years ago
float newAngle[3]; float newOrigin[3];
9 years ago
float distance = 168.0f;
9 years ago
v_lastDistance += v_frametime * 96.0f; // move unit per seconds back
9 years ago
9 years ago
if( v_resetCamera )
9 years ago
v_lastDistance = 64.0f;
9 years ago
if( distance > v_lastDistance )
9 years ago
distance = v_lastDistance;
9 years ago
VectorCopy( ent1->origin, newOrigin );
9 years ago
9 years ago
if( ent1->player )
newOrigin[2] += 17.0f; // head level of living player
9 years ago
// get new angle towards second target
9 years ago
if( ent2 )
9 years ago
{
VectorSubtract( ent2->origin, ent1->origin, newAngle );
VectorAngles( newAngle, newAngle );
newAngle[0] = -newAngle[0];
}
else
{
// if no second target is given, look down to dead player
newAngle[0] = 90.0f;
newAngle[1] = 0.0f;
newAngle[2] = 0.0f;
9 years ago
}
// and smooth view
V_SmoothInterpolateAngles( v_lastAngles, newAngle, angle, 120.0f );
9 years ago
9 years ago
V_GetChaseOrigin( angle, newOrigin, distance, origin );
9 years ago
VectorCopy( angle, v_lastAngles );
9 years ago
}*/
9 years ago
void V_GetSingleTargetCam( cl_entity_t * ent1, float * angle, float * origin )
9 years ago
{
9 years ago
float newAngle[3]; float newOrigin[3];
int flags = gHUD.m_Spectator.m_iObserverFlags;
9 years ago
// see is target is a dead player
9 years ago
qboolean deadPlayer = ent1->player && ( ent1->curstate.solid == SOLID_NOT );
float dfactor = ( flags & DRC_FLAG_DRAMATIC ) ? -1.0f : 1.0f;
9 years ago
float distance = 112.0f + ( 16.0f * dfactor ); // get close if dramatic;
9 years ago
9 years ago
// go away in final scenes or if player just died
9 years ago
if( flags & DRC_FLAG_FINAL )
distance *= 2.0f;
else if( deadPlayer )
distance *= 1.5f;
9 years ago
// let v_lastDistance float smoothly away
9 years ago
v_lastDistance += v_frametime * 32.0f; // move unit per seconds back
9 years ago
9 years ago
if( distance > v_lastDistance )
9 years ago
distance = v_lastDistance;
9 years ago
VectorCopy( ent1->origin, newOrigin );
if( ent1->player )
9 years ago
{
9 years ago
if( deadPlayer )
newOrigin[2] += 2.0f; //laying on ground
9 years ago
else
newOrigin[2] += 17.0f; // head level of living player
9 years ago
}
else
newOrigin[2]+= 8.0f; // object, tricky, must be above bomb in CS
9 years ago
// we have no second target, choose view direction based on
// show front of primary target
9 years ago
VectorCopy( ent1->angles, newAngle );
9 years ago
// show dead players from front, normal players back
9 years ago
if( flags & DRC_FLAG_FACEPLAYER )
newAngle[1] += 180.0f;
9 years ago
9 years ago
newAngle[0] += 12.5f * dfactor; // lower angle if dramatic
9 years ago
// if final scene (bomb), show from real high pos
9 years ago
if( flags & DRC_FLAG_FINAL )
9 years ago
newAngle[0] = 22.5f;
// choose side of object/player
9 years ago
if( flags & DRC_FLAG_SIDE )
newAngle[1] += 22.5f;
9 years ago
else
9 years ago
newAngle[1] -= 22.5f;
9 years ago
V_SmoothInterpolateAngles( v_lastAngles, newAngle, angle, 120.0f );
// HACK, if player is dead don't clip against his dead body, can't check this
V_GetChaseOrigin( angle, newOrigin, distance, origin );
}
9 years ago
float MaxAngleBetweenAngles( float *a1, float *a2 )
9 years ago
{
float d, maxd = 0.0f;
NormalizeAngles( a1 );
NormalizeAngles( a2 );
9 years ago
for( int i = 0; i < 3; i++ )
9 years ago
{
d = a2[i] - a1[i];
if( d > 180.0f )
9 years ago
{
d -= 360.0f;
9 years ago
}
else if( d < -180.0f )
9 years ago
{
d += 360.0f;
9 years ago
}
9 years ago
d = fabs( d );
9 years ago
9 years ago
if( d > maxd )
maxd = d;
9 years ago
}
return maxd;
}
9 years ago
void V_GetDoubleTargetsCam( cl_entity_t *ent1, cl_entity_t *ent2, float *angle, float *origin )
9 years ago
{
9 years ago
float newAngle[3], newOrigin[3], tempVec[3];
9 years ago
9 years ago
int flags = gHUD.m_Spectator.m_iObserverFlags;
9 years ago
9 years ago
float dfactor = ( flags & DRC_FLAG_DRAMATIC ) ? -1.0f : 1.0f;
9 years ago
float distance = 112.0f + ( 16.0f * dfactor ); // get close if dramatic;
9 years ago
9 years ago
// go away in final scenes or if player just died
9 years ago
if( flags & DRC_FLAG_FINAL )
distance *= 2.0f;
9 years ago
// let v_lastDistance float smoothly away
9 years ago
v_lastDistance += v_frametime * 32.0f; // move unit per seconds back
9 years ago
9 years ago
if( distance > v_lastDistance )
9 years ago
distance = v_lastDistance;
9 years ago
VectorCopy( ent1->origin, newOrigin );
9 years ago
9 years ago
if( ent1->player )
newOrigin[2] += 17.0f; // head level of living player
9 years ago
else
newOrigin[2] += 8.0f; // object, tricky, must be above bomb in CS
9 years ago
// get new angle towards second target
VectorSubtract( ent2->origin, ent1->origin, newAngle );
VectorAngles( newAngle, newAngle );
newAngle[0] = -newAngle[0];
// set angle diffrent in Dramtaic scenes
9 years ago
newAngle[0] += 12.5f * dfactor; // lower angle if dramatic
if( flags & DRC_FLAG_SIDE )
newAngle[1] += 22.5f;
9 years ago
else
9 years ago
newAngle[1] -= 22.5f;
9 years ago
float d = MaxAngleBetweenAngles( v_lastAngles, newAngle );
9 years ago
if( ( d < v_cameraFocusAngle) && ( v_cameraMode == CAM_MODE_RELAX ) )
9 years ago
{
// difference is to small and we are in relax camera mode, keep viewangles
9 years ago
VectorCopy( v_lastAngles, newAngle );
9 years ago
}
9 years ago
else if( ( d < v_cameraRelaxAngle ) && ( v_cameraMode == CAM_MODE_FOCUS ) )
9 years ago
{
// we catched up with our target, relax again
v_cameraMode = CAM_MODE_RELAX;
}
else
{
// target move too far away, focus camera again
v_cameraMode = CAM_MODE_FOCUS;
}
// and smooth view, if not a scene cut
9 years ago
if( v_resetCamera || ( v_cameraMode == CAM_MODE_RELAX ) )
9 years ago
{
VectorCopy( newAngle, angle );
}
else
{
V_SmoothInterpolateAngles( v_lastAngles, newAngle, angle, 180.0f );
}
V_GetChaseOrigin( newAngle, newOrigin, distance, origin );
// move position up, if very close at target
9 years ago
if( v_lastDistance < 64.0f )
origin[2] += 16.0f * ( 1.0f - ( v_lastDistance / 64.0f ) );
9 years ago
// calculate angle to second target
VectorSubtract( ent2->origin, origin, tempVec );
VectorAngles( tempVec, tempVec );
tempVec[0] = -tempVec[0];
/* take middle between two viewangles
9 years ago
InterpolateAngles( newAngle, tempVec, newAngle, 0.5f ); */
9 years ago
}
9 years ago
void V_GetDirectedChasePosition(cl_entity_t *ent1, cl_entity_t *ent2,float *angle, float *origin)
9 years ago
{
9 years ago
if( v_resetCamera )
9 years ago
{
v_lastDistance = 4096.0f;
// v_cameraMode = CAM_MODE_FOCUS;
}
9 years ago
if( ( ent2 == (cl_entity_t*)0xFFFFFFFF ) || ( ent1->player && ( ent1->curstate.solid == SOLID_NOT ) ) )
9 years ago
{
// we have no second target or player just died
9 years ago
V_GetSingleTargetCam( ent1, angle, origin );
9 years ago
}
9 years ago
else if( ent2 )
9 years ago
{
// keep both target in view
V_GetDoubleTargetsCam( ent1, ent2, angle, origin );
}
else
{
// second target disappeard somehow (dead)
// keep last good viewangle
float newOrigin[3];
9 years ago
int flags = gHUD.m_Spectator.m_iObserverFlags;
9 years ago
9 years ago
float dfactor = ( flags & DRC_FLAG_DRAMATIC ) ? -1.0f : 1.0f;
9 years ago
float distance = 112.0f + ( 16.0f * dfactor ); // get close if dramatic;
9 years ago
9 years ago
// go away in final scenes or if player just died
9 years ago
if( flags & DRC_FLAG_FINAL )
distance *= 2.0f;
9 years ago
// let v_lastDistance float smoothly away
v_lastDistance+= v_frametime * 32.0f; // move unit per seconds back
9 years ago
if( distance > v_lastDistance )
9 years ago
distance = v_lastDistance;
9 years ago
VectorCopy( ent1->origin, newOrigin );
if( ent1->player )
newOrigin[2] += 17.0f; // head level of living player
9 years ago
else
newOrigin[2] += 8.0f; // object, tricky, must be above bomb in CS
9 years ago
V_GetChaseOrigin( angle, newOrigin, distance, origin );
}
9 years ago
VectorCopy( angle, v_lastAngles );
9 years ago
}
9 years ago
void V_GetChasePos( int target, float *cl_angles, float *origin, float *angles )
9 years ago
{
9 years ago
cl_entity_t *ent = NULL;
if( target )
9 years ago
{
ent = gEngfuncs.GetEntityByIndex( target );
9 years ago
}
9 years ago
9 years ago
if( !ent )
9 years ago
{
// just copy a save in-map position
9 years ago
VectorCopy( vJumpAngles, angles );
VectorCopy( vJumpOrigin, origin );
9 years ago
return;
}
9 years ago
if( gHUD.m_Spectator.m_autoDirector->value )
9 years ago
{
9 years ago
if( g_iUser3 )
9 years ago
V_GetDirectedChasePosition( ent, gEngfuncs.GetEntityByIndex( g_iUser3 ),
angles, origin );
else
9 years ago
V_GetDirectedChasePosition( ent, (cl_entity_t*)0xFFFFFFFF,
9 years ago
angles, origin );
}
else
{
9 years ago
if( cl_angles == NULL ) // no mouse angles given, use entity angles ( locked mode )
9 years ago
{
9 years ago
VectorCopy( ent->angles, angles);
angles[0] *= -1.0f;
9 years ago
}
else
9 years ago
VectorCopy( cl_angles, angles );
9 years ago
9 years ago
VectorCopy( ent->origin, origin );
9 years ago
origin[2] += 28.0f; // DEFAULT_VIEWHEIGHT - some offset
9 years ago
V_GetChaseOrigin( angles, origin, cl_chasedist->value, origin );
}
v_resetCamera = false;
}
void V_ResetChaseCam()
{
v_resetCamera = true;
}
9 years ago
void V_GetInEyePos( int target, float *origin, float *angles )
9 years ago
{
9 years ago
if( !target )
9 years ago
{
// just copy a save in-map position
VectorCopy ( vJumpAngles, angles );
VectorCopy ( vJumpOrigin, origin );
return;
};
9 years ago
cl_entity_t *ent = gEngfuncs.GetEntityByIndex( target );
9 years ago
9 years ago
if( !ent )
9 years ago
return;
9 years ago
VectorCopy( ent->origin, origin );
VectorCopy( ent->angles, angles );
9 years ago
9 years ago
angles[PITCH] *= -3.0f; // see CL_ProcessEntityUpdate()
9 years ago
9 years ago
if( ent->curstate.solid == SOLID_NOT )
9 years ago
{
angles[ROLL] = 80.0f; // dead view angle
origin[2] += -8.0f; // PM_DEAD_VIEWHEIGHT
9 years ago
}
9 years ago
else if( ent->curstate.usehull == 1 )
origin[2] += 12.0f; // VEC_DUCK_VIEW;
9 years ago
else
// exacty eye position can't be caluculated since it depends on
// client values like cl_bobcycle, this offset matches the default values
origin[2] += 28.0f; // DEFAULT_VIEWHEIGHT
9 years ago
}
9 years ago
void V_GetMapFreePosition( float *cl_angles, float *origin, float *angles )
9 years ago
{
vec3_t forward;
vec3_t zScaledTarget;
9 years ago
VectorCopy( cl_angles, angles );
9 years ago
// modify angles since we don't wanna see map's bottom
9 years ago
angles[0] = 51.25f + 38.75f * ( angles[0] / 90.0f );
9 years ago
zScaledTarget[0] = gHUD.m_Spectator.m_mapOrigin[0];
zScaledTarget[1] = gHUD.m_Spectator.m_mapOrigin[1];
9 years ago
zScaledTarget[2] = gHUD.m_Spectator.m_mapOrigin[2] * ( ( 90.0f - angles[0] ) / 90.0f );
9 years ago
9 years ago
AngleVectors( angles, forward, NULL, NULL );
9 years ago
9 years ago
VectorNormalize( forward );
9 years ago
9 years ago
VectorMA( zScaledTarget, -( 4096.0f / gHUD.m_Spectator.m_mapZoom ), forward, origin );
9 years ago
}
9 years ago
void V_GetMapChasePosition( int target, float *cl_angles, float *origin, float *angles )
9 years ago
{
vec3_t forward;
9 years ago
if( target )
9 years ago
{
9 years ago
cl_entity_t *ent = gEngfuncs.GetEntityByIndex( target );
9 years ago
9 years ago
if( gHUD.m_Spectator.m_autoDirector->value )
9 years ago
{
// this is done to get the angles made by director mode
9 years ago
V_GetChasePos( target, cl_angles, origin, angles );
VectorCopy( ent->origin, origin );
9 years ago
// keep fix chase angle horizontal
angles[0] = 45.0f;
}
else
{
9 years ago
VectorCopy( cl_angles, angles );
VectorCopy( ent->origin, origin );
9 years ago
// modify angles since we don't wanna see map's bottom
9 years ago
angles[0] = 51.25f + 38.75f * ( angles[0] / 90.0f );
9 years ago
}
}
else
{
// keep out roaming position, but modify angles
9 years ago
VectorCopy( cl_angles, angles );
angles[0] = 51.25f + 38.75f * ( angles[0] / 90.0f );
9 years ago
}
9 years ago
origin[2] *= ( ( 90.0f - angles[0] ) / 90.0f );
9 years ago
angles[2] = 0.0f; // don't roll angle (if chased player is dead)
9 years ago
AngleVectors( angles, forward, NULL, NULL );
9 years ago
9 years ago
VectorNormalize( forward );
9 years ago
VectorMA( origin, -1536.0f, forward, origin );
9 years ago
}
9 years ago
int V_FindViewModelByWeaponModel( int weaponindex )
9 years ago
{
static const char *modelmap[][2] =
9 years ago
{
{ "models/p_crossbow.mdl", "models/v_crossbow.mdl" },
{ "models/p_crowbar.mdl", "models/v_crowbar.mdl" },
{ "models/p_egon.mdl", "models/v_egon.mdl" },
{ "models/p_gauss.mdl", "models/v_gauss.mdl" },
{ "models/p_9mmhandgun.mdl", "models/v_9mmhandgun.mdl" },
{ "models/p_grenade.mdl", "models/v_grenade.mdl" },
{ "models/p_hgun.mdl", "models/v_hgun.mdl" },
{ "models/p_9mmAR.mdl", "models/v_9mmAR.mdl" },
{ "models/p_357.mdl", "models/v_357.mdl" },
{ "models/p_rpg.mdl", "models/v_rpg.mdl" },
{ "models/p_shotgun.mdl", "models/v_shotgun.mdl" },
{ "models/p_squeak.mdl", "models/v_squeak.mdl" },
{ "models/p_tripmine.mdl", "models/v_tripmine.mdl" },
{ "models/p_satchel_radio.mdl", "models/v_satchel_radio.mdl" },
{ "models/p_satchel.mdl", "models/v_satchel.mdl" },
{ NULL, NULL }
};
9 years ago
struct model_s *weaponModel = IEngineStudio.GetModelByIndex( weaponindex );
9 years ago
9 years ago
if( weaponModel )
9 years ago
{
int len = strlen( weaponModel->name );
int i = 0;
9 years ago
while( modelmap[i][0] != NULL )
9 years ago
{
9 years ago
if( !strnicmp( weaponModel->name, modelmap[i][0], len ) )
9 years ago
{
return gEngfuncs.pEventAPI->EV_FindModelIndex( modelmap[i][1] );
}
i++;
}
return 0;
}
else
return 0;
}
/*
==================
V_CalcSpectatorRefdef
==================
*/
9 years ago
void V_CalcSpectatorRefdef( struct ref_params_s * pparams )
9 years ago
{
9 years ago
static vec3_t velocity( 0.0f, 0.0f, 0.0f );
9 years ago
static int lastWeaponModelIndex = 0;
static int lastViewModelIndex = 0;
9 years ago
cl_entity_t *ent = gEngfuncs.GetEntityByIndex( g_iUser2 );
9 years ago
pparams->onlyClientDraw = false;
// refresh position
9 years ago
VectorCopy( pparams->simorg, v_sim_org );
9 years ago
// get old values
9 years ago
VectorCopy( pparams->cl_viewangles, v_cl_angles );
VectorCopy( pparams->viewangles, v_angles );
VectorCopy( pparams->vieworg, v_origin );
9 years ago
9 years ago
if( ( g_iUser1 == OBS_IN_EYE || gHUD.m_Spectator.m_pip->value == INSET_IN_EYE ) && ent )
9 years ago
{
// calculate player velocity
float timeDiff = ent->curstate.msg_time - ent->prevstate.msg_time;
9 years ago
if( timeDiff > 0 )
9 years ago
{
vec3_t distance;
9 years ago
VectorSubtract( ent->prevstate.origin, ent->curstate.origin, distance );
VectorScale( distance, 1 / timeDiff, distance );
velocity[0] = velocity[0] * 0.9f + distance[0] * 0.1f;
velocity[1] = velocity[1] * 0.9f + distance[1] * 0.1f;
velocity[2] = velocity[2] * 0.9f + distance[2] * 0.1f;
VectorCopy( velocity, pparams->simvel );
9 years ago
}
// predict missing client data and set weapon model ( in HLTV mode or inset in eye mode )
if( 1 ) //gEngfuncs.IsSpectateOnly() )
9 years ago
{
V_GetInEyePos( g_iUser2, pparams->simorg, pparams->cl_viewangles );
pparams->health = 1;
9 years ago
cl_entity_t *gunModel = gEngfuncs.GetViewModel();
9 years ago
9 years ago
if( lastWeaponModelIndex != ent->curstate.weaponmodel )
9 years ago
{
// weapon model changed
lastWeaponModelIndex = ent->curstate.weaponmodel;
lastViewModelIndex = V_FindViewModelByWeaponModel( lastWeaponModelIndex );
9 years ago
if( lastViewModelIndex )
9 years ago
{
9 years ago
gEngfuncs.pfnWeaponAnim( 0, 0 ); // reset weapon animation
9 years ago
}
else
{
// model not found
gunModel->model = NULL; // disable weapon model
lastWeaponModelIndex = lastViewModelIndex = 0;
}
}
9 years ago
if( lastViewModelIndex )
9 years ago
{
gunModel->model = IEngineStudio.GetModelByIndex( lastViewModelIndex );
gunModel->curstate.modelindex = lastViewModelIndex;
gunModel->curstate.frame = 0;
gunModel->curstate.colormap = 0;
gunModel->index = g_iUser2;
}
else
{
gunModel->model = NULL; // disable weaopn model
}
}
else
{
// only get viewangles from entity
9 years ago
VectorCopy( ent->angles, pparams->cl_viewangles );
pparams->cl_viewangles[PITCH] *= -3.0f; // see CL_ProcessEntityUpdate()
9 years ago
}
}
v_frametime = pparams->frametime;
9 years ago
if( pparams->nextView == 0 )
9 years ago
{
// first renderer cycle, full screen
9 years ago
switch( g_iUser1 )
9 years ago
{
9 years ago
case OBS_CHASE_LOCKED:
V_GetChasePos( g_iUser2, NULL, v_origin, v_angles );
break;
case OBS_CHASE_FREE:
V_GetChasePos( g_iUser2, v_cl_angles, v_origin, v_angles );
break;
case OBS_ROAMING:
VectorCopy( v_cl_angles, v_angles );
VectorCopy( v_sim_org, v_origin );
break;
case OBS_IN_EYE:
V_CalcNormalRefdef( pparams );
break;
case OBS_MAP_FREE:
pparams->onlyClientDraw = true;
V_GetMapFreePosition( v_cl_angles, v_origin, v_angles );
break;
case OBS_MAP_CHASE:
pparams->onlyClientDraw = true;
V_GetMapChasePosition( g_iUser2, v_cl_angles, v_origin, v_angles );
break;
9 years ago
}
9 years ago
if( gHUD.m_Spectator.m_pip->value )
9 years ago
pparams->nextView = 1; // force a second renderer view
gHUD.m_Spectator.m_iDrawCycle = 0;
}
else
{
// second renderer cycle, inset window
// set inset parameters
9 years ago
pparams->viewport[0] = XRES( gHUD.m_Spectator.m_OverviewData.insetWindowX ); // change viewport to inset window
pparams->viewport[1] = YRES( gHUD.m_Spectator.m_OverviewData.insetWindowY );
pparams->viewport[2] = XRES( gHUD.m_Spectator.m_OverviewData.insetWindowWidth );
pparams->viewport[3] = YRES( gHUD.m_Spectator.m_OverviewData.insetWindowHeight );
pparams->nextView = 0; // on further view
9 years ago
// override some settings in certain modes
9 years ago
switch( (int)gHUD.m_Spectator.m_pip->value )
9 years ago
{
9 years ago
case INSET_CHASE_FREE:
V_GetChasePos( g_iUser2, v_cl_angles, v_origin, v_angles );
break;
case INSET_IN_EYE:
V_CalcNormalRefdef( pparams );
break;
case INSET_MAP_FREE:
pparams->onlyClientDraw = true;
V_GetMapFreePosition( v_cl_angles, v_origin, v_angles );
break;
case INSET_MAP_CHASE:
pparams->onlyClientDraw = true;
if( g_iUser1 == OBS_ROAMING )
V_GetMapChasePosition( 0, v_cl_angles, v_origin, v_angles );
else
V_GetMapChasePosition( g_iUser2, v_cl_angles, v_origin, v_angles );
break;
9 years ago
}
gHUD.m_Spectator.m_iDrawCycle = 1;
}
// write back new values into pparams
9 years ago
VectorCopy( v_cl_angles, pparams->cl_viewangles );
VectorCopy( v_angles, pparams->viewangles )
VectorCopy( v_origin, pparams->vieworg );
9 years ago
}
void DLLEXPORT V_CalcRefdef( struct ref_params_s *pparams )
{
// intermission / finale rendering
9 years ago
if( pparams->intermission )
{
V_CalcIntermissionRefdef( pparams );
9 years ago
}
9 years ago
else if( pparams->spectator || g_iUser1 ) // g_iUser true if in spectator mode
9 years ago
{
9 years ago
V_CalcSpectatorRefdef( pparams );
9 years ago
}
9 years ago
else if( !pparams->paused )
9 years ago
{
9 years ago
V_CalcNormalRefdef( pparams );
9 years ago
}
/*
// Example of how to overlay the whole screen with red at 50 % alpha
#define SF_TEST
#if defined SF_TEST
{
screenfade_t sf;
gEngfuncs.pfnGetScreenFade( &sf );
sf.fader = 255;
sf.fadeg = 0;
sf.fadeb = 0;
sf.fadealpha = 128;
sf.fadeFlags = FFADE_STAYOUT | FFADE_OUT;
gEngfuncs.pfnSetScreenFade( &sf );
}
#endif
*/
}
/*
=============
V_DropPunchAngle
=============
*/
9 years ago
void V_DropPunchAngle( float frametime, float *ev_punchangle )
9 years ago
{
9 years ago
float len;
len = VectorNormalize( ev_punchangle );
len -= ( 10.0f + len * 0.5f ) * (float)frametime;
len = Q_max( len, 0.0f );
9 years ago
VectorScale( ev_punchangle, len, ev_punchangle );
9 years ago
}
/*
=============
V_PunchAxis
Client side punch effect
=============
*/
void V_PunchAxis( int axis, float punch )
{
g_ev_punchangle[axis] = punch;
9 years ago
}
/*
=============
V_Init
=============
*/
9 years ago
void V_Init( void )
9 years ago
{
9 years ago
scr_ofsx = gEngfuncs.pfnRegisterVariable( "scr_ofsx","0", 0 );
scr_ofsy = gEngfuncs.pfnRegisterVariable( "scr_ofsy","0", 0 );
scr_ofsz = gEngfuncs.pfnRegisterVariable( "scr_ofsz","0", 0 );
v_centermove = gEngfuncs.pfnRegisterVariable( "v_centermove", "0.15", 0 );
v_centerspeed = gEngfuncs.pfnRegisterVariable( "v_centerspeed","500", 0 );
cl_bobcycle = gEngfuncs.pfnRegisterVariable( "cl_bobcycle","0.8", 0 );// best default for my experimental gun wag (sjb)
cl_bob = gEngfuncs.pfnRegisterVariable( "cl_bob","0.01", 0 );// best default for my experimental gun wag (sjb)
cl_bobup = gEngfuncs.pfnRegisterVariable( "cl_bobup","0.5", 0 );
cl_waterdist = gEngfuncs.pfnRegisterVariable( "cl_waterdist","4", 0 );
cl_chasedist = gEngfuncs.pfnRegisterVariable( "cl_chasedist","112", 0 );
9 years ago
}
//#define TRACE_TEST
#if defined( TRACE_TEST )
extern float in_fov;
/*
====================
CalcFov
====================
*/
9 years ago
float CalcFov( float fov_x, float width, float height )
9 years ago
{
9 years ago
float a;
float x;
9 years ago
if( fov_x < 1.0f || fov_x > 179.0f )
fov_x = 90.0f; // error, set to 90
9 years ago
x = width / tan( fov_x / 360.0f * M_PI_F );
9 years ago
9 years ago
a = atan ( height / x );
9 years ago
a = a * 360.0f / M_PI_F;
9 years ago
return a;
}
int hitent = -1;
void V_Move( int mx, int my )
{
float fov;
float fx, fy;
float dx, dy;
float c_x, c_y;
float dX, dY;
vec3_t forward, up, right;
vec3_t newangles;
vec3_t farpoint;
pmtrace_t tr;
fov = CalcFov( in_fov, (float)ScreenWidth, (float)ScreenHeight );
c_x = (float)ScreenWidth / 2.0f;
c_y = (float)ScreenHeight / 2.0f;
9 years ago
dx = (float)mx - c_x;
dy = (float)my - c_y;
// Proportion we moved in each direction
fx = dx / c_x;
fy = dy / c_y;
dX = fx * in_fov / 2.0f;
dY = fy * fov / 2.0f;
9 years ago
newangles = v_angles;
9 years ago
newangles[YAW] -= dX;
newangles[PITCH] += dY;
9 years ago
// Now rotate v_forward around that point
9 years ago
AngleVectors( newangles, forward, right, up );
9 years ago
farpoint = v_origin + 8192 * forward;
// Trace
9 years ago
tr = *( gEngfuncs.PM_TraceLine( (float *)&v_origin, (float *)&farpoint, PM_TRACELINE_PHYSENTSONLY, 2 /*point sized hull*/, -1 ) );
9 years ago
if( tr.fraction != 1.0f && tr.ent != 0 )
9 years ago
{
hitent = PM_GetPhysEntInfo( tr.ent );
PM_ParticleLine( (float *)&v_origin, (float *)&tr.endpos, 5, 1.0f, 0.0f );
9 years ago
}
else
{
hitent = -1;
}
}
#endif