934 lines · 20.3 KB · C
RawDownload
// view.c -- player eye positioning #include <stdlib.h>#include <math.h>#include "quakedef.h"#include "r_shared.h"#include "r_local.h" /* 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 ofentities sent from the server may not include everything in the pvs, especiallywhen crossing a water boudnary. */ cvar_t lcd_x = {"lcd_x","0"};cvar_t lcd_yaw = {"lcd_yaw","0"}; cvar_t scr_ofsx = {"scr_ofsx","0", false};cvar_t scr_ofsy = {"scr_ofsy","0", false};cvar_t scr_ofsz = {"scr_ofsz","0", false}; cvar_t cl_rollspeed = {"cl_rollspeed", "200"};cvar_t cl_rollangle = {"cl_rollangle", "2.0"}; cvar_t cl_bob = {"cl_bob","0.02", false};cvar_t cl_bobcycle = {"cl_bobcycle","0.6", false};cvar_t cl_bobup = {"cl_bobup","0.5", false}; cvar_t v_kicktime = {"v_kicktime", "0.5", false};cvar_t v_kickroll = {"v_kickroll", "0.6", false};cvar_t v_kickpitch = {"v_kickpitch", "0.6", false}; cvar_t v_iyaw_cycle = {"v_iyaw_cycle", "2", false};cvar_t v_iroll_cycle = {"v_iroll_cycle", "0.5", false};cvar_t v_ipitch_cycle = {"v_ipitch_cycle", "1", false};cvar_t v_iyaw_level = {"v_iyaw_level", "0.3", false};cvar_t v_iroll_level = {"v_iroll_level", "0.1", false};cvar_t v_ipitch_level = {"v_ipitch_level", "0.3", false}; cvar_t v_idlescale = {"v_idlescale", "0", false}; cvar_t crosshair = {"crosshair", "0", true};cvar_t cl_crossx = {"cl_crossx", "0", false};cvar_t cl_crossy = {"cl_crossy", "0", false}; cvar_t gl_cshiftpercent = {"gl_cshiftpercent", "100", false}; float v_dmg_time, v_dmg_roll, v_dmg_pitch; extern int in_forward, in_forward2, in_back; /*===============V_CalcRoll Used by view and sv_user===============*/vec3_t forward, right, up; float V_CalcRoll (vec3_t angles, vec3_t velocity){	float sign;	float side;	float value; 	AngleVectors (angles, forward, right, up);	side = DotProduct (velocity, right);	sign = side < 0 ? -1 : 1;	side = fabs(side); 	value = cl_rollangle.value;// if (cl.inwater)// value *= 6; 	if (side < cl_rollspeed.value)		side = side * value / cl_rollspeed.value;	else		side = value; 	return side*sign; } /*===============V_CalcBob ===============*/float V_CalcBob (void){	float bob;	float cycle; 	cycle = cl.time - (int)(cl.time/cl_bobcycle.value)*cl_bobcycle.value;	cycle /= cl_bobcycle.value;	if (cycle < cl_bobup.value)		cycle = M_PI * cycle / cl_bobup.value;	else		cycle = M_PI + M_PI*(cycle-cl_bobup.value)/(1.0 - cl_bobup.value); // bob is proportional to velocity in the xy plane// (don't count Z, or jumping messes it up) 	bob = sqrt(cl.velocity[0]*cl.velocity[0] + cl.velocity[1]*cl.velocity[1]) * cl_bob.value;//Con_Printf ("speed: %5.1f\n", Length(cl.velocity));	bob = bob*0.3 + bob*0.7*sin(cycle);	if (bob > 4)		bob = 4;	else if (bob < -7)		bob = -7;	return bob; } //============================================================================= cvar_t v_centermove = {"v_centermove", "0.15", false};cvar_t v_centerspeed = {"v_centerspeed","500"}; void V_StartPitchDrift (void){#if 1	if (cl.laststop == cl.time)	{		return; // something else is keeping it from drifting	}#endif	if (cl.nodrift || !cl.pitchvel)	{		cl.pitchvel = v_centerspeed.value;		cl.nodrift = false;		cl.driftmove = 0;	}} void V_StopPitchDrift (void){	cl.laststop = cl.time;	cl.nodrift = true;	cl.pitchvel = 0;} /*===============V_DriftPitch Moves the client pitch angle towards cl.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. Drifting is enabled when the center view key is hit, mlook is released andlookspring is non 0, or when===============*/void V_DriftPitch (void){	float delta, move; 	if (noclip_anglehack || !cl.onground || cls.demoplayback )	{		cl.driftmove = 0;		cl.pitchvel = 0;		return;	} // don't count small mouse motion	if (cl.nodrift)	{		if ( fabs(cl.cmd.forwardmove) < cl_forwardspeed.value)			cl.driftmove = 0;		else			cl.driftmove += host_frametime; 		if ( cl.driftmove > v_centermove.value)		{			V_StartPitchDrift ();		}		return;	} 	delta = cl.idealpitch - cl.viewangles[PITCH]; 	if (!delta)	{		cl.pitchvel = 0;		return;	} 	move = host_frametime * cl.pitchvel;	cl.pitchvel += host_frametime * v_centerspeed.value; //Con_Printf ("move: %f (%f)\n", move, host_frametime); 	if (delta > 0)	{		if (move > delta)		{			cl.pitchvel = 0;			move = delta;		}		cl.viewangles[PITCH] += move;	}	else if (delta < 0)	{		if (move > -delta)		{			cl.pitchvel = 0;			move = -delta;		}		cl.viewangles[PITCH] -= move;	}} /*============================================================================== 						PALETTE FLASHES ==============================================================================*/ cshift_t cshift_empty = { {130,80,50}, 0 };cshift_t cshift_water = { {130,80,50}, 128 };cshift_t cshift_slime = { {0,25,5}, 150 };cshift_t cshift_lava = { {255,80,0}, 150 }; cvar_t v_gamma = {"gamma", "1", true}; uint8_t gammatable[256]; // palette is sent through this void BuildGammaTable (float g){	int i, inf; 	if (g == 1.0)	{		for (i=0 ; i<256 ; i++)			gammatable[i] = i;		return;	} 	for (i=0 ; i<256 ; i++)	{		inf = 255 * pow ( (i+0.5)/255.5 , g ) + 0.5;		if (inf < 0)			inf = 0;		if (inf > 255)			inf = 255;		gammatable[i] = inf;	}} /*=================V_CheckGamma=================*/bool V_CheckGamma (void){	static float oldgammavalue; 	if (v_gamma.value == oldgammavalue)		return false;	oldgammavalue = v_gamma.value; 	BuildGammaTable (v_gamma.value);	vid.recalc_refdef = 1; // force a surface cache flush 	return true;} /*===============V_ParseDamage===============*/void V_ParseDamage (void){	int armor, blood;	vec3_t from;	int i;	vec3_t forward, right, up;	entity_t *ent;	float side;	float count; 	armor = MSG_ReadByte ();	blood = MSG_ReadByte ();	for (i=0 ; i<3 ; i++)		from[i] = MSG_ReadCoord (); 	count = blood*0.5 + armor*0.5;	if (count < 10)		count = 10; 	cl.faceanimtime = cl.time + 0.2; // but sbar face into pain frame 	cl.cshifts[CSHIFT_DAMAGE].percent += 3*count;	if (cl.cshifts[CSHIFT_DAMAGE].percent < 0)		cl.cshifts[CSHIFT_DAMAGE].percent = 0;	if (cl.cshifts[CSHIFT_DAMAGE].percent > 150)		cl.cshifts[CSHIFT_DAMAGE].percent = 150; 	if (armor > blood)	{		cl.cshifts[CSHIFT_DAMAGE].destcolor[0] = 200;		cl.cshifts[CSHIFT_DAMAGE].destcolor[1] = 100;		cl.cshifts[CSHIFT_DAMAGE].destcolor[2] = 100;	}	else if (armor)	{		cl.cshifts[CSHIFT_DAMAGE].destcolor[0] = 220;		cl.cshifts[CSHIFT_DAMAGE].destcolor[1] = 50;		cl.cshifts[CSHIFT_DAMAGE].destcolor[2] = 50;	}	else	{		cl.cshifts[CSHIFT_DAMAGE].destcolor[0] = 255;		cl.cshifts[CSHIFT_DAMAGE].destcolor[1] = 0;		cl.cshifts[CSHIFT_DAMAGE].destcolor[2] = 0;	} //// calculate view angle kicks//	ent = &cl_entities[cl.viewentity]; 	VectorSubtract (from, ent->origin, from);	VectorNormalize (from); 	AngleVectors (ent->angles, forward, right, up); 	side = DotProduct (from, right);	v_dmg_roll = count*side*v_kickroll.value; 	side = DotProduct (from, forward);	v_dmg_pitch = count*side*v_kickpitch.value; 	v_dmg_time = v_kicktime.value;} /*==================V_cshift_f==================*/void V_cshift_f (void){	cshift_empty.destcolor[0] = strtol(Cmd_Argv(1), NULL, 0);	cshift_empty.destcolor[1] = strtol(Cmd_Argv(2), NULL, 0);	cshift_empty.destcolor[2] = strtol(Cmd_Argv(3), NULL, 0);	cshift_empty.percent = strtol(Cmd_Argv(4), NULL, 0);} /*==================V_BonusFlash_f When you run over an item, the server sends this command==================*/void V_BonusFlash_f (void){	cl.cshifts[CSHIFT_BONUS].destcolor[0] = 215;	cl.cshifts[CSHIFT_BONUS].destcolor[1] = 186;	cl.cshifts[CSHIFT_BONUS].destcolor[2] = 69;	cl.cshifts[CSHIFT_BONUS].percent = 50;} /*=============V_SetContentsColor Underwater, lava, etc each has a color shift=============*/void V_SetContentsColor (int contents){	switch (contents)	{	case CONTENTS_EMPTY:	case CONTENTS_SOLID:		cl.cshifts[CSHIFT_CONTENTS] = cshift_empty;		break;	case CONTENTS_LAVA:		cl.cshifts[CSHIFT_CONTENTS] = cshift_lava;		break;	case CONTENTS_SLIME:		cl.cshifts[CSHIFT_CONTENTS] = cshift_slime;		break;	default:		cl.cshifts[CSHIFT_CONTENTS] = cshift_water;	}} /*=============V_CalcPowerupCshift=============*/void V_CalcPowerupCshift (void){	if (cl.items & IT_QUAD)	{		cl.cshifts[CSHIFT_POWERUP].destcolor[0] = 0;		cl.cshifts[CSHIFT_POWERUP].destcolor[1] = 0;		cl.cshifts[CSHIFT_POWERUP].destcolor[2] = 255;		cl.cshifts[CSHIFT_POWERUP].percent = 30;	}	else if (cl.items & IT_SUIT)	{		cl.cshifts[CSHIFT_POWERUP].destcolor[0] = 0;		cl.cshifts[CSHIFT_POWERUP].destcolor[1] = 255;		cl.cshifts[CSHIFT_POWERUP].destcolor[2] = 0;		cl.cshifts[CSHIFT_POWERUP].percent = 20;	}	else if (cl.items & IT_INVISIBILITY)	{		cl.cshifts[CSHIFT_POWERUP].destcolor[0] = 100;		cl.cshifts[CSHIFT_POWERUP].destcolor[1] = 100;		cl.cshifts[CSHIFT_POWERUP].destcolor[2] = 100;		cl.cshifts[CSHIFT_POWERUP].percent = 100;	}	else if (cl.items & IT_INVULNERABILITY)	{		cl.cshifts[CSHIFT_POWERUP].destcolor[0] = 255;		cl.cshifts[CSHIFT_POWERUP].destcolor[1] = 255;		cl.cshifts[CSHIFT_POWERUP].destcolor[2] = 0;		cl.cshifts[CSHIFT_POWERUP].percent = 30;	}	else		cl.cshifts[CSHIFT_POWERUP].percent = 0;} /*=============V_UpdatePalette=============*/void V_UpdatePalette (void){	int i, j;	bool new;	uint8_t *basepal, *newpal;	uint8_t pal[768];	int r,g,b;	bool 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;

Lines 1–500 of 934.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t