Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Third person
#1
This is the entire view.cpp since I made a few changes that will keep thirdperson off for those who don't want it on when they die:P.

Code:
// 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 "pmtrace.h"
#include "screenfade.h"
#include "shake.h"

// Spectator Mode
extern "C"
{
    float    vecNewViewAngles[3];
    int  iHasNewViewAngles;
    float    vecNewViewOrigin[3];
    int  iHasNewViewOrigin;
    int  iIsSpectator;
}

extern float g_flStartScaleTime;
extern int iMouseInUse;
void CAM_ToThirdPerson(void);
void CAM_ToFirstPerson(void);

#ifndef M_PI
#define M_PI  3.14159265358979323846    // matches value in gcc v2 math.h
#endif

extern "C"
{
    int CL_IsThirdPerson( void );
    void CL_CameraOffset( float *ofs );

    void DLLEXPORT V_CalcRefdef( struct ref_params_s *pparams );

    void PM_ParticleLine( float *start, float *end, int pcolor, float life, float vert);
    int PM_GetInfo( int ent );

}

void V_DropPunchAngle ( float frametime, float *ev_punchangle );
void VectorAngles( const float *forward, float *angles );

/*
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;

vec3_t v_origin, v_angles;

vec3_t ev_punchangle;

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;

// 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;
    // Normalize angles
&nbsp;&nbsp;&nbsp;&nbsp;for ( i = 0; i < 3; i++ )
&nbsp;&nbsp;&nbsp;&nbsp;{
 if ( angles[i] > 180.0 )
 {
 &nbsp;&nbsp;&nbsp;&nbsp;angles[i] -= 360.0;
 }
 else if ( angles[i] < -180.0 )
 {
 &nbsp;&nbsp;&nbsp;&nbsp;angles[i] += 360.0;
 }
&nbsp;&nbsp;&nbsp;&nbsp;}
}

/*
===================
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 )
{
&nbsp;&nbsp;&nbsp;&nbsp;int i;
&nbsp;&nbsp;&nbsp;&nbsp;float ang1, ang2;
&nbsp;&nbsp;&nbsp;&nbsp;float d;
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;V_NormalizeAngles( start );
&nbsp;&nbsp;&nbsp;&nbsp;V_NormalizeAngles( end );

&nbsp;&nbsp;&nbsp;&nbsp;for ( i = 0; i < 3; i++ )
&nbsp;&nbsp;&nbsp;&nbsp;{
 ang1 = start[i];
 ang2 = end[i];

 d = ang2 - ang1;
 if ( d > 180 )
 {
 &nbsp;&nbsp;&nbsp;&nbsp;d -= 360;
 }
 else if ( d < -180 )
 {&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp;&nbsp;&nbsp;&nbsp;d += 360;
 }

 output[i] = ang1 + d * frac;
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;V_NormalizeAngles( output );
}

// Quakeworld bob code, this fixes jitters in the mutliplayer since the clock (pparams->time) isn't quite linear
float V_CalcBob ( struct ref_params_s *pparams )
{
&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;&nbsp;&nbsp;&nbsp;double&nbsp;&nbsp;&nbsp;&nbsp;bobtime;
&nbsp;&nbsp;&nbsp;&nbsp;static float&nbsp;&nbsp;&nbsp;&nbsp;bob;
&nbsp;&nbsp;&nbsp;&nbsp;float&nbsp;&nbsp;&nbsp;&nbsp;cycle;
&nbsp;&nbsp;&nbsp;&nbsp;static float&nbsp;&nbsp;&nbsp;&nbsp;lasttime;
&nbsp;&nbsp;&nbsp;&nbsp;vec3_t&nbsp;&nbsp;&nbsp;&nbsp;vel;
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;if ( pparams->spectator || iIsSpectator )
 return 0;

&nbsp;&nbsp;&nbsp;&nbsp;if ( pparams->onground == -1 ||
  pparams->time == lasttime )
&nbsp;&nbsp;&nbsp;&nbsp;{
 // just use old value
 return bob;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;lasttime = pparams->time;

&nbsp;&nbsp;&nbsp;&nbsp;bobtime += pparams->frametime;
&nbsp;&nbsp;&nbsp;&nbsp;cycle = bobtime - (int)( bobtime / cl_bobcycle->value ) * cl_bobcycle->value;
&nbsp;&nbsp;&nbsp;&nbsp;cycle /= cl_bobcycle->value;
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;if ( cycle < cl_bobup->value )
&nbsp;&nbsp;&nbsp;&nbsp;{
 cycle = M_PI * cycle / cl_bobup->value;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;{
 cycle = M_PI + M_PI * ( cycle - cl_bobup->value )/( 1.0 - cl_bobup->value );
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;// bob is proportional to simulated velocity in the xy plane
&nbsp;&nbsp;&nbsp;&nbsp;// (don't count Z, or jumping messes it up)
&nbsp;&nbsp;&nbsp;&nbsp;VectorCopy( pparams->simvel, vel );
&nbsp;&nbsp;&nbsp;&nbsp;vel[2] = 0;

&nbsp;&nbsp;&nbsp;&nbsp;bob = sqrt( vel[0] * vel[0] + vel[1] * vel[1] ) * cl_bob->value;
&nbsp;&nbsp;&nbsp;&nbsp;bob = bob * 0.3 + bob * 0.7 * sin(cycle);
&nbsp;&nbsp;&nbsp;&nbsp;bob = min( bob, 4 );
&nbsp;&nbsp;&nbsp;&nbsp;bob = max( bob, -7 );
&nbsp;&nbsp;&nbsp;&nbsp;return bob;
&nbsp;&nbsp;&nbsp;&nbsp;
}

/*
===============
V_CalcRoll
Used by view and sv_user
===============
*/
float V_CalcRoll (vec3_t angles, vec3_t velocity, float rollangle, float rollspeed )
{
   float   sign;
   float   side;
   float   value;
&nbsp;&nbsp;&nbsp;&nbsp;vec3_t  forward, right, up;
   
&nbsp;&nbsp;&nbsp;&nbsp;AngleVectors ( angles, forward, right, up );
   
&nbsp;&nbsp;&nbsp;&nbsp;side = DotProduct (velocity, right);
   sign = side < 0 ? -1 : 1;
   side = fabs( side );
   
&nbsp;&nbsp;&nbsp;&nbsp;value = rollangle;
   if (side < rollspeed)
&nbsp;&nbsp;&nbsp;&nbsp;{
 side = side * value / rollspeed;
&nbsp;&nbsp;&nbsp;&nbsp;}
   else
&nbsp;&nbsp;&nbsp;&nbsp;{
 side = value;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;return side * sign;
}

typedef struct pitchdrift_s
{
&nbsp;&nbsp;&nbsp;&nbsp;float  pitchvel;
&nbsp;&nbsp;&nbsp;&nbsp;int  &nbsp;&nbsp;&nbsp;&nbsp;nodrift;
&nbsp;&nbsp;&nbsp;&nbsp;float  driftmove;
&nbsp;&nbsp;&nbsp;&nbsp;double  laststop;
} pitchdrift_t;

static pitchdrift_t pd;

void V_StartPitchDrift( void )
{
&nbsp;&nbsp;&nbsp;&nbsp;if ( pd.laststop == gEngfuncs.GetClientTime() )
&nbsp;&nbsp;&nbsp;&nbsp;{
 return;  // something else is keeping it from drifting
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;if ( pd.nodrift || !pd.pitchvel )
&nbsp;&nbsp;&nbsp;&nbsp;{
 pd.pitchvel = v_centerspeed->value;
 pd.nodrift = 0;
 pd.driftmove = 0;
&nbsp;&nbsp;&nbsp;&nbsp;}
}

void V_StopPitchDrift ( void )
{
&nbsp;&nbsp;&nbsp;&nbsp;pd.laststop = gEngfuncs.GetClientTime();
&nbsp;&nbsp;&nbsp;&nbsp;pd.nodrift = 1;
&nbsp;&nbsp;&nbsp;&nbsp;pd.pitchvel = 0;
}

/*
===============
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.
===============
*/
void V_DriftPitch ( struct ref_params_s *pparams )
{
&nbsp;&nbsp;&nbsp;&nbsp;float  delta, move;

&nbsp;&nbsp;&nbsp;&nbsp;if ( gEngfuncs.IsNoClipping() || !pparams->onground || pparams->demoplayback || pparams->spectator )
&nbsp;&nbsp;&nbsp;&nbsp;{
 pd.driftmove = 0;
 pd.pitchvel = 0;
 return;
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;// don't count small mouse motion
&nbsp;&nbsp;&nbsp;&nbsp;if (pd.nodrift)
&nbsp;&nbsp;&nbsp;&nbsp;{
 if ( fabs( pparams->cmd->forwardmove ) < cl_forwardspeed->value )
 &nbsp;&nbsp;&nbsp;&nbsp;pd.driftmove = 0;
 else
 &nbsp;&nbsp;&nbsp;&nbsp;pd.driftmove += pparams->frametime;
&nbsp;&nbsp;&nbsp;&nbsp;
 if ( pd.driftmove > v_centermove->value)
 {
 &nbsp;&nbsp;&nbsp;&nbsp;V_StartPitchDrift ();
 }
 return;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;delta = pparams->idealpitch - pparams->cl_viewangles[PITCH];

&nbsp;&nbsp;&nbsp;&nbsp;if (!delta)
&nbsp;&nbsp;&nbsp;&nbsp;{
 pd.pitchvel = 0;
 return;
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;move = pparams->frametime * pd.pitchvel;
&nbsp;&nbsp;&nbsp;&nbsp;pd.pitchvel += pparams->frametime * v_centerspeed->value;
&nbsp;&nbsp;&nbsp;&nbsp;
//Con_Printf ("move: %f (%f)\n", move, pparams->frametime);

&nbsp;&nbsp;&nbsp;&nbsp;if (delta > 0)
&nbsp;&nbsp;&nbsp;&nbsp;{
 if (move > delta)
 {
 &nbsp;&nbsp;&nbsp;&nbsp;pd.pitchvel = 0;
 &nbsp;&nbsp;&nbsp;&nbsp;move = delta;
 }
 pparams->cl_viewangles[PITCH] += move;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;else if (delta < 0)
&nbsp;&nbsp;&nbsp;&nbsp;{
 if (move > -delta)
 {
 &nbsp;&nbsp;&nbsp;&nbsp;pd.pitchvel = 0;
 &nbsp;&nbsp;&nbsp;&nbsp;move = -delta;
 }
 pparams->cl_viewangles[PITCH] -= move;
&nbsp;&nbsp;&nbsp;&nbsp;}
}

/*
==============================================================================
     VIEW RENDERING
==============================================================================
*/

/*
==================
V_CalcGunAngle
==================
*/
void V_CalcGunAngle ( struct ref_params_s *pparams )
{&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;cl_entity_t *viewent;
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;viewent = gEngfuncs.GetViewModel();
&nbsp;&nbsp;&nbsp;&nbsp;if ( !viewent )
 return;

&nbsp;&nbsp;&nbsp;&nbsp;viewent->angles[YAW]   =  pparams->viewangles[YAW]   + pparams->crosshairangle[YAW];
&nbsp;&nbsp;&nbsp;&nbsp;viewent->angles[PITCH] = -pparams->viewangles[PITCH] + pparams->crosshairangle[PITCH] * 0.25;
&nbsp;&nbsp;&nbsp;&nbsp;viewent->angles[ROLL]  -= v_idlescale * sin(pparams->time*v_iroll_cycle.value) * v_iroll_level.value;
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;// don't apply all of the v_ipitch to prevent normally unseen parts of viewmodel from coming into view.
&nbsp;&nbsp;&nbsp;&nbsp;viewent->angles[PITCH] -= v_idlescale * sin(pparams->time*v_ipitch_cycle.value) * (v_ipitch_level.value * 0.5);
&nbsp;&nbsp;&nbsp;&nbsp;viewent->angles[YAW]   -= v_idlescale * sin(pparams->time*v_iyaw_cycle.value) * v_iyaw_level.value;

&nbsp;&nbsp;&nbsp;&nbsp;VectorCopy( viewent->angles, viewent->curstate.angles );
&nbsp;&nbsp;&nbsp;&nbsp;VectorCopy( viewent->angles, viewent->latched.prevangles );
}

/*
==============
V_AddIdle

Idle swaying
==============
*/
void V_AddIdle ( struct ref_params_s *pparams )
{
&nbsp;&nbsp;&nbsp;&nbsp;pparams->viewangles[ROLL] += v_idlescale * sin(pparams->time*v_iroll_cycle.value) * v_iroll_level.value;
&nbsp;&nbsp;&nbsp;&nbsp;pparams->viewangles[PITCH] += v_idlescale * sin(pparams->time*v_ipitch_cycle.value) * v_ipitch_level.value;
&nbsp;&nbsp;&nbsp;&nbsp;pparams->viewangles[YAW] += v_idlescale * sin(pparams->time*v_iyaw_cycle.value) * v_iyaw_level.value;
}


/*
==============
V_CalcViewRoll

Roll is induced by movement and damage
==============
*/
void V_CalcViewRoll ( struct ref_params_s *pparams )
{
&nbsp;&nbsp;&nbsp;&nbsp;float  side;
&nbsp;&nbsp;&nbsp;&nbsp;cl_entity_t *viewentity;
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;viewentity = gEngfuncs.GetEntityByIndex( pparams->viewentity );
&nbsp;&nbsp;&nbsp;&nbsp;if ( !viewentity )
 return;

&nbsp;&nbsp;&nbsp;&nbsp;side = V_CalcRoll ( viewentity->angles, pparams->simvel, pparams->movevars->rollangle, pparams->movevars->rollspeed );

&nbsp;&nbsp;&nbsp;&nbsp;pparams->viewangles[ROLL] += side;

&nbsp;&nbsp;&nbsp;&nbsp;if ( pparams->health <= 0 &amp;&amp; ( pparams->viewheight[2] != 0 ) )
&nbsp;&nbsp;&nbsp;&nbsp;{
 // 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;&nbsp;&nbsp;&nbsp;&nbsp;// dead view angle
 return;
&nbsp;&nbsp;&nbsp;&nbsp;}
}


/*
==================
V_CalcIntermissionRefdef

==================
*/
void V_CalcIntermissionRefdef ( struct ref_params_s *pparams )
{
&nbsp;&nbsp;&nbsp;&nbsp;cl_entity_t&nbsp;&nbsp;&nbsp;&nbsp;*ent, *view;
&nbsp;&nbsp;&nbsp;&nbsp;float  old;

// don't allow cheats in multiplayer
#if !defined( _DEBUG )
&nbsp;&nbsp;&nbsp;&nbsp;if ( pparams->maxclients > 1 )
&nbsp;&nbsp;&nbsp;&nbsp;{
 gEngfuncs.Cvar_SetValue ("scr_ofsx", 0);
 gEngfuncs.Cvar_SetValue ("scr_ofsy", 0);
 gEngfuncs.Cvar_SetValue ("scr_ofsz", 0);
&nbsp;&nbsp;&nbsp;&nbsp;}
#endif

&nbsp;&nbsp;&nbsp;&nbsp;// ent is the player model ( visible when out of body )
&nbsp;&nbsp;&nbsp;&nbsp;ent = gEngfuncs.GetLocalPlayer();
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;// view is the weapon model (only visible from inside body )
&nbsp;&nbsp;&nbsp;&nbsp;view = gEngfuncs.GetViewModel();

&nbsp;&nbsp;&nbsp;&nbsp;VectorCopy ( pparams->simorg, pparams->vieworg );
&nbsp;&nbsp;&nbsp;&nbsp;VectorCopy ( pparams->cl_viewangles, pparams->viewangles );

&nbsp;&nbsp;&nbsp;&nbsp;view->model = NULL;

&nbsp;&nbsp;&nbsp;&nbsp;// allways idle in intermission
&nbsp;&nbsp;&nbsp;&nbsp;old = v_idlescale;
&nbsp;&nbsp;&nbsp;&nbsp;v_idlescale = 1;

&nbsp;&nbsp;&nbsp;&nbsp;V_AddIdle ( pparams );

&nbsp;&nbsp;&nbsp;&nbsp;v_idlescale = old;

&nbsp;&nbsp;&nbsp;&nbsp;v_origin = pparams->vieworg;
&nbsp;&nbsp;&nbsp;&nbsp;v_angles = pparams->viewangles;
}

#define ORIGIN_BACKUP 64
#define ORIGIN_MASK ( ORIGIN_BACKUP - 1 )

typedef struct
{
&nbsp;&nbsp;&nbsp;&nbsp;float Origins[ ORIGIN_BACKUP ][3];
&nbsp;&nbsp;&nbsp;&nbsp;float OriginTime[ ORIGIN_BACKUP ];

&nbsp;&nbsp;&nbsp;&nbsp;float Angles[ ORIGIN_BACKUP ][3];
&nbsp;&nbsp;&nbsp;&nbsp;float AngleTime[ ORIGIN_BACKUP ];

&nbsp;&nbsp;&nbsp;&nbsp;int CurrentOrigin;
&nbsp;&nbsp;&nbsp;&nbsp;int CurrentAngle;
} viewinterp_t;

/*
==================
V_CalcRefdef

==================
*/
void V_CalcNormalRefdef ( struct ref_params_s *pparams )
{
&nbsp;&nbsp;&nbsp;&nbsp;cl_entity_t  *ent, *view;
&nbsp;&nbsp;&nbsp;&nbsp;int    i;
&nbsp;&nbsp;&nbsp;&nbsp;vec3_t  &nbsp;&nbsp;&nbsp;&nbsp;angles;
&nbsp;&nbsp;&nbsp;&nbsp;float  &nbsp;&nbsp;&nbsp;&nbsp;bob, waterOffset;
&nbsp;&nbsp;&nbsp;&nbsp;static viewinterp_t  ViewInterp;

&nbsp;&nbsp;&nbsp;&nbsp;static float oldz = 0;
&nbsp;&nbsp;&nbsp;&nbsp;static float lasttime;

&nbsp;&nbsp;&nbsp;&nbsp;static float lastang[3];
&nbsp;&nbsp;&nbsp;&nbsp;vec3_t angdelta;

&nbsp;&nbsp;&nbsp;&nbsp;vec3_t camAngles, camForward, camRight, camUp;
&nbsp;&nbsp;&nbsp;&nbsp;cl_entity_t *pwater;

&nbsp;&nbsp;&nbsp;&nbsp;//Miagi to store flag
&nbsp;&nbsp;&nbsp;&nbsp;static float cam_gotofirstperson;

&nbsp;&nbsp;&nbsp;&nbsp;// don't allow cheats in multiplayer
&nbsp;&nbsp;&nbsp;&nbsp;if ( pparams->maxclients > 1 )
&nbsp;&nbsp;&nbsp;&nbsp;{
 scr_ofsx->value = 0.0;
 scr_ofsy->value = 0.0;
 scr_ofsz->value = 0.0;
&nbsp;&nbsp;&nbsp;&nbsp;}


&nbsp;&nbsp;&nbsp;&nbsp;V_DriftPitch ( pparams );

&nbsp;&nbsp;&nbsp;&nbsp;// ent is the player model ( visible when out of body )
&nbsp;&nbsp;&nbsp;&nbsp;ent = gEngfuncs.GetLocalPlayer();
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;// view is the weapon model (only visible from inside body )
&nbsp;&nbsp;&nbsp;&nbsp;view = gEngfuncs.GetViewModel();

&nbsp;&nbsp;&nbsp;&nbsp;// transform the view offset by the model's matrix to get the offset from
&nbsp;&nbsp;&nbsp;&nbsp;// model origin for the view
&nbsp;&nbsp;&nbsp;&nbsp;bob = V_CalcBob ( pparams );

&nbsp;&nbsp;&nbsp;&nbsp;// Observer angle capturing and smoothing
&nbsp;&nbsp;&nbsp;&nbsp;if ( iHasNewViewOrigin )
&nbsp;&nbsp;&nbsp;&nbsp;{
 // Get the angles from the physics code
 VectorCopy( vecNewViewOrigin, pparams->vieworg );
 VectorCopy( vecNewViewOrigin, pparams->simorg );
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;// refresh position
&nbsp;&nbsp;&nbsp;&nbsp;VectorCopy ( pparams->simorg, pparams->vieworg );
&nbsp;&nbsp;&nbsp;&nbsp;pparams->vieworg[2] += ( bob );
&nbsp;&nbsp;&nbsp;&nbsp;VectorAdd( pparams->vieworg, pparams->viewheight, pparams->vieworg );

&nbsp;&nbsp;&nbsp;&nbsp;// Observer angle capturing and smoothing
&nbsp;&nbsp;&nbsp;&nbsp;if ( iHasNewViewAngles )
&nbsp;&nbsp;&nbsp;&nbsp;{
 // Get the angles from the physics code
 VectorCopy( vecNewViewAngles, pparams->cl_viewangles );
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;else if ( pparams->health == -5 )
&nbsp;&nbsp;&nbsp;&nbsp;{
 //Miagi saving view
 if ( !CL_IsThirdPerson() )
 {
   cam_gotofirstperson = 1;
 }
 //End Miagi saving
 CAM_ToThirdPerson();

 // Lock mouse movement   Miagi-Dont lock
 iMouseInUse=0;

 pparams->cl_viewangles[0] = 89;

 // Spin the view
 float flTimeDelta = (pparams->time - g_flStartScaleTime);
 if ( flTimeDelta > 0 )
 {
 &nbsp;&nbsp;&nbsp;&nbsp;float flROFSpin = 1.0 + (flTimeDelta * 2.0);
 &nbsp;&nbsp;&nbsp;&nbsp;float flSpin = flTimeDelta * 45;

 &nbsp;&nbsp;&nbsp;&nbsp;pparams->cl_viewangles[1] = flSpin * flROFSpin;
 }
 
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;//Miagi Go back to first if in first
&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;{
 if ( cam_gotofirstperson == 1 )
 {
 &nbsp;&nbsp;&nbsp;&nbsp;cam_gotofirstperson = 0;
 &nbsp;&nbsp;&nbsp;&nbsp;CAM_ToFirstPerson();
 }
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;//End Miagi
/*&nbsp;&nbsp;&nbsp;&nbsp;else    causing the problem.. Miagi
&nbsp;&nbsp;&nbsp;&nbsp;{
 //CAM_ToFirstPerson();

 // Unlock mouse movement
 //iMouseInUse=0;

 CAM_ToThirdPerson();

 // Lock mouse movement
 iMouseInUse=0;

&nbsp;&nbsp;&nbsp;&nbsp;}*/

&nbsp;&nbsp;&nbsp;&nbsp;VectorSubtract( pparams->cl_viewangles, lastang, angdelta );
&nbsp;&nbsp;&nbsp;&nbsp;if ( Length( angdelta ) != 0.0 )
&nbsp;&nbsp;&nbsp;&nbsp;{
 VectorCopy( pparams->cl_viewangles, ViewInterp.Angles[ ViewInterp.CurrentAngle &amp; ORIGIN_MASK ] );
 ViewInterp.AngleTime[ ViewInterp.CurrentAngle &amp; ORIGIN_MASK ] = pparams->time;
 ViewInterp.CurrentAngle++;

 VectorCopy( pparams->cl_viewangles, lastang );
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;if ( cl_vsmoothing &amp;&amp; cl_vsmoothing->value &amp;&amp; ( iIsSpectator &amp; SPEC_SMOOTH_ANGLES ) )
&nbsp;&nbsp;&nbsp;&nbsp;{
 int foundidx;
 int i;
 float t;

 if ( cl_vsmoothing->value < 0.0 )
 {
 &nbsp;&nbsp;&nbsp;&nbsp;gEngfuncs.Cvar_SetValue( "cl_vsmoothing", 0.0 );
 }

 t = pparams->time - cl_vsmoothing->value;

 for ( i = 1; i < ORIGIN_MASK; i++ )
 {
 &nbsp;&nbsp;&nbsp;&nbsp;foundidx = ViewInterp.CurrentAngle - 1 - i;
 &nbsp;&nbsp;&nbsp;&nbsp;if ( ViewInterp.AngleTime[ foundidx &amp; ORIGIN_MASK ] <= t )
   break;
 }

 if ( i < ORIGIN_MASK &amp;&amp; ViewInterp.AngleTime[ foundidx &amp; ORIGIN_MASK ] != 0.0 )
 {
 &nbsp;&nbsp;&nbsp;&nbsp;// Interpolate
 &nbsp;&nbsp;&nbsp;&nbsp;double dt;

 &nbsp;&nbsp;&nbsp;&nbsp;dt = ViewInterp.AngleTime[ (foundidx + 1) &amp; ORIGIN_MASK ] - ViewInterp.AngleTime[ foundidx &amp; ORIGIN_MASK ];
 &nbsp;&nbsp;&nbsp;&nbsp;if ( dt > 0.0 )
 &nbsp;&nbsp;&nbsp;&nbsp;{
   double frac;

   frac = ( t - ViewInterp.AngleTime[ foundidx &amp; ORIGIN_MASK] ) / dt;
   frac = min( 1.0, frac );

   // interpolate angles
   V_InterpolateAngles( ViewInterp.Angles[ foundidx &amp; ORIGIN_MASK ], ViewInterp.Angles[ (foundidx + 1) &amp; ORIGIN_MASK ], pparams->cl_viewangles, frac );

   VectorCopy( pparams->cl_viewangles, vecNewViewAngles );
 &nbsp;&nbsp;&nbsp;&nbsp;}
 }
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;VectorCopy ( pparams->cl_viewangles, pparams->viewangles );

&nbsp;&nbsp;&nbsp;&nbsp;gEngfuncs.V_CalcShake();
&nbsp;&nbsp;&nbsp;&nbsp;gEngfuncs.V_ApplyShake( pparams->vieworg, pparams->viewangles, 1.0 );

&nbsp;&nbsp;&nbsp;&nbsp;// never let view origin sit exactly on a node line, because a water plane can
&nbsp;&nbsp;&nbsp;&nbsp;// dissapear when viewed with the eye exactly on it.
&nbsp;&nbsp;&nbsp;&nbsp;// FIXME, we send origin at 1/128 now, change this?
&nbsp;&nbsp;&nbsp;&nbsp;// the server protocol only specifies to 1/16 pixel, so add 1/32 in each axis
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;pparams->vieworg[0] += 1.0/32;
&nbsp;&nbsp;&nbsp;&nbsp;pparams->vieworg[1] += 1.0/32;
&nbsp;&nbsp;&nbsp;&nbsp;pparams->vieworg[2] += 1.0/32;

&nbsp;&nbsp;&nbsp;&nbsp;// Check for problems around water, move the viewer artificially if necessary
&nbsp;&nbsp;&nbsp;&nbsp;// -- this prevents drawing errors in GL due to waves

&nbsp;&nbsp;&nbsp;&nbsp;waterOffset = 0;
&nbsp;&nbsp;&nbsp;&nbsp;if ( pparams->waterlevel >= 2 )
&nbsp;&nbsp;&nbsp;&nbsp;{
 int  i, contents, waterDist, waterEntity;
 vec3_t&nbsp;&nbsp;&nbsp;&nbsp;point;
 waterDist = cl_waterdist->value;

 if ( pparams->hardware )
 {
 &nbsp;&nbsp;&nbsp;&nbsp;waterEntity = gEngfuncs.PM_WaterEntity( pparams->simorg );
 &nbsp;&nbsp;&nbsp;&nbsp;if ( waterEntity >= 0 &amp;&amp; waterEntity < pparams->max_entities )
 &nbsp;&nbsp;&nbsp;&nbsp;{
   pwater = gEngfuncs.GetEntityByIndex( waterEntity );
   if ( pwater &amp;&amp; ( pwater->model != NULL ) )
   {
   &nbsp;&nbsp;&nbsp;&nbsp;waterDist += ( pwater->curstate.scale * 16 );&nbsp;&nbsp;&nbsp;&nbsp;// Add in wave height
   }
 &nbsp;&nbsp;&nbsp;&nbsp;}
 }
 else
 {
 &nbsp;&nbsp;&nbsp;&nbsp;waterEntity = 0;&nbsp;&nbsp;&nbsp;&nbsp;// Don't need this in software
 }
 
 VectorCopy( pparams->vieworg, point );

 // Eyes are above water, make sure we're above the waves
 if ( pparams->waterlevel == 2 )&nbsp;&nbsp;&nbsp;&nbsp;
 {
 &nbsp;&nbsp;&nbsp;&nbsp;point[2] -= waterDist;
 &nbsp;&nbsp;&nbsp;&nbsp;for ( i = 0; i < waterDist; i++ )
 &nbsp;&nbsp;&nbsp;&nbsp;{
   contents = gEngfuncs.PM_PointContents( point, NULL );
   if ( contents > CONTENTS_WATER )
   &nbsp;&nbsp;&nbsp;&nbsp;break;
   point[2] += 1;
 &nbsp;&nbsp;&nbsp;&nbsp;}
 &nbsp;&nbsp;&nbsp;&nbsp;waterOffset = (point[2] + waterDist) - pparams->vieworg[2];
 }
 else
 {
 &nbsp;&nbsp;&nbsp;&nbsp;// eyes are under water.  Make sure we're far enough under
 &nbsp;&nbsp;&nbsp;&nbsp;point[2] += waterDist;

 &nbsp;&nbsp;&nbsp;&nbsp;for ( i = 0; i < waterDist; i++ )
 &nbsp;&nbsp;&nbsp;&nbsp;{
   contents = gEngfuncs.PM_PointContents( point, NULL );
   if ( contents <= CONTENTS_WATER )
   &nbsp;&nbsp;&nbsp;&nbsp;break;
   point[2] -= 1;
 &nbsp;&nbsp;&nbsp;&nbsp;}
 &nbsp;&nbsp;&nbsp;&nbsp;waterOffset = (point[2] - waterDist) - pparams->vieworg[2];
 }
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;pparams->vieworg[2] += waterOffset;
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;V_CalcViewRoll ( pparams );
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;V_AddIdle ( pparams );

&nbsp;&nbsp;&nbsp;&nbsp;// offsets
&nbsp;&nbsp;&nbsp;&nbsp;VectorCopy( pparams->cl_viewangles, angles );

&nbsp;&nbsp;&nbsp;&nbsp;AngleVectors ( angles, pparams->forward, pparams->right, pparams->up );

&nbsp;&nbsp;&nbsp;&nbsp;for ( i=0; i<3; i++ )
&nbsp;&nbsp;&nbsp;&nbsp;{
 pparams->vieworg[i] += scr_ofsx->value*pparams->forward[i] + scr_ofsy->value*pparams->right[i] + scr_ofsz->value*pparams->up[i];
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;// Treating cam_ofs[2] as the distance
&nbsp;&nbsp;&nbsp;&nbsp;if( CL_IsThirdPerson() )
&nbsp;&nbsp;&nbsp;&nbsp;{
 vec3_t ofs;
 ofs[0] = ofs[1] = ofs[2] = 0.0;
 CL_CameraOffset( (float *)&amp;ofs );

 VectorCopy( ofs, camAngles );
 camAngles[ ROLL ]&nbsp;&nbsp;&nbsp;&nbsp;= 0;
 AngleVectors( camAngles, camForward, camRight, camUp );

 // Is the player in a falling anim? If so, raise camera above and look down
 if ( pparams->health == -5 )
 {
 &nbsp;&nbsp;&nbsp;&nbsp;pparams->vieworg[2] += 92;
 }
 else
 {
 &nbsp;&nbsp;&nbsp;&nbsp;for ( i = 0; i < 3; i++ )
 &nbsp;&nbsp;&nbsp;&nbsp;{
   pparams->vieworg[ i ] += -ofs[2] * camForward[ i ];
 &nbsp;&nbsp;&nbsp;&nbsp;}

 &nbsp;&nbsp;&nbsp;&nbsp;pparams->vieworg[2] += 20;
 }
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;// Give gun our viewangles
&nbsp;&nbsp;&nbsp;&nbsp;VectorCopy ( pparams->cl_viewangles, view->angles );
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;// set up gun position
&nbsp;&nbsp;&nbsp;&nbsp;V_CalcGunAngle ( pparams );

&nbsp;&nbsp;&nbsp;&nbsp;// Use predicted origin as view origin.
&nbsp;&nbsp;&nbsp;&nbsp;VectorCopy ( pparams->simorg, view->origin );      
&nbsp;&nbsp;&nbsp;&nbsp;view->origin[2] += ( waterOffset );
&nbsp;&nbsp;&nbsp;&nbsp;VectorAdd( view->origin, pparams->viewheight, view->origin );

&nbsp;&nbsp;&nbsp;&nbsp;// Let the viewmodel shake at about 10% of the amplitude
&nbsp;&nbsp;&nbsp;&nbsp;gEngfuncs.V_ApplyShake( view->origin, view->angles, 0.9 );

&nbsp;&nbsp;&nbsp;&nbsp;for ( i = 0; i < 3; i++ )
&nbsp;&nbsp;&nbsp;&nbsp;{
 view->origin[ i ] += bob * 0.4 * pparams->forward[ i ];
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;view->origin[2] += bob;

&nbsp;&nbsp;&nbsp;&nbsp;// throw in a little tilt.
&nbsp;&nbsp;&nbsp;&nbsp;view->angles[YAW]   -= bob * 0.5;
&nbsp;&nbsp;&nbsp;&nbsp;view->angles[ROLL]  -= bob * 1;
&nbsp;&nbsp;&nbsp;&nbsp;view->angles[PITCH] -= bob * 0.3;

&nbsp;&nbsp;&nbsp;&nbsp;// pushing the view origin down off of the same X/Z plane as the ent's origin will give the
&nbsp;&nbsp;&nbsp;&nbsp;// gun a very nice 'shifting' effect when the player looks up/down. If there is a problem
&nbsp;&nbsp;&nbsp;&nbsp;// with view model distortion, this may be a cause. (SJB).
&nbsp;&nbsp;&nbsp;&nbsp;view->origin[2] -= 1;

&nbsp;&nbsp;&nbsp;&nbsp;// fudge position around to keep amount of weapon visible
&nbsp;&nbsp;&nbsp;&nbsp;// roughly equal with different FOV
&nbsp;&nbsp;&nbsp;&nbsp;if (pparams->viewsize == 110)
&nbsp;&nbsp;&nbsp;&nbsp;{
 view->origin[2] += 1;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;else if (pparams->viewsize == 100)
&nbsp;&nbsp;&nbsp;&nbsp;{
 view->origin[2] += 2;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;else if (pparams->viewsize == 90)
&nbsp;&nbsp;&nbsp;&nbsp;{
 view->origin[2] += 1;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;else if (pparams->viewsize == 80)
&nbsp;&nbsp;&nbsp;&nbsp;{
 view->origin[2] += 0.5;
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;// Add in the punchangle, if any
&nbsp;&nbsp;&nbsp;&nbsp;VectorAdd ( pparams->viewangles, pparams->punchangle, pparams->viewangles );

&nbsp;&nbsp;&nbsp;&nbsp;// Include client side punch, too
&nbsp;&nbsp;&nbsp;&nbsp;VectorAdd ( pparams->viewangles, (float *)&amp;ev_punchangle, pparams->viewangles);

&nbsp;&nbsp;&nbsp;&nbsp;V_DropPunchAngle ( pparams->frametime, (float *)&amp;ev_punchangle );

&nbsp;&nbsp;&nbsp;&nbsp;// smooth out stair step ups
#if 1
&nbsp;&nbsp;&nbsp;&nbsp;if ( !pparams->smoothing &amp;&amp; pparams->onground &amp;&amp; pparams->simorg[2] - oldz > 0)
&nbsp;&nbsp;&nbsp;&nbsp;{
 float steptime;
 
 steptime = pparams->time - lasttime;
 if (steptime < 0)
&nbsp;&nbsp;&nbsp;&nbsp;//FIXME  I_Error ("steptime < 0");
 &nbsp;&nbsp;&nbsp;&nbsp;steptime = 0;

 oldz += steptime * 150;
 if (oldz > pparams->simorg[2])
 &nbsp;&nbsp;&nbsp;&nbsp;oldz = pparams->simorg[2];
 if (pparams->simorg[2] - oldz > 18)
 &nbsp;&nbsp;&nbsp;&nbsp;oldz = pparams->simorg[2]- 18;
 pparams->vieworg[2] += oldz - pparams->simorg[2];
 view->origin[2] += oldz - pparams->simorg[2];
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;{
 oldz = pparams->simorg[2];
&nbsp;&nbsp;&nbsp;&nbsp;}
#endif

&nbsp;&nbsp;&nbsp;&nbsp;{
 static float lastorg[3];
 vec3_t delta;

 VectorSubtract( pparams->simorg, lastorg, delta );

 if ( Length( delta ) != 0.0 )
 {
 &nbsp;&nbsp;&nbsp;&nbsp;VectorCopy( pparams->simorg, ViewInterp.Origins[ ViewInterp.CurrentOrigin &amp; ORIGIN_MASK ] );
 &nbsp;&nbsp;&nbsp;&nbsp;ViewInterp.OriginTime[ ViewInterp.CurrentOrigin &amp; ORIGIN_MASK ] = pparams->time;
 &nbsp;&nbsp;&nbsp;&nbsp;ViewInterp.CurrentOrigin++;

 &nbsp;&nbsp;&nbsp;&nbsp;VectorCopy( pparams->simorg, lastorg );
 }
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;// Smooth out whole view in multiplayer when on trains, lifts
&nbsp;&nbsp;&nbsp;&nbsp;if ( cl_vsmoothing &amp;&amp; cl_vsmoothing->value &amp;&amp;
 ( ( iIsSpectator &amp; SPEC_SMOOTH_ORIGIN ) || (pparams->smoothing &amp;&amp; ( pparams->maxclients > 1 ) ) ) )
&nbsp;&nbsp;&nbsp;&nbsp;{
 int foundidx;
 int i;
 float t;

 if ( cl_vsmoothing->value < 0.0 )
 {
 &nbsp;&nbsp;&nbsp;&nbsp;gEngfuncs.Cvar_SetValue( "cl_vsmoothing", 0.0 );
 }

 t = pparams->time - cl_vsmoothing->value;

 for ( i = 1; i < ORIGIN_MASK; i++ )
 {
 &nbsp;&nbsp;&nbsp;&nbsp;foundidx = ViewInterp.CurrentOrigin - 1 - i;
 &nbsp;&nbsp;&nbsp;&nbsp;if ( ViewInterp.OriginTime[ foundidx &amp; ORIGIN_MASK ] <= t )
   break;
 }

 if ( i < ORIGIN_MASK &amp;&amp;  ViewInterp.OriginTime[ foundidx &amp; ORIGIN_MASK ] != 0.0 )
 {
 &nbsp;&nbsp;&nbsp;&nbsp;// Interpolate
 &nbsp;&nbsp;&nbsp;&nbsp;vec3_t delta;
 &nbsp;&nbsp;&nbsp;&nbsp;double frac;
 &nbsp;&nbsp;&nbsp;&nbsp;double dt;
 &nbsp;&nbsp;&nbsp;&nbsp;vec3_t neworg;

 &nbsp;&nbsp;&nbsp;&nbsp;dt = ViewInterp.OriginTime[ (foundidx + 1) &amp; ORIGIN_MASK ] - ViewInterp.OriginTime[ foundidx &amp; ORIGIN_MASK ];
 &nbsp;&nbsp;&nbsp;&nbsp;if ( dt > 0.0 )
 &nbsp;&nbsp;&nbsp;&nbsp;{
   frac = ( t - ViewInterp.OriginTime[ foundidx &amp; ORIGIN_MASK] ) / dt;
   frac = min( 1.0, frac );
   VectorSubtract( ViewInterp.Origins[ ( foundidx + 1 ) &amp; ORIGIN_MASK ], ViewInterp.Origins[ foundidx &amp; ORIGIN_MASK ], delta );
   VectorMA( ViewInterp.Origins[ foundidx &amp; ORIGIN_MASK ], frac, delta, neworg );

   // Dont interpolate large changes
   if ( Length( delta ) < 64 )
   {
   &nbsp;&nbsp;&nbsp;&nbsp;VectorSubtract( neworg, pparams->simorg, delta );

   &nbsp;&nbsp;&nbsp;&nbsp;VectorAdd( pparams->simorg, delta, pparams->simorg );
   &nbsp;&nbsp;&nbsp;&nbsp;VectorAdd( pparams->vieworg, delta, pparams->vieworg );
   &nbsp;&nbsp;&nbsp;&nbsp;VectorAdd( view->origin, delta, view->origin );

   &nbsp;&nbsp;&nbsp;&nbsp;VectorCopy( pparams->simorg, vecNewViewOrigin );
   }
 &nbsp;&nbsp;&nbsp;&nbsp;}
 }
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;// Store off v_angles before munging for third person
&nbsp;&nbsp;&nbsp;&nbsp;v_angles = pparams->viewangles;

&nbsp;&nbsp;&nbsp;&nbsp;if ( CL_IsThirdPerson() )
&nbsp;&nbsp;&nbsp;&nbsp;{
 VectorCopy( camAngles, pparams->viewangles);
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;// override all previous settings if the viewent isn't the client
&nbsp;&nbsp;&nbsp;&nbsp;if ( pparams->viewentity > pparams->maxclients )
&nbsp;&nbsp;&nbsp;&nbsp;{
 cl_entity_t *viewentity;
 viewentity = gEngfuncs.GetEntityByIndex( pparams->viewentity );
 if ( viewentity )
 {
 &nbsp;&nbsp;&nbsp;&nbsp;VectorCopy( viewentity->origin, pparams->vieworg );
 &nbsp;&nbsp;&nbsp;&nbsp;VectorCopy( viewentity->angles, pparams->viewangles );

 &nbsp;&nbsp;&nbsp;&nbsp;// Store off overridden viewangles
 &nbsp;&nbsp;&nbsp;&nbsp;v_angles = pparams->viewangles;
 }
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;lasttime = pparams->time;

&nbsp;&nbsp;&nbsp;&nbsp;v_origin = pparams->vieworg;
}

void DLLEXPORT V_CalcRefdef( struct ref_params_s *pparams )
{
&nbsp;&nbsp;&nbsp;&nbsp;// intermission / finale rendering
&nbsp;&nbsp;&nbsp;&nbsp;if ( pparams->intermission )
&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;
 V_CalcIntermissionRefdef ( pparams );&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;else if ( !pparams->paused )
&nbsp;&nbsp;&nbsp;&nbsp;{
 V_CalcNormalRefdef ( pparams );
&nbsp;&nbsp;&nbsp;&nbsp;}

/*
// Example of how to overlay the whole screen with red at 50 % alpha
#define SF_TEST
#if defined SF_TEST
&nbsp;&nbsp;&nbsp;&nbsp;{
 screenfade_t sf;
 gEngfuncs.pfnGetScreenFade( &amp;sf );

 sf.fader = 255;
 sf.fadeg = 0;
 sf.fadeb = 0;
 sf.fadealpha = 128;
 sf.fadeFlags = FFADE_STAYOUT | FFADE_OUT;

 gEngfuncs.pfnSetScreenFade( &amp;sf );
&nbsp;&nbsp;&nbsp;&nbsp;}
#endif
*/
}

/*
=============
V_DropPunchAngle

=============
*/
void V_DropPunchAngle ( float frametime, float *ev_punchangle )
{
&nbsp;&nbsp;&nbsp;&nbsp;float&nbsp;&nbsp;&nbsp;&nbsp;len;
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;len = VectorNormalize ( ev_punchangle );
&nbsp;&nbsp;&nbsp;&nbsp;len -= (10.0 + len * 0.5) * frametime;
&nbsp;&nbsp;&nbsp;&nbsp;len = max( len, 0.0 );
&nbsp;&nbsp;&nbsp;&nbsp;VectorScale ( ev_punchangle, len, ev_punchangle );
}

/*
=============
V_PunchAxis

Client side punch effect
=============
*/
void V_PunchAxis( int axis, float punch )
{
&nbsp;&nbsp;&nbsp;&nbsp;ev_punchangle[ axis ] = punch;
}

/*
=============
V_Init
=============
*/
void V_Init (void)
{
&nbsp;&nbsp;&nbsp;&nbsp;gEngfuncs.pfnAddCommand ("centerview", V_StartPitchDrift );

&nbsp;&nbsp;&nbsp;&nbsp;scr_ofsx  &nbsp;&nbsp;&nbsp;&nbsp;= gEngfuncs.pfnRegisterVariable( "scr_ofsx","0", 0 );
&nbsp;&nbsp;&nbsp;&nbsp;scr_ofsy  &nbsp;&nbsp;&nbsp;&nbsp;= gEngfuncs.pfnRegisterVariable( "scr_ofsy","0", 0 );
&nbsp;&nbsp;&nbsp;&nbsp;scr_ofsz  &nbsp;&nbsp;&nbsp;&nbsp;= gEngfuncs.pfnRegisterVariable( "scr_ofsz","0", 0 );

&nbsp;&nbsp;&nbsp;&nbsp;v_centermove  = gEngfuncs.pfnRegisterVariable( "v_centermove", "0.15", 0 );
&nbsp;&nbsp;&nbsp;&nbsp;v_centerspeed  = gEngfuncs.pfnRegisterVariable( "v_centerspeed","500", 0 );

&nbsp;&nbsp;&nbsp;&nbsp;cl_bobcycle  &nbsp;&nbsp;&nbsp;&nbsp;= gEngfuncs.pfnRegisterVariable( "cl_bobcycle","0.8", 0 );// best default for my experimental gun wag (sjb)
&nbsp;&nbsp;&nbsp;&nbsp;cl_bob    = gEngfuncs.pfnRegisterVariable( "cl_bob","0.01", 0 );// best default for my experimental gun wag (sjb)
&nbsp;&nbsp;&nbsp;&nbsp;cl_bobup  &nbsp;&nbsp;&nbsp;&nbsp;= gEngfuncs.pfnRegisterVariable( "cl_bobup","0.5", 0 );
&nbsp;&nbsp;&nbsp;&nbsp;cl_waterdist  = gEngfuncs.pfnRegisterVariable( "cl_waterdist","4", 0 );
}


//#define TRACE_TEST
#if defined( TRACE_TEST )

extern float in_fov;
/*
====================
CalcFov
====================
*/
float CalcFov (float fov_x, float width, float height)
{
&nbsp;&nbsp;&nbsp;&nbsp;float&nbsp;&nbsp;&nbsp;&nbsp;a;
&nbsp;&nbsp;&nbsp;&nbsp;float&nbsp;&nbsp;&nbsp;&nbsp;x;

&nbsp;&nbsp;&nbsp;&nbsp;if (fov_x < 1 || fov_x > 179)
 fov_x = 90;&nbsp;&nbsp;&nbsp;&nbsp;// error, set to 90

&nbsp;&nbsp;&nbsp;&nbsp;x = width/tan(fov_x/360*M_PI);

&nbsp;&nbsp;&nbsp;&nbsp;a = atan (height/x);

&nbsp;&nbsp;&nbsp;&nbsp;a = a*360/M_PI;

&nbsp;&nbsp;&nbsp;&nbsp;return a;
}

int hitent = -1;

void V_Move( int mx, int my )
{
&nbsp;&nbsp;&nbsp;&nbsp;float fov;
&nbsp;&nbsp;&nbsp;&nbsp;float fx, fy;
&nbsp;&nbsp;&nbsp;&nbsp;float dx, dy;
&nbsp;&nbsp;&nbsp;&nbsp;float c_x, c_y;
&nbsp;&nbsp;&nbsp;&nbsp;float dX, dY;
&nbsp;&nbsp;&nbsp;&nbsp;vec3_t forward, up, right;
&nbsp;&nbsp;&nbsp;&nbsp;vec3_t newangles;

&nbsp;&nbsp;&nbsp;&nbsp;vec3_t farpoint;
&nbsp;&nbsp;&nbsp;&nbsp;pmtrace_t tr;

&nbsp;&nbsp;&nbsp;&nbsp;fov = CalcFov( in_fov, (float)ScreenWidth, (float)ScreenHeight );

&nbsp;&nbsp;&nbsp;&nbsp;c_x = (float)ScreenWidth / 2.0;
&nbsp;&nbsp;&nbsp;&nbsp;c_y = (float)ScreenHeight / 2.0;

&nbsp;&nbsp;&nbsp;&nbsp;dx = (float)mx - c_x;
&nbsp;&nbsp;&nbsp;&nbsp;dy = (float)my - c_y;

&nbsp;&nbsp;&nbsp;&nbsp;// Proportion we moved in each direction
&nbsp;&nbsp;&nbsp;&nbsp;fx = dx / c_x;
&nbsp;&nbsp;&nbsp;&nbsp;fy = dy / c_y;

&nbsp;&nbsp;&nbsp;&nbsp;dX = fx * in_fov / 2.0;
&nbsp;&nbsp;&nbsp;&nbsp;dY = fy * fov / 2.0;

&nbsp;&nbsp;&nbsp;&nbsp;newangles = v_angles;

&nbsp;&nbsp;&nbsp;&nbsp;newangles[ YAW ] -= dX;
&nbsp;&nbsp;&nbsp;&nbsp;newangles[ PITCH ] += dY;

&nbsp;&nbsp;&nbsp;&nbsp;// Now rotate v_forward around that point
&nbsp;&nbsp;&nbsp;&nbsp;AngleVectors ( newangles, forward, right, up );

&nbsp;&nbsp;&nbsp;&nbsp;farpoint = v_origin + 8192 * forward;

&nbsp;&nbsp;&nbsp;&nbsp;// Trace
&nbsp;&nbsp;&nbsp;&nbsp;tr = *(gEngfuncs.PM_TraceLine( (float *)&amp;v_origin, (float *)&amp;farpoint, PM_TRACELINE_PHYSENTSONLY, 2 /*point sized hull*/, -1 ));

&nbsp;&nbsp;&nbsp;&nbsp;if ( tr.fraction != 1.0 &amp;&amp; tr.ent != 0 )
&nbsp;&nbsp;&nbsp;&nbsp;{
 hitent = PM_GetInfo( tr.ent );
 PM_ParticleLine( (float *)&amp;v_origin, (float *)&amp;tr.endpos, 5, 1.0, 0.0 );
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;{
 hitent = -1;
&nbsp;&nbsp;&nbsp;&nbsp;}
}

#endif
&lt;@Miagi&gt; !8 Am I spamming?
&lt;@ChanServ&gt; Miagi: Yes.
&lt;@Miagi&gt; !8 Should I stop?
&lt;@ChanServ&gt; Miagi: Oh, please, PLEASE, make it stop!

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)