/* =============== CG_CalcViewValues Sets cg.refdef view values =============== */ static int CG_CalcViewValues( void ) { playerState_t *ps; memset( &cg.refdef, 0, sizeof( cg.refdef ) ); // calculate size of 3D view CG_CalcVrect( ); ps = &cg.predictedPlayerState; // intermission view if( ps->pm_type == PM_INTERMISSION || ps->pm_type == PM_FREEZE || ps->pm_type == PM_SPECTATOR ) { 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 ] ); // the bob velocity should't get too fast to avoid jerking if( cg.xyspeed > 300.0f ) cg.xyspeed = 300.0f; VectorCopy( ps->origin, cg.refdef.vieworg ); if( BG_ClassHasAbility( ps->stats[ STAT_CLASS ], SCA_WALLCLIMBER ) ) CG_smoothWWTransitions( ps, ps->viewangles, cg.refdefViewAngles ); else if( BG_ClassHasAbility( ps->stats[ STAT_CLASS ], SCA_WALLJUMPER ) ) CG_smoothWJTransitions( ps, ps->viewangles, cg.refdefViewAngles ); else VectorCopy( ps->viewangles, cg.refdefViewAngles ); //clumsy logic, but it needs to be this way round because the CS propogation //delay screws things up otherwise if( !BG_ClassHasAbility( ps->stats[ STAT_CLASS ], SCA_WALLJUMPER ) ) { if( !( ps->stats[ STAT_STATE ] & SS_WALLCLIMBING ) ) VectorSet( cg.lastNormal, 0.0f, 0.0f, 1.0f ); } // 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; } //shut off the poison cloud effect if it's still on the go if( cg.snap->ps.stats[ STAT_HEALTH ] <= 0 ) { if( CG_IsParticleSystemValid( &cg.poisonCloudPS ) ) CG_DestroyParticleSystem( &cg.poisonCloudPS ); } else cg.wasDeadLastFrame = qfalse; 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; //draw the surface normal looking at if( cg_drawSurfNormal.integer ) CG_DrawSurfNormal( ); // field of view return CG_CalcFov( ); }
/* =============== CG_CalcViewValues Sets cg.refdef view values =============== */ static int CG_CalcViewValues( void ) { playerState_t *ps; memset( &cg.refdef, 0, sizeof( cg.refdef ) ); // calculate size of 3D view CG_CalcVrect(); ps = &cg.predictedPlayerState; CG_CalcColorGradingForPoint( ps->origin ); CG_AddColorGradingEffects( ps ); CG_AddReverbEffects( ps->origin ); // intermission view if ( ps->pm_type == PM_INTERMISSION || ps->pm_type == PM_FREEZE || ps->pm_type == PM_SPECTATOR ) { 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 ] ); // to avoid jerking, the bob velocity shouldn't be too high if ( cg.xyspeed > 300.0f ) { cg.xyspeed = 300.0f; } VectorCopy( ps->origin, cg.refdef.vieworg ); if ( BG_ClassHasAbility( ps->stats[ STAT_CLASS ], SCA_WALLCLIMBER ) ) { CG_smoothWWTransitions( ps, ps->viewangles, cg.refdefViewAngles ); } else if ( BG_ClassHasAbility( ps->stats[ STAT_CLASS ], SCA_WALLJUMPER ) ) { CG_smoothWJTransitions( ps, ps->viewangles, cg.refdefViewAngles ); } else { VectorCopy( ps->viewangles, cg.refdefViewAngles ); } //clumsy logic, but it needs to be this way around because the CS propagation //delay screws things up otherwise if ( !BG_ClassHasAbility( ps->stats[ STAT_CLASS ], SCA_WALLJUMPER ) ) { if ( !( ps->stats[ STAT_STATE ] & SS_WALLCLIMBING ) ) { VectorSet( cg.lastNormal, 0.0f, 0.0f, 1.0f ); } } // 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; } } //shut off the poison cloud effect if it's still on the go if ( cg.snap->ps.stats[ STAT_HEALTH ] > 0 ) { cg.wasDeadLastFrame = qfalse; } if ( cg.renderingThirdPerson ) { // back away from character CG_OffsetThirdPersonView(); } else { float speed; // offset for local bobbing and kicks CG_OffsetFirstPersonView(); // Compute motion blur vector speed = VectorNormalize2( cg.snap->ps.velocity, cg.refdef.blurVec ); speed = (speed - cg_motionblurMinSpeed.value); if( speed < 0.0f ) speed = 0.0f; VectorScale( cg.refdef.blurVec, speed * cg_motionblur.value, cg.refdef.blurVec ); } // position eye relative to origin AnglesToAxis( cg.refdefViewAngles, cg.refdef.viewaxis ); if ( cg.hyperspace ) { cg.refdef.rdflags |= RDF_NOWORLDMODEL | RDF_HYPERSPACE; } //draw the surface normal looking at if ( cg_drawSurfNormal.integer ) { CG_DrawSurfNormal(); } // field of view return CG_CalcFov(); }