📄 view.c
字号:
ib = i*a + b;
if (ir > 255)
ir = 255;
if (ig > 255)
ig = 255;
if (ib > 255)
ib = 255;
ramps[0][i] = gammatable[ir];
ramps[1][i] = gammatable[ig];
ramps[2][i] = gammatable[ib];
}
basepal = host_basepal;
newpal = pal;
for (i=0 ; i<256 ; i++)
{
ir = basepal[0];
ig = basepal[1];
ib = basepal[2];
basepal += 3;
newpal[0] = ramps[0][ir];
newpal[1] = ramps[1][ig];
newpal[2] = ramps[2][ib];
newpal += 3;
}
VID_ShiftPalette (pal);
}
#else // !GLQUAKE
void V_UpdatePalette (void)
{
int i, j;
qboolean new;
byte *basepal, *newpal;
byte pal[768];
int r,g,b;
qboolean force;
V_CalcPowerupCshift ();
new = false;
for (i=0 ; i<NUM_CSHIFTS ; i++)
{
if (cl.cshifts[i].percent != cl.prev_cshifts[i].percent)
{
new = true;
cl.prev_cshifts[i].percent = cl.cshifts[i].percent;
}
for (j=0 ; j<3 ; j++)
if (cl.cshifts[i].destcolor[j] != cl.prev_cshifts[i].destcolor[j])
{
new = true;
cl.prev_cshifts[i].destcolor[j] = cl.cshifts[i].destcolor[j];
}
}
// drop the damage value
cl.cshifts[CSHIFT_DAMAGE].percent -= host_frametime*150;
if (cl.cshifts[CSHIFT_DAMAGE].percent <= 0)
cl.cshifts[CSHIFT_DAMAGE].percent = 0;
// drop the bonus value
cl.cshifts[CSHIFT_BONUS].percent -= host_frametime*100;
if (cl.cshifts[CSHIFT_BONUS].percent <= 0)
cl.cshifts[CSHIFT_BONUS].percent = 0;
force = V_CheckGamma ();
if (!new && !force)
return;
basepal = host_basepal;
newpal = pal;
for (i=0 ; i<256 ; i++)
{
r = basepal[0];
g = basepal[1];
b = basepal[2];
basepal += 3;
for (j=0 ; j<NUM_CSHIFTS ; j++)
{
r += (cl.cshifts[j].percent*(cl.cshifts[j].destcolor[0]-r))>>8;
g += (cl.cshifts[j].percent*(cl.cshifts[j].destcolor[1]-g))>>8;
b += (cl.cshifts[j].percent*(cl.cshifts[j].destcolor[2]-b))>>8;
}
newpal[0] = gammatable[r];
newpal[1] = gammatable[g];
newpal[2] = gammatable[b];
newpal += 3;
}
VID_ShiftPalette (pal);
}
#endif // !GLQUAKE
/*
==============================================================================
VIEW RENDERING
==============================================================================
*/
float angledelta (float a)
{
a = anglemod(a);
if (a > 180)
a -= 360;
return a;
}
/*
==================
CalcGunAngle
==================
*/
void CalcGunAngle (void)
{
float yaw, pitch, move;
static float oldyaw = 0;
static float oldpitch = 0;
yaw = r_refdef.viewangles[YAW];
pitch = -r_refdef.viewangles[PITCH];
yaw = angledelta(yaw - r_refdef.viewangles[YAW]) * 0.4;
if (yaw > 10)
yaw = 10;
if (yaw < -10)
yaw = -10;
pitch = angledelta(-pitch - r_refdef.viewangles[PITCH]) * 0.4;
if (pitch > 10)
pitch = 10;
if (pitch < -10)
pitch = -10;
move = host_frametime*20;
if (yaw > oldyaw)
{
if (oldyaw + move < yaw)
yaw = oldyaw + move;
}
else
{
if (oldyaw - move > yaw)
yaw = oldyaw - move;
}
if (pitch > oldpitch)
{
if (oldpitch + move < pitch)
pitch = oldpitch + move;
}
else
{
if (oldpitch - move > pitch)
pitch = oldpitch - move;
}
oldyaw = yaw;
oldpitch = pitch;
cl.viewent.angles[YAW] = r_refdef.viewangles[YAW] + yaw;
cl.viewent.angles[PITCH] = - (r_refdef.viewangles[PITCH] + pitch);
cl.viewent.angles[ROLL] -= v_idlescale->value * sin(cl.time*v_iroll_cycle->value) * v_iroll_level->value;
cl.viewent.angles[PITCH] -= v_idlescale->value * sin(cl.time*v_ipitch_cycle->value) * v_ipitch_level->value;
cl.viewent.angles[YAW] -= v_idlescale->value * sin(cl.time*v_iyaw_cycle->value) * v_iyaw_level->value;
}
/*
==============
V_BoundOffsets
==============
*/
void V_BoundOffsets (void)
{
entity_t *ent;
ent = &cl_entities[cl.viewentity];
// absolutely bound refresh reletive to entity clipping hull
// so the view can never be inside a solid wall
if (r_refdef.vieworg[0] < ent->origin[0] - 14)
r_refdef.vieworg[0] = ent->origin[0] - 14;
else if (r_refdef.vieworg[0] > ent->origin[0] + 14)
r_refdef.vieworg[0] = ent->origin[0] + 14;
if (r_refdef.vieworg[1] < ent->origin[1] - 14)
r_refdef.vieworg[1] = ent->origin[1] - 14;
else if (r_refdef.vieworg[1] > ent->origin[1] + 14)
r_refdef.vieworg[1] = ent->origin[1] + 14;
if (r_refdef.vieworg[2] < ent->origin[2] - 22)
r_refdef.vieworg[2] = ent->origin[2] - 22;
else if (r_refdef.vieworg[2] > ent->origin[2] + 30)
r_refdef.vieworg[2] = ent->origin[2] + 30;
}
/*
==============
V_AddIdle
Idle swaying
==============
*/
void V_AddIdle (void)
{
r_refdef.viewangles[ROLL] += v_idlescale->value * sin(cl.time*v_iroll_cycle->value) * v_iroll_level->value;
r_refdef.viewangles[PITCH] += v_idlescale->value * sin(cl.time*v_ipitch_cycle->value) * v_ipitch_level->value;
r_refdef.viewangles[YAW] += v_idlescale->value * sin(cl.time*v_iyaw_cycle->value) * v_iyaw_level->value;
}
/*
==============
V_CalcViewRoll
Roll is induced by movement and damage
==============
*/
void V_CalcViewRoll (void)
{
float side;
side = V_CalcRoll (cl_entities[cl.viewentity].angles, cl.velocity);
r_refdef.viewangles[ROLL] += side;
if (v_dmg_time > 0)
{
r_refdef.viewangles[ROLL] += v_dmg_time/v_kicktime->value*v_dmg_roll;
r_refdef.viewangles[PITCH] += v_dmg_time/v_kicktime->value*v_dmg_pitch;
v_dmg_time -= host_frametime;
}
if (cl.stats[STAT_HEALTH] <= 0)
{
r_refdef.viewangles[ROLL] = 80; // dead view angle
return;
}
}
/*
==================
V_CalcIntermissionRefdef
==================
*/
void V_CalcIntermissionRefdef (void)
{
entity_t *ent, *view;
float old;
// ent is the player model (visible when out of body)
ent = &cl_entities[cl.viewentity];
// view is the weapon model (only visible from inside body)
view = &cl.viewent;
VectorCopy (ent->origin, r_refdef.vieworg);
VectorCopy (ent->angles, r_refdef.viewangles);
view->model = NULL;
// always idle in intermission
old = v_idlescale->value;
v_idlescale->value = 1;
V_AddIdle ();
v_idlescale->value = old;
}
/*
==================
V_CalcRefdef
==================
*/
void V_CalcRefdef (void)
{
entity_t *ent, *view;
int i;
vec3_t forward, right, up;
vec3_t angles;
float bob;
static float oldz = 0;
V_DriftPitch ();
// ent is the player model (visible when out of body)
ent = &cl_entities[cl.viewentity];
// view is the weapon model (only visible from inside body)
view = &cl.viewent;
// transform the view offset by the model's matrix to get the offset from
// model origin for the view
ent->angles[YAW] = cl.viewangles[YAW]; // the model should face
// the view dir
ent->angles[PITCH] = -cl.viewangles[PITCH]; // the model should face
// the view dir
bob = V_CalcBob ();
// refresh position
VectorCopy (ent->origin, r_refdef.vieworg);
r_refdef.vieworg[2] += cl.viewheight + bob;
// never let it sit exactly on a node line, because a water plane can
// dissapear when viewed with the eye exactly on it.
// the server protocol only specifies to 1/16 pixel, so add 1/32 in each axis
r_refdef.vieworg[0] += 1.0/32;
r_refdef.vieworg[1] += 1.0/32;
r_refdef.vieworg[2] += 1.0/32;
VectorCopy (cl.viewangles, r_refdef.viewangles);
V_CalcViewRoll ();
V_AddIdle ();
// offsets
angles[PITCH] = -ent->angles[PITCH]; // because entity pitches are
// actually backward
angles[YAW] = ent->angles[YAW];
angles[ROLL] = ent->angles[ROLL];
AngleVectors (angles, forward, right, up);
for (i=0 ; i<3 ; i++)
r_refdef.vieworg[i] += scr_ofsx->value*forward[i]
+ scr_ofsy->value*right[i]
+ scr_ofsz->value*up[i];
V_BoundOffsets ();
// set up gun position
VectorCopy (cl.viewangles, view->angles);
CalcGunAngle ();
VectorCopy (ent->origin, view->origin);
view->origin[2] += cl.viewheight;
for (i=0 ; i<3 ; i++)
{
view->origin[i] += forward[i]*bob*0.4;
// view->origin[i] += right[i]*bob*0.4;
// view->origin[i] += up[i]*bob*0.8;
}
view->origin[2] += bob;
// fudge position around to keep amount of weapon visible
// roughly equal with different FOV
#if 0
if (cl.model_precache[cl.stats[STAT_WEAPON]] && strcmp (cl.model_precache[cl.stats[STAT_WEAPON]]->name, "progs/v_shot2.mdl"))
#endif
if (scr_viewsize->value == 110)
view->origin[2] += 1;
else if (scr_viewsize->value == 100)
view->origin[2] += 2;
else if (scr_viewsize->value == 90)
view->origin[2] += 1;
else if (scr_viewsize->value == 80)
view->origin[2] += 0.5;
view->model = cl.model_precache[cl.stats[STAT_WEAPON]];
view->frame = cl.stats[STAT_WEAPONFRAME];
view->colormap = vid.colormap;
// set up the refresh position
VectorAdd (r_refdef.viewangles, cl.punchangle, r_refdef.viewangles);
// smooth out stair step ups
if (cl.onground && ent->origin[2] - oldz > 0)
{
float steptime;
steptime = cl.time - cl.oldtime;
if (steptime < 0)
//FIXME I_Error ("steptime < 0");
steptime = 0;
oldz += steptime * 80;
if (oldz > ent->origin[2])
oldz = ent->origin[2];
if (ent->origin[2] - oldz > 12)
oldz = ent->origin[2] - 12;
r_refdef.vieworg[2] += oldz - ent->origin[2];
view->origin[2] += oldz - ent->origin[2];
}
else
oldz = ent->origin[2];
if (chase_active->value)
Chase_Update ();
}
/*
==================
V_RenderView
The player's clipping box goes from (-16 -16 -24) to (16 16 32) from
the entity origin, so any view position inside that will be valid
==================
*/
extern vrect_t scr_vrect;
void V_RenderView (void)
{
if (con_forcedup)
return;
// don't allow cheats in multiplayer
if (cl.maxclients > 1)
{
Cvar_Set (scr_ofsx, "0");
Cvar_Set (scr_ofsy, "0");
Cvar_Set (scr_ofsz, "0");
}
if (cl.intermission)
{ // intermission / finale rendering
V_CalcIntermissionRefdef ();
}
else
{
if (!cl.paused /* && (sv.maxclients > 1 || key_dest == key_game) */ )
V_CalcRefdef ();
}
R_PushDlights ();
if (lcd_x->value)
{
//
// render two interleaved views
//
int i;
vid.rowbytes <<= 1;
vid.aspect *= 0.5;
r_refdef.viewangles[YAW] -= lcd_yaw->value;
for (i=0 ; i<3 ; i++)
r_refdef.vieworg[i] -= right[i]*lcd_x->value;
R_RenderView ();
vid.buffer += vid.rowbytes>>1;
R_PushDlights ();
r_refdef.viewangles[YAW] += lcd_yaw->value*2;
for (i=0 ; i<3 ; i++)
r_refdef.vieworg[i] += 2*right[i]*lcd_x->value;
R_RenderView ();
vid.buffer -= vid.rowbytes>>1;
r_refdef.vrect.height <<= 1;
vid.rowbytes >>= 1;
vid.aspect *= 2;
}
else
{
R_RenderView ();
}
#ifndef GLQUAKE
if (crosshair->value)
Draw_Character (scr_vrect.x + scr_vrect.width/2 + cl_crossx->value,
scr_vrect.y + scr_vrect.height/2 + cl_crossy->value, '+');
#endif
}
//============================================================================
// 2001-09-18 New cvar system by Maddes (Init) start
/*
=============
V_Init_Cvars
=============
*/
void V_Init_Cvars (void)
{
lcd_x = Cvar_Get ("lcd_x", "0", CVAR_ORIGINAL);
lcd_yaw = Cvar_Get ("lcd_yaw", "0", CVAR_ORIGINAL);
v_centermove = Cvar_Get ("v_centermove", "0.15", CVAR_ORIGINAL);
v_centerspeed = Cvar_Get ("v_centerspeed", "500", CVAR_ORIGINAL);
v_iyaw_cycle = Cvar_Get ("v_iyaw_cycle", "2", CVAR_ORIGINAL);
v_iroll_cycle = Cvar_Get ("v_iroll_cycle", "0.5", CVAR_ORIGINAL);
v_ipitch_cycle = Cvar_Get ("v_ipitch_cycle", "1", CVAR_ORIGINAL);
v_iyaw_level = Cvar_Get ("v_iyaw_level", "0.3", CVAR_ORIGINAL);
v_iroll_level = Cvar_Get ("v_iroll_level", "0.1", CVAR_ORIGINAL);
v_ipitch_level = Cvar_Get ("v_ipitch_level", "0.3", CVAR_ORIGINAL);
v_idlescale = Cvar_Get ("v_idlescale", "0", CVAR_ORIGINAL);
crosshair = Cvar_Get ("crosshair", "0", CVAR_ARCHIVE|CVAR_ORIGINAL);
cl_crossx = Cvar_Get ("cl_crossx", "0", CVAR_ORIGINAL);
cl_crossy = Cvar_Get ("cl_crossy", "0", CVAR_ORIGINAL);
gl_cshiftpercent = Cvar_Get ("gl_cshiftpercent", "100", CVAR_ORIGINAL);
scr_ofsx = Cvar_Get ("scr_ofsx", "0", CVAR_ORIGINAL);
scr_ofsy = Cvar_Get ("scr_ofsy", "0", CVAR_ORIGINAL);
scr_ofsz = Cvar_Get ("scr_ofsz", "0", CVAR_ORIGINAL);
cl_rollspeed = Cvar_Get ("cl_rollspeed", "200", CVAR_ORIGINAL);
cl_rollangle = Cvar_Get ("cl_rollangle", "2.0", CVAR_ORIGINAL);
cl_bob = Cvar_Get ("cl_bob", "0.02", CVAR_ORIGINAL);
cl_bobcycle = Cvar_Get ("cl_bobcycle", "0.6", CVAR_ORIGINAL);
cl_bobup = Cvar_Get ("cl_bobup", "0.5", CVAR_ORIGINAL);
v_kicktime = Cvar_Get ("v_kicktime", "0.5", CVAR_ORIGINAL);
v_kickroll = Cvar_Get ("v_kickroll", "0.6", CVAR_ORIGINAL);
v_kickpitch = Cvar_Get ("v_kickpitch", "0.6", CVAR_ORIGINAL);
BuildGammaTable (1.0); // no gamma yet
v_gamma = Cvar_Get ("gamma", "1", CVAR_ARCHIVE|CVAR_ORIGINAL);
}
// 2001-09-18 New cvar system by Maddes (Init) end
/*
=============
V_Init
=============
*/
void V_Init (void)
{
Cmd_AddCommand ("v_cshift", V_cshift_f);
Cmd_AddCommand ("bf", V_BonusFlash_f);
Cmd_AddCommand ("centerview", V_StartPitchDrift);
// 2001-09-18 New cvar system by Maddes (Init) start
/*
lcd_x = Cvar_Get ("lcd_x", "0", CVAR_ORIGINAL);
lcd_yaw = Cvar_Get ("lcd_yaw", "0", CVAR_ORIGINAL);
v_centermove = Cvar_Get ("v_centermove", "0.15", CVAR_ORIGINAL);
v_centerspeed = Cvar_Get ("v_centerspeed", "500", CVAR_ORIGINAL);
v_iyaw_cycle = Cvar_Get ("v_iyaw_cycle", "2", CVAR_ORIGINAL);
v_iroll_cycle = Cvar_Get ("v_iroll_cycle", "0.5", CVAR_ORIGINAL);
v_ipitch_cycle = Cvar_Get ("v_ipitch_cycle", "1", CVAR_ORIGINAL);
v_iyaw_level = Cvar_Get ("v_iyaw_level", "0.3", CVAR_ORIGINAL);
v_iroll_level = Cvar_Get ("v_iroll_level", "0.1", CVAR_ORIGINAL);
v_ipitch_level = Cvar_Get ("v_ipitch_level", "0.3", CVAR_ORIGINAL);
v_idlescale = Cvar_Get ("v_idlescale", "0", CVAR_ORIGINAL);
crosshair = Cvar_Get ("crosshair", "0", CVAR_ARCHIVE|CVAR_ORIGINAL);
cl_crossx = Cvar_Get ("cl_crossx", "0", CVAR_ORIGINAL);
cl_crossy = Cvar_Get ("cl_crossy", "0", CVAR_ORIGINAL);
gl_cshiftpercent = Cvar_Get ("gl_cshiftpercent", "100", CVAR_ORIGINAL);
scr_ofsx = Cvar_Get ("scr_ofsx", "0", CVAR_ORIGINAL);
scr_ofsy = Cvar_Get ("scr_ofsy", "0", CVAR_ORIGINAL);
scr_ofsz = Cvar_Get ("scr_ofsz", "0", CVAR_ORIGINAL);
cl_rollspeed = Cvar_Get ("cl_rollspeed", "200", CVAR_ORIGINAL);
cl_rollangle = Cvar_Get ("cl_rollangle", "2.0", CVAR_ORIGINAL);
cl_bob = Cvar_Get ("cl_bob", "0.02", CVAR_ORIGINAL);
cl_bobcycle = Cvar_Get ("cl_bobcycle", "0.6", CVAR_ORIGINAL);
cl_bobup = Cvar_Get ("cl_bobup", "0.5", CVAR_ORIGINAL);
v_kicktime = Cvar_Get ("v_kicktime", "0.5", CVAR_ORIGINAL);
v_kickroll = Cvar_Get ("v_kickroll", "0.6", CVAR_ORIGINAL);
v_kickpitch = Cvar_Get ("v_kickpitch", "0.6", CVAR_ORIGINAL);
BuildGammaTable (1.0); // no gamma yet
v_gamma = Cvar_Get ("gamma", "1", CVAR_ARCHIVE|CVAR_ORIGINAL);
*/
// 2001-09-18 New cvar system by Maddes (Init) start
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -