📄 cg_view.c
字号:
#endif
}
//======================================================================
void CG_ZoomDown_f( void ) {
if ( cg.zoomed ) {
return;
}
cg.zoomed = qtrue;
cg.zoomTime = cg.time;
}
void CG_ZoomUp_f( void ) {
if ( !cg.zoomed ) {
return;
}
cg.zoomed = qfalse;
cg.zoomTime = cg.time;
}
/*
====================
CG_CalcFov
Fixed fov at intermissions, otherwise account for fov variable and zooms.
====================
*/
#define WAVE_AMPLITUDE 1
#define WAVE_FREQUENCY 0.4
static int CG_CalcFov( void ) {
float x;
float phase;
float v;
int contents;
float fov_x, fov_y;
float zoomFov;
float f;
int inwater;
if ( cg.predictedPlayerState.pm_type == PM_INTERMISSION ) {
// if in intermission, use a fixed value
fov_x = 90;
} else {
// user selectable
if ( cgs.dmflags & DF_FIXED_FOV ) {
// dmflag to prevent wide fov for all clients
fov_x = 90;
} else {
fov_x = cg_fov.value;
if ( fov_x < 1 ) {
fov_x = 1;
} else if ( fov_x > 160 ) {
fov_x = 160;
}
}
// account for zooms
zoomFov = cg_zoomFov.value;
if ( zoomFov < 1 ) {
zoomFov = 1;
} else if ( zoomFov > 160 ) {
zoomFov = 160;
}
if ( cg.zoomed ) {
f = ( cg.time - cg.zoomTime ) / (float)ZOOM_TIME;
if ( f > 1.0 ) {
fov_x = zoomFov;
} else {
fov_x = fov_x + f * ( zoomFov - fov_x );
}
} else {
f = ( cg.time - cg.zoomTime ) / (float)ZOOM_TIME;
if ( f > 1.0 ) {
fov_x = fov_x;
} else {
fov_x = zoomFov + f * ( fov_x - zoomFov );
}
}
}
x = cg.refdef.width / tan( fov_x / 360 * M_PI );
fov_y = atan2( cg.refdef.height, x );
fov_y = fov_y * 360 / M_PI;
// warp if underwater
contents = CG_PointContents( cg.refdef.vieworg, -1 );
if ( contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ){
phase = cg.time / 1000.0 * WAVE_FREQUENCY * M_PI * 2;
v = WAVE_AMPLITUDE * sin( phase );
fov_x += v;
fov_y -= v;
inwater = qtrue;
}
else {
inwater = qfalse;
}
// set it
cg.refdef.fov_x = fov_x;
cg.refdef.fov_y = fov_y;
if ( !cg.zoomed ) {
cg.zoomSensitivity = 1;
} else {
cg.zoomSensitivity = cg.refdef.fov_y / 75.0;
}
return inwater;
}
/*
===============
CG_DamageBlendBlob
===============
*/
static void CG_DamageBlendBlob( void ) {
int t;
int maxTime;
refEntity_t ent;
if ( !cg.damageValue ) {
return;
}
//if (cg.cameraMode) {
// return;
//}
// ragePro systems can't fade blends, so don't obscure the screen
if ( cgs.glconfig.hardwareType == GLHW_RAGEPRO ) {
return;
}
maxTime = DAMAGE_TIME;
t = cg.time - cg.damageTime;
if ( t <= 0 || t >= maxTime ) {
return;
}
memset( &ent, 0, sizeof( ent ) );
ent.reType = RT_SPRITE;
ent.renderfx = RF_FIRST_PERSON;
VectorMA( cg.refdef.vieworg, 8, cg.refdef.viewaxis[0], ent.origin );
VectorMA( ent.origin, cg.damageX * -8, cg.refdef.viewaxis[1], ent.origin );
VectorMA( ent.origin, cg.damageY * 8, cg.refdef.viewaxis[2], ent.origin );
ent.radius = cg.damageValue * 3;
ent.customShader = cgs.media.viewBloodShader;
ent.shaderRGBA[0] = 255;
ent.shaderRGBA[1] = 255;
ent.shaderRGBA[2] = 255;
ent.shaderRGBA[3] = 200 * ( 1.0 - ((float)t / maxTime) );
trap_R_AddRefEntityToScene( &ent );
}
/*
===============
CG_CalcViewValues
Sets cg.refdef view values
===============
*/
static int CG_CalcViewValues( void ) {
playerState_t *ps;
memset( &cg.refdef, 0, sizeof( cg.refdef ) );
// strings for in game rendering
// Q_strncpyz( cg.refdef.text[0], "Park Ranger", sizeof(cg.refdef.text[0]) );
// Q_strncpyz( cg.refdef.text[1], "19", sizeof(cg.refdef.text[1]) );
// calculate size of 3D view
CG_CalcVrect();
ps = &cg.predictedPlayerState;
/*
if (cg.cameraMode) {
vec3_t origin, angles;
if (trap_getCameraInfo(cg.time, &origin, &angles)) {
VectorCopy(origin, cg.refdef.vieworg);
angles[ROLL] = 0;
VectorCopy(angles, cg.refdefViewAngles);
AnglesToAxis( cg.refdefViewAngles, cg.refdef.viewaxis );
return CG_CalcFov();
} else {
cg.cameraMode = qfalse;
}
}
*/
// intermission view
if ( ps->pm_type == PM_INTERMISSION ) {
VectorCopy( ps->origin, cg.refdef.vieworg );
VectorCopy( ps->viewangles, cg.refdefViewAngles );
AnglesToAxis( cg.refdefViewAngles, cg.refdef.viewaxis );
return CG_CalcFov();
}
cg.bobcycle = ( ps->bobCycle & 128 ) >> 7;
cg.bobfracsin = fabs( sin( ( ps->bobCycle & 127 ) / 127.0 * M_PI ) );
cg.xyspeed = sqrt( ps->velocity[0] * ps->velocity[0] +
ps->velocity[1] * ps->velocity[1] );
VectorCopy( ps->origin, cg.refdef.vieworg );
VectorCopy( ps->viewangles, cg.refdefViewAngles );
if (cg_cameraOrbit.integer) {
if (cg.time > cg.nextOrbitTime) {
cg.nextOrbitTime = cg.time + cg_cameraOrbitDelay.integer;
cg_thirdPersonAngle.value += cg_cameraOrbit.value;
}
}
// add error decay
if ( cg_errorDecay.value > 0 ) {
int t;
float f;
t = cg.time - cg.predictedErrorTime;
f = ( cg_errorDecay.value - t ) / cg_errorDecay.value;
if ( f > 0 && f < 1 ) {
VectorMA( cg.refdef.vieworg, f, cg.predictedError, cg.refdef.vieworg );
} else {
cg.predictedErrorTime = 0;
}
}
if ( cg.renderingThirdPerson ) {
// back away from character
CG_OffsetThirdPersonView();
} else {
// offset for local bobbing and kicks
CG_OffsetFirstPersonView();
}
// position eye reletive to origin
AnglesToAxis( cg.refdefViewAngles, cg.refdef.viewaxis );
if ( cg.hyperspace ) {
cg.refdef.rdflags |= RDF_NOWORLDMODEL | RDF_HYPERSPACE;
}
// field of view
return CG_CalcFov();
}
/*
=====================
CG_PowerupTimerSounds
=====================
*/
static void CG_PowerupTimerSounds( void ) {
int i;
int t;
// powerup timers going away
for ( i = 0 ; i < MAX_POWERUPS ; i++ ) {
t = cg.snap->ps.powerups[i];
if ( t <= cg.time ) {
continue;
}
if ( t - cg.time >= POWERUP_BLINKS * POWERUP_BLINK_TIME ) {
continue;
}
if ( ( t - cg.time ) / POWERUP_BLINK_TIME != ( t - cg.oldTime ) / POWERUP_BLINK_TIME ) {
trap_S_StartSound( NULL, cg.snap->ps.clientNum, CHAN_ITEM, cgs.media.wearOffSound );
}
}
}
/*
=====================
CG_AddBufferedSound
=====================
*/
void CG_AddBufferedSound( sfxHandle_t sfx ) {
if ( !sfx )
return;
cg.soundBuffer[cg.soundBufferIn] = sfx;
cg.soundBufferIn = (cg.soundBufferIn + 1) % MAX_SOUNDBUFFER;
if (cg.soundBufferIn == cg.soundBufferOut) {
cg.soundBufferOut++;
}
}
/*
=====================
CG_PlayBufferedSounds
=====================
*/
static void CG_PlayBufferedSounds( void ) {
if ( cg.soundTime < cg.time ) {
if (cg.soundBufferOut != cg.soundBufferIn && cg.soundBuffer[cg.soundBufferOut]) {
trap_S_StartLocalSound(cg.soundBuffer[cg.soundBufferOut], CHAN_ANNOUNCER);
cg.soundBuffer[cg.soundBufferOut] = 0;
cg.soundBufferOut = (cg.soundBufferOut + 1) % MAX_SOUNDBUFFER;
cg.soundTime = cg.time + 750;
}
}
}
//=========================================================================
/*
=================
CG_DrawActiveFrame
Generates and draws a game scene and status information at the given time.
=================
*/
void CG_DrawActiveFrame( int serverTime, stereoFrame_t stereoView, qboolean demoPlayback ) {
int inwater;
cg.time = serverTime;
cg.demoPlayback = demoPlayback;
// update cvars
CG_UpdateCvars();
// if we are only updating the screen as a loading
// pacifier, don't even try to read snapshots
if ( cg.infoScreenText[0] != 0 ) {
CG_DrawInformation();
return;
}
// any looped sounds will be respecified as entities
// are added to the render list
trap_S_ClearLoopingSounds(qfalse);
// clear all the render lists
trap_R_ClearScene();
// set up cg.snap and possibly cg.nextSnap
CG_ProcessSnapshots();
// if we haven't received any snapshots yet, all
// we can draw is the information screen
if ( !cg.snap || ( cg.snap->snapFlags & SNAPFLAG_NOT_ACTIVE ) ) {
CG_DrawInformation();
return;
}
// let the client system know what our weapon and zoom settings are
trap_SetUserCmdValue( cg.weaponSelect, cg.zoomSensitivity );
// this counter will be bumped for every valid scene we generate
cg.clientFrame++;
// update cg.predictedPlayerState
CG_PredictPlayerState();
// decide on third person view
cg.renderingThirdPerson = cg_thirdPerson.integer || (cg.snap->ps.stats[STAT_HEALTH] <= 0);
// build cg.refdef
inwater = CG_CalcViewValues();
// first person blend blobs, done after AnglesToAxis
if ( !cg.renderingThirdPerson ) {
CG_DamageBlendBlob();
}
// build the render lists
if ( !cg.hyperspace ) {
CG_AddPacketEntities(); // adter calcViewValues, so predicted player state is correct
CG_AddMarks();
CG_AddParticles ();
CG_AddLocalEntities();
}
CG_AddViewWeapon( &cg.predictedPlayerState );
// add buffered sounds
CG_PlayBufferedSounds();
// play buffered voice chats
CG_PlayBufferedVoiceChats();
// finish up the rest of the refdef
if ( cg.testModelEntity.hModel ) {
CG_AddTestModel();
}
cg.refdef.time = cg.time;
memcpy( cg.refdef.areamask, cg.snap->areamask, sizeof( cg.refdef.areamask ) );
// warning sounds when powerup is wearing off
CG_PowerupTimerSounds();
// update audio positions
trap_S_Respatialize( cg.snap->ps.clientNum, cg.refdef.vieworg, cg.refdef.viewaxis, inwater );
// make sure the lagometerSample and frame timing isn't done twice when in stereo
if ( stereoView != STEREO_RIGHT ) {
cg.frametime = cg.time - cg.oldTime;
if ( cg.frametime < 0 ) {
cg.frametime = 0;
}
cg.oldTime = cg.time;
CG_AddLagometerFrameInfo();
}
if (cg_timescale.value != cg_timescaleFadeEnd.value) {
if (cg_timescale.value < cg_timescaleFadeEnd.value) {
cg_timescale.value += cg_timescaleFadeSpeed.value * ((float)cg.frametime) / 1000;
if (cg_timescale.value > cg_timescaleFadeEnd.value)
cg_timescale.value = cg_timescaleFadeEnd.value;
}
else {
cg_timescale.value -= cg_timescaleFadeSpeed.value * ((float)cg.frametime) / 1000;
if (cg_timescale.value < cg_timescaleFadeEnd.value)
cg_timescale.value = cg_timescaleFadeEnd.value;
}
if (cg_timescaleFadeSpeed.value) {
trap_Cvar_Set("timescale", va("%f", cg_timescale.value));
}
}
// actually issue the rendering calls
CG_DrawActive( stereoView );
if ( cg_stats.integer ) {
CG_Printf( "cg.clientFrame:%i\n", cg.clientFrame );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -