void CSDKPlayerShared::RampSlowAimIn(float flGoal)
{
	if (flGoal > 0)
		m_flSlowAimIn = Approach(flGoal, m_flSlowAimIn, da_slowaimin_speedin.GetFloat()*gpGlobals->frametime);
	else
		m_flSlowAimIn = Approach(flGoal, m_flSlowAimIn, da_slowaimin_speedout.GetFloat()*gpGlobals->frametime);
}
IMotionEvent::simresult_e CGrabController::Simulate( IPhysicsMotionController *pController, IPhysicsObject *pObject, float deltaTime, Vector &linear, AngularImpulse &angular )
{
	game_shadowcontrol_params_t shadowParams = m_shadow;
	if ( InContactWithHeavyObject( pObject, GetLoadWeight() ) )
	{
		m_contactAmount = Approach( 0.1f, m_contactAmount, deltaTime*2.0f );
	}
	else
	{
		m_contactAmount = Approach( 1.0f, m_contactAmount, deltaTime*2.0f );
	}
	shadowParams.maxAngular = m_shadow.maxAngular * m_contactAmount * m_contactAmount * m_contactAmount;
	m_timeToArrive = pObject->ComputeShadowControl( shadowParams, m_timeToArrive, deltaTime );
	
	// Slide along the current contact points to fix bouncing problems
	Vector velocity;
	AngularImpulse angVel;
	pObject->GetVelocity( &velocity, &angVel );
	PhysComputeSlideDirection( pObject, velocity, angVel, &velocity, &angVel, GetLoadWeight() );
	pObject->SetVelocityInstantaneous( &velocity, NULL );

	linear.Init();
	angular.Init();
	m_errorTime += deltaTime;

	return SIM_LOCAL_ACCELERATION;
}
//-----------------------------------------------------------------------------
// Purpose: only called for local player
//-----------------------------------------------------------------------------
void C_TFWeaponBuilder::Redraw()
{
	if ( m_iValidBuildPoseParam >= 0 )
	{
		CTFPlayer *pOwner = ToTFPlayer( GetOwner() );
		if ( !pOwner )
			return;

		// Assuming here that our model is the same as our viewmodel's model!
		CBaseViewModel *pViewModel = pOwner->GetViewModel(0);

		if ( pViewModel )
		{
			float flPoseParamValue = pViewModel->GetPoseParameter( m_iValidBuildPoseParam );

			C_BaseObject *pObj = m_hObjectBeingBuilt.Get();

			if ( pObj && pObj->WasLastPlacementPosValid() )
			{
				// pose param approach 1.0
				flPoseParamValue = Approach( 1.0, flPoseParamValue, 3.0 * gpGlobals->frametime );
			}
			else
			{
				// pose param approach 0.0
				flPoseParamValue = Approach( 0.0, flPoseParamValue, 1.5 * gpGlobals->frametime );
			}

			pViewModel->SetPoseParameter( m_iValidBuildPoseParam, flPoseParamValue );
		}
	}

	BaseClass::Redraw();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CASWInput::CalculateCameraShift( C_ASW_Player *pPlayer, float flDeltaX, float flDeltaY, float &flShiftX, float &flShiftY )
{
	// Init.
	flShiftX = 0.0f;
	flShiftY = 0.0f;

	if ( !asw_cam_marine_shift_enable.GetBool() )
		return;

	if ( m_bCameraFixed || Holdout_Resupply_Frame::HasResupplyFrameOpen() || g_asw_iPlayerListOpen > 0 || ( pPlayer && pPlayer->GetSpectatingMarine() ) )
	{
		m_fShiftFraction = Approach( 0.0f, m_fShiftFraction, gpGlobals->frametime );
	}
	else
	{
		m_fShiftFraction = Approach( 1.0f, m_fShiftFraction, gpGlobals->frametime );
	}

	if ( ASWGameRules() )
	{
		m_fShiftFraction = m_fShiftFraction * ( 1.0f - ASWGameRules()->GetMarineDeathCamInterp() );
	}

	flShiftX = flDeltaX * asw_cam_marine_shift_maxx.GetFloat() * m_fShiftFraction;
	float camshifty = (flDeltaY < 0) ? asw_cam_marine_shift_maxy.GetFloat() : asw_cam_marine_shift_maxy_south.GetFloat();
	flShiftY = flDeltaY * camshifty * m_fShiftFraction;


	return;

	// Calculate the shift, spherically, based on the cursor distance from the player.
	float flDistance = FastSqrt( flDeltaX * flDeltaX + flDeltaY * flDeltaY );
	if ( flDistance > asw_cam_marine_sphere_min.GetFloat() )
	{
		flDistance -= asw_cam_marine_sphere_min.GetFloat();

		float flRatio = 1.0f;
		if ( m_flCurrentCameraDist < asw_cam_marine_dist.GetFloat() )
		{
			flRatio = ( m_flCurrentCameraDist / asw_cam_marine_dist.GetFloat() ) * 0.8f;
		}

		float flTemp = flDistance / ( asw_cam_marine_sphere_max.GetFloat() * flRatio );
		flTemp = clamp( flTemp, 0.0f, 1.0f );

		float flAngle = atan2( (float)flDeltaY, (float)flDeltaX );
		flShiftX = cos( flAngle ) * flTemp * ( asw_cam_marine_shift_maxx.GetFloat() * flRatio );
		if ( flDeltaY < 0 )
		{
			flShiftY = sin( flAngle ) * flTemp * ( asw_cam_marine_shift_maxy.GetFloat() * flRatio );
		}
		else
		{
			flShiftY = sin( flAngle ) * flTemp * ( asw_cam_marine_shift_maxy_south.GetFloat() * flRatio );
		}
	}
}
void CDAViewRender::PerformSlowMoEffect( const CViewSetup &view )
{
	C_DAPlayer *pPlayer = C_DAPlayer::GetLocalOrSpectatedPlayer();

	if ( !pPlayer )
		return;

	if (!da_postprocess_shaders.GetBool())
		return;

	if (!pPlayer->IsAlive())
		m_flStyleLerp = 0;

	ConVarRef da_postprocess_slowmo("da_postprocess_slowmo");
	ConVarRef da_postprocess_deathcam("da_postprocess_deathcam");
	ConVarRef da_postprocess_skill("da_postprocess_skill");
	ConVarRef da_postprocess_vr("da_postprocess_vr");

	da_postprocess_vr.SetValue(UseVR());

	if (pPlayer->IsStyleSkillActive())
		m_flStyleLerp = Approach(1, m_flStyleLerp, gpGlobals->frametime*2);
	else
		m_flStyleLerp = Approach(0, m_flStyleLerp, gpGlobals->frametime);

	bool bShowPostProcess = false;
	if (pPlayer->GetSlowMoMultiplier() < 1)
		bShowPostProcess = true;
	else if (m_flStyleLerp)
		bShowPostProcess = true;
	else if (!pPlayer->IsAlive() && pPlayer->GetObserverMode() == OBS_MODE_FREEZECAM)
		bShowPostProcess = true;
	else if (da_postprocess_compare.GetInt() || da_postprocess_slowmo.GetInt())
		bShowPostProcess = true;

	if (pPlayer->IsAlive())
		da_postprocess_deathcam.SetValue(false);
	else
		da_postprocess_deathcam.SetValue(true);

	da_postprocess_skill.SetValue(m_flStyleLerp);

	if (bShowPostProcess)
	{
		IMaterial *pMaterial = materials->FindMaterial( "shaders/slowmo", TEXTURE_GROUP_CLIENT_EFFECTS, true );

		if ( !IsErrorMaterial(pMaterial) )
		{
			if (da_postprocess_compare.GetInt() == 1)
				DrawScreenEffectMaterial( pMaterial, view.x, view.y, view.width/2, view.height );
			else
				DrawScreenEffectMaterial( pMaterial, view.x, view.y, view.width, view.height );
		}
	}
}
void ClientModeSDK::OnColorCorrectionWeightsReset( void )
{
	C_ColorCorrection *pNewColorCorrection = NULL;
	C_ColorCorrection *pOldColorCorrection = m_pCurrentColorCorrection;

	C_HL2WarsPlayer *pPlayer = C_HL2WarsPlayer::GetLocalHL2WarsPlayer();
	if ( pPlayer )
	{
		pNewColorCorrection = pPlayer->GetActiveColorCorrection();
	}

#if 0

	if ( m_CCFailedHandle != INVALID_CLIENT_CCHANDLE && ASWGameRules() )
	{
		m_fFailedCCWeight = Approach( TechMarineFailPanel::s_pTechPanel ? 1.0f : 0.0f, m_fFailedCCWeight, gpGlobals->frametime * ( 1.0f / FAILED_CC_FADE_TIME ) );
		g_pColorCorrectionMgr->SetColorCorrectionWeight( m_CCFailedHandle, m_fFailedCCWeight );

		// If the mission was failed due to a dead tech, disable the environmental color correction in favor of the mission failed color correction
		if ( m_fFailedCCWeight != 0.0f && m_pCurrentColorCorrection )
		{
			m_pCurrentColorCorrection->EnableOnClient( false );
			m_pCurrentColorCorrection = NULL;
		}
	}

	if ( m_CCInfestedHandle != INVALID_CLIENT_CCHANDLE && ASWGameRules() )
	{
		C_ASW_Marine *pMarine = C_ASW_Marine::GetLocalMarine();
		m_fInfestedCCWeight = Approach( pMarine && pMarine->IsInfested() ? 1.0f : 0.0f, m_fInfestedCCWeight, gpGlobals->frametime * ( 1.0f / INFESTED_CC_FADE_TIME ) );
		g_pColorCorrectionMgr->SetColorCorrectionWeight( m_CCInfestedHandle, m_fInfestedCCWeight );

		// If the mission was failed due to a dead tech, disable the environmental color correction in favor of the mission failed color correction
		if ( m_fInfestedCCWeight != 0.0f && m_pCurrentColorCorrection )
		{
			m_pCurrentColorCorrection->EnableOnClient( false );
			m_pCurrentColorCorrection = NULL;
		}
	}
#endif // 0

	// Only blend between environmental color corrections if there is no failure/infested-induced color correction
	if ( pNewColorCorrection != pOldColorCorrection /*&& m_fFailedCCWeight == 0.0f && m_fInfestedCCWeight == 0.0f*/ )
	{
		if ( pOldColorCorrection )
		{
			pOldColorCorrection->EnableOnClient( false );
		}
		if ( pNewColorCorrection )
		{
			pNewColorCorrection->EnableOnClient( true, pOldColorCorrection == NULL );
		}
		m_pCurrentColorCorrection = pNewColorCorrection;
	}
}
示例#7
0
void ARX_GLOBALMODS_Apply() {
	
	ARX_PROFILE_FUNC();
	
	float baseinc = g_framedelay;
	float incdiv1000 = g_framedelay * 0.001f;
	
	GLOBAL_MODS & current = g_currentFogParameters;
	GLOBAL_MODS & desired = g_desiredFogParameters;
	
	if (desired.flags & GMOD_ZCLIP) {
		current.zclip = Approach(current.zclip, desired.zclip, baseinc * 2);
	} else { // return to default...
		desired.zclip = current.zclip = Approach(current.zclip, DEFAULT_ZCLIP, baseinc * 2);
	}

	// Now goes for RGB mods
	if(desired.flags & GMOD_DCOLOR) {
		current.depthcolor.r = Approach(current.depthcolor.r, desired.depthcolor.r, incdiv1000);
		current.depthcolor.g = Approach(current.depthcolor.g, desired.depthcolor.g, incdiv1000);
		current.depthcolor.b = Approach(current.depthcolor.b, desired.depthcolor.b, incdiv1000);
	} else {
		current.depthcolor.r = Approach(current.depthcolor.r, 0, incdiv1000);
		current.depthcolor.g = Approach(current.depthcolor.g, 0, incdiv1000);
		current.depthcolor.b = Approach(current.depthcolor.b, 0, incdiv1000);
	}
	
	float fZclipp = config.video.fogDistance * 1.2f * (DEFAULT_ZCLIP - DEFAULT_MINZCLIP) / 10.f + DEFAULT_MINZCLIP;
	fZclipp += (g_camera->focal - 310.f) * 5.f;
	g_camera->cdepth = std::min(current.zclip, fZclipp);
	
	g_fogColor = Color(current.depthcolor);
}
示例#8
0
void CTFViewModel::CalcViewModelView( CBasePlayer *owner, const Vector& eyePosition, const QAngle& eyeAngles )
{
#if defined( CLIENT_DLL )

    Vector vecNewOrigin = eyePosition;
    QAngle vecNewAngles = eyeAngles;

    // Check for lowering the weapon
    C_TFPlayer *pPlayer = ToTFPlayer( owner );

    Assert( pPlayer );

    bool bLowered = pPlayer->IsWeaponLowered();

    QAngle vecLoweredAngles(0,0,0);

    m_vLoweredWeaponOffset.x = Approach( bLowered ? cl_gunlowerangle.GetFloat() : 0, m_vLoweredWeaponOffset.x, cl_gunlowerspeed.GetFloat() );
    vecLoweredAngles.x += m_vLoweredWeaponOffset.x;

    vecNewAngles += vecLoweredAngles;


    // Viewmodel offset
    Vector	forward, right, up;
    AngleVectors(eyeAngles, &forward, &right, &up);
    vecNewOrigin += forward*v_viewmodel_offset_x.GetFloat() + right*v_viewmodel_offset_y.GetFloat() + up*v_viewmodel_offset_z.GetFloat();

    if (owner->GetActiveWeapon())
        ToTFPlayer(owner)->GetActiveTFWeapon()->UpdateViewModel();

    BaseClass::CalcViewModelView( owner, vecNewOrigin, vecNewAngles );

#endif
}
示例#9
0
文件: ragdoll.cpp 项目: BoXorz/MSS
void C_ServerRagdoll::AddEntity( void )
{
    BaseClass::AddEntity();

    // Move blend weight toward target over 0.2 seconds
    m_flBlendWeightCurrent = Approach( m_flBlendWeight, m_flBlendWeightCurrent, gpGlobals->frametime * 5.0f );
}
示例#10
0
void CMenuMarcher::Think()
{
	BaseClass::Think();

	Speak();

	Vector vecNewOrigin = GetGlobalOrigin() + Vector(0, 5, 0) * (float)GameServer()->GetFrameTime();

	if (vecNewOrigin.y > 80)
		vecNewOrigin.y -= 160;

	vecNewOrigin.z = vecNewOrigin.z + GetGlobalVelocity().z * (float)GameServer()->GetFrameTime();

	float flNewHoverHeight = FindHoverHeight(vecNewOrigin) + 2;

	if (vecNewOrigin.z > flNewHoverHeight)
	{
		SetGlobalVelocity(Vector(0, 0, GetGlobalVelocity().z - 5 * (float)GameServer()->GetFrameTime()));
	}
	else
	{
		vecNewOrigin.z = flNewHoverHeight;
		SetGlobalVelocity(Vector(0, 0, Approach(0, GetGlobalVelocity().z, 1 * (float)GameServer()->GetFrameTime())));
	}

	SetGlobalOrigin(vecNewOrigin);
}
示例#11
0
void CStatusEffectSkinProxy::OnBind( C_BaseEntity *pEnt )
{
	float flEffectMagnitude;

	if (pEnt->IsPlayer() && ToCFPlayer(pEnt))
	{
		C_CFPlayer* pPlayer = ToCFPlayer(pEnt);
		flEffectMagnitude = pPlayer->m_pStats->GetEffectFromBitmask(STATUSEFFECT_SLOWNESS);
	}
	else if (pEnt->IsNPC() && dynamic_cast<C_CFActor*>(pEnt))
	{
		flEffectMagnitude = dynamic_cast<C_CFActor*>(pEnt)->m_flEffectMagnitude;
	}
	else
		return;

	if (m_pDetailBlend)
	{
		float flCurrent = m_pDetailBlend->GetFloatValue();
		float flGoal = RemapValClamped(flEffectMagnitude, 0.0f, 1.0f, 0.3f, 1.0f );

		if (flEffectMagnitude < 0.01)
			flGoal = 0.0f;

		m_pDetailBlend->SetFloatValue( Approach(flGoal, flCurrent, gpGlobals->frametime/10) );
	}
}
示例#12
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : time - 
//-----------------------------------------------------------------------------
void CFire::Extinguish( float heat )
{
	if ( !m_bEnabled )
		return;

	m_lastDamage = gpGlobals->curtime + 0.5;
	bool out = m_flHeatLevel > 0 ? true : false;

	m_flHeatLevel -= heat;
	m_flHeatAbsorb += fire_extabsorb.GetFloat() * heat;
	if ( m_flHeatAbsorb > fire_maxabsorb.GetFloat() )
	{
		m_flHeatAbsorb = fire_maxabsorb.GetFloat();
	}

	// drift toward the average attack time after being sprayed
	// some fires are heavily scripted so their attack looks weird 
	// once interacted with.  Basically, this blends out the scripting 
	// as the fire is sprayed with the extinguisher.
	float averageAttackTime = m_flMaxHeat * (FIRE_NORMAL_ATTACK_TIME/FIRE_MAX_HEAT_LEVEL);
	m_flAttackTime = Approach( averageAttackTime, m_flAttackTime, 2 * gpGlobals->frametime );

	if ( m_flHeatLevel <= 0 )
	{
		m_flHeatLevel = 0;
		if ( out )
		{
			GoOut();
		}
	}
}
void CSDKPlayer::DecayStyle()
{
	if (IsStyleSkillActive())
		return;

	float flDecayPerSecond = RemapValClamped(m_flStylePoints, 0, da_stylemeteractivationcost.GetFloat(), da_style_decay_min.GetFloat(), da_style_decay_max.GetFloat());
	float flDecayThisFrame = flDecayPerSecond * gpGlobals->frametime * GetSlowMoMultiplier();
	m_flStylePoints = Approach(0, m_flStylePoints, flDecayThisFrame);
}
Vector CSDKPlayerShared::GetRecoil(float flFrameTime)
{
	if (m_flRecoilAccumulator <= 0)
		return Vector(0, 0, 0);

	float flRecoil = m_flRecoilAccumulator*flFrameTime;
	m_flRecoilAccumulator = Approach(0, m_flRecoilAccumulator, flFrameTime * da_recoildecay.GetFloat());
	return m_vecRecoilDirection * flRecoil;
}
示例#15
0
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CFourWheelVehiclePhysics::SetSteering( float flSteering, float flSteeringRate )
{
	if ( !flSteeringRate )
	{
		m_controls.steering = flSteering;
	}
	else
	{
		m_controls.steering = Approach( flSteering, m_controls.steering, flSteeringRate );
	}
}
const Vector CSDKPlayer::CalculateThirdPersonCameraPosition(const Vector& vecEye, const QAngle& angCamera)
{
	float flCamBackIdle = GetUserInfoFloat("da_cam_back");
	float flCamUpIdle = GetUserInfoFloat("da_cam_up");
	float flCamRightIdle = GetUserInfoFloat("da_cam_right");

	float flCamBackAim = GetUserInfoFloat("da_cam_back_aim");
	float flCamUpAim = GetUserInfoFloat("da_cam_up_aim");
	float flCamRightAim = GetUserInfoFloat("da_cam_right_aim");

	float flCamBack = RemapValClamped(Gain(m_Shared.GetAimIn(), 0.8f), 0, 1, flCamBackIdle, flCamBackAim);
	float flCamUp = RemapValClamped(Gain(m_Shared.GetAimIn(), 0.8f), 0, 1, flCamUpIdle, flCamUpAim);
	float flCamRight = RemapValClamped(Gain(m_Shared.GetAimIn(), 0.8f), 0, 1, flCamRightIdle, flCamRightAim);

	m_flSideLerp = Approach(m_bThirdPersonCamSide?1:-1, m_flSideLerp, gpGlobals->frametime*15);
	flCamRight *= m_flSideLerp;

	Vector camForward, camRight, camUp;
	AngleVectors( angCamera, &camForward, &camRight, &camUp );

	Vector vecCameraOffset = -camForward*flCamBack + camRight*flCamRight + camUp*flCamUp;

	m_flStuntLerp = Approach((m_Shared.IsDiving()||m_Shared.IsRolling())?1:0, m_flStuntLerp, gpGlobals->frametime*2);

	if (m_flStuntLerp)
		vecCameraOffset += camUp * (m_flStuntLerp * da_cam_stunt_up.GetFloat());

	Vector vecNewOrigin = vecEye + vecCameraOffset;

	trace_t trace;

	CTraceFilterSimple traceFilter( this, COLLISION_GROUP_NONE );
	UTIL_TraceHull( vecEye, vecNewOrigin,
		Vector(-CAM_HULL_OFFSET, -CAM_HULL_OFFSET, -CAM_HULL_OFFSET), Vector(CAM_HULL_OFFSET, CAM_HULL_OFFSET, CAM_HULL_OFFSET),
		MASK_VISIBLE|CONTENTS_GRATE, &traceFilter, &trace );

	m_flCameraLerp = Approach(trace.fraction, m_flCameraLerp, da_cambacklerp.GetFloat()*gpGlobals->frametime);

	return vecEye + vecCameraOffset * m_flCameraLerp;
}
void CBulletManager::BulletsThink(float flFrameTime)
{
	for (int i = 0; i < m_aBullets.Count(); i++)
	{
		CBullet& oBullet = m_aBullets[i];
		if (!oBullet.m_bActive)
			continue;

		if (!oBullet.m_hShooter)
			oBullet.Deactivate();

		float flSpeed = da_bullet_speed.GetFloat();
		float flLerpTime = flSpeed / 400 * flFrameTime;

		if (oBullet.m_hShooter)
		{
			if (oBullet.m_hShooter->m_Shared.m_bSuperSkill || oBullet.m_hShooter->GetSlowMoType() == SLOWMO_ACTIVATED || oBullet.m_hShooter->GetSlowMoType() == SLOWMO_STYLESKILL)
				flSpeed = da_bullet_speed_active.GetFloat();

				flLerpTime *= oBullet.m_hShooter->GetSlowMoMultiplier();
		}

		oBullet.m_flCurrAlpha = Approach(oBullet.m_flGoalAlpha, oBullet.m_flCurrAlpha, flLerpTime);

		if (oBullet.m_bActive && oBullet.m_flGoalAlpha == 0 && oBullet.m_flCurrAlpha == 0)
		{
			oBullet.m_bActive = false;
#ifdef CLIENT_DLL
			ClientLeafSystem()->RemoveRenderable( oBullet.m_hRenderHandle );
#endif
			continue;
		}

		if (gpGlobals->curtime > oBullet.m_flShotTime + 10)
		{
			oBullet.Deactivate();
			continue;
		}

		if (!oBullet.m_hShooter)
			continue;

		float dt;
		if (oBullet.m_hShooter->GetSlowMoMultiplier() == 1)
			dt = -1;
		else
			dt = flSpeed * oBullet.m_hShooter->GetSlowMoMultiplier() * flFrameTime;

		SimulateBullet(oBullet, dt);
	}
}
示例#18
0
void CDigitanksEntity::StartTurn()
{
	// Recache it and make sure it's not dirty.
	DirtyVisibility();
	GetVisibility();

	float flHealth = m_flHealth;
	m_flHealth = Approach(m_flTotalHealth, m_flHealth, HealthRechargeRate());

	if (flHealth - m_flHealth < 0)
		DigitanksGame()->OnTakeDamage(this, NULL, NULL, flHealth - m_flHealth, true, false);

	m_ahSupplyLinesIntercepted.clear();
}
void CSDKPlayer::UpdateViewBobRamp()
{
#ifdef CLIENT_DLL
	// It's not filled in for remote clients, so force the local one since it's the same.
	float flMaxBobSpeed = C_SDKPlayer::GetLocalSDKPlayer()->m_Shared.m_flRunSpeed*0.7f;
#else
	float flMaxBobSpeed = m_Shared.m_flRunSpeed*0.7f;
#endif

	float flBobRampGoal = RemapValClamped(GetLocalVelocity().LengthSqr(), 0, flMaxBobSpeed*flMaxBobSpeed, 0, 1);
	if (!(GetFlags() & FL_ONGROUND) || m_Shared.IsRolling() || m_Shared.IsSliding())
		flBobRampGoal = 0;

	m_Shared.m_flViewBobRamp = Approach(flBobRampGoal, m_Shared.m_flViewBobRamp, gpGlobals->frametime*m_flSlowMoMultiplier*4);
}
示例#20
0
//-----------------------------------------------------------------------------
// Purpose: Updates the velocity and position of the rotating barrel
//-----------------------------------------------------------------------------
void CTFMinigun::UpdateBarrelMovement()
{
	if ( m_flBarrelCurrentVelocity != m_flBarrelTargetVelocity )
	{
		// update barrel velocity to bring it up to speed or to rest
		m_flBarrelCurrentVelocity = Approach( m_flBarrelTargetVelocity, m_flBarrelCurrentVelocity, 0.1 );

		if ( 0 == m_flBarrelCurrentVelocity )
		{	
			// if we've stopped rotating, turn off the wind-down sound
			WeaponSoundUpdate();
		}
	}

	// update the barrel rotation based on current velocity
	m_flBarrelAngle += m_flBarrelCurrentVelocity * gpGlobals->frametime;
}
void CSDKPlayer::UpdateCurrentTime()
{
	m_flCurrentTime += gpGlobals->frametime * GetSlowMoMultiplier();

	m_flSlowMoMultiplier = Approach(GetSlowMoGoal(), m_flSlowMoMultiplier, gpGlobals->frametime*2);

	if (m_flSlowMoTime > 0 && gpGlobals->curtime > m_flSlowMoTime)
	{
		m_flSlowMoTime = 0;
		m_iSlowMoType = SLOWMO_NONE;

#ifdef GAME_DLL
		SDKGameRules()->PlayerSlowMoUpdate(this);
#endif
	}

	UpdateViewBobRamp();
}
int main()
{
    try
    {
        using once  = Once;
        using times = Times;

        // run-time configurable:

        const int  Nsweep    = 1;
        const int  Nsection  = 2;
        const bool onceX     = true;

              auto scanner   = create_scanner  ( "Z" );
        const auto distance  = create_condition( "123 nm" );
        const auto threshold = create_condition( "chan1", "<=", "2.7 V" );

        Curve curve;

        curve.times( Nsweep )
             .scans( scanner )
             .add  (        Retract().stop_on( distance )   ).unless( onceX )
             .add  ( once ( Retract().stop_on( distance ) ) ).when  ( onceX )
             .add  ( times( Nsection )
                     .add ( Dwell()                         )
                     .add ( Approach().stop_on( threshold ) )
                     .add ( Dwell()                         )
                     .add ( Retract ().stop_on( distance  ) ) )
             ;

        std::cout << "\n1.curve.sweep(): "; curve.sweep();
        std::cout << "\n2.curve.sweep(): "; curve.sweep();
    }
    catch ( std::exception const & e )
    {
        std::cout << "Error: " << e.what() << std::endl;
    }
}
示例#23
0
void CGeneralWindow::Think()
{
	BaseClass::Think();

	m_flDeployed = Approach(m_flDeployedGoal, m_flDeployed, (float)GameServer()->GetFrameTime());

	SetPos(100, glgui::CRootPanel::Get()->GetHeight() - (int)(m_flDeployed*GetHeight()*1.5f));

	int iPrintChars = (int)((GameServer()->GetGameTime() - m_flStartTime)*50);
	if (m_flStartTime)
		m_pText->SetPrintChars(iPrintChars);

	bool bScrolling = (iPrintChars < (int)m_pText->GetText().length());

	if (bScrolling)
		m_pButton->SetButtonColor(Color(255, 0, 0, 255));
	else
		m_pButton->SetButtonColor(Color(255, 0, 0, 255)*Oscillate((float)GameServer()->GetGameTime(), 1));

	if (bScrolling)
	{
		if (!m_bHelperSpeaking)
		{
			CSoundLibrary::PlaySound(NULL, "sound/helper-speech.wav", true);
			m_bHelperSpeaking = true;
			CSoundLibrary::SetSoundVolume(NULL, "sound/helper-speech.wav", 0.7f);
		}
	}
	else
	{
		if (m_bHelperSpeaking)
		{
			CSoundLibrary::StopSound(NULL, "sound/helper-speech.wav");
			m_bHelperSpeaking = false;
		}
	}
}
void C_GlobalLight::ClientThink()
{
    VPROF("C_GlobalLight::ClientThink");

    bool bSupressWorldLights = false;

    if ( cl_globallight_freeze.GetBool() == true )
    {
        return;
    }
    //let us turn this shit on and off ingame
    m_bEnabled = cl_globallight_enabled.GetBool();

    if ( m_bEnabled )
    {
        Vector vLinearFloatLightColor( m_LightColor.r, m_LightColor.g, m_LightColor.b );
        float flLinearFloatLightAlpha = m_LightColor.a;

        if ( m_CurrentLinearFloatLightColor != vLinearFloatLightColor || m_flCurrentLinearFloatLightAlpha != flLinearFloatLightAlpha )
        {
            float flColorTransitionSpeed = gpGlobals->frametime * m_flColorTransitionTime * 255.0f;

            m_CurrentLinearFloatLightColor.x = Approach( vLinearFloatLightColor.x, m_CurrentLinearFloatLightColor.x, flColorTransitionSpeed );
            m_CurrentLinearFloatLightColor.y = Approach( vLinearFloatLightColor.y, m_CurrentLinearFloatLightColor.y, flColorTransitionSpeed );
            m_CurrentLinearFloatLightColor.z = Approach( vLinearFloatLightColor.z, m_CurrentLinearFloatLightColor.z, flColorTransitionSpeed );
            m_flCurrentLinearFloatLightAlpha = Approach( flLinearFloatLightAlpha, m_flCurrentLinearFloatLightAlpha, flColorTransitionSpeed );
        }

        FlashlightState_t state;

        Vector vDirection = m_shadowDirection;
        VectorNormalize( vDirection );

        //Vector vViewUp = Vector( 0.0f, 1.0f, 0.0f );
        Vector vSunDirection2D = vDirection;
        vSunDirection2D.z = 0.0f;

        HACK_GETLOCALPLAYER_GUARD( "C_GlobalLight::ClientThink" );

        if ( !C_BasePlayer::GetLocalPlayer() )
            return;

        Vector vPos;
        QAngle EyeAngles;
        float flZNear, flZFar, flFov;

        C_BasePlayer::GetLocalPlayer()->CalcView( vPos, EyeAngles, flZNear, flZFar, flFov );
//		Vector vPos = C_BasePlayer::GetLocalPlayer()->GetAbsOrigin();

//		vPos = Vector( 0.0f, 0.0f, 500.0f );
        vPos = ( vPos + vSunDirection2D * m_flNorthOffset ) - vDirection * m_flSunDistance;
        vPos += Vector( cl_globallight_xoffset.GetFloat(), cl_globallight_yoffset.GetFloat(), 0.0f );

        if (cl_globallight_showpos.GetBool() == true) {	//ËÀË ß ÒÓÒÀ ÍÅÌÍÎÃÎ ÍÀØÊÎÄÈË, ÍÅ ÐÓÃÀÉÒÈÑ ÏËÇ ËÀÍÑÏÑ
            if (cl_globallight_xpos.GetFloat() !=0 &&  cl_globallight_ypos.GetFloat() !=0) {
                DevMsg("X = %3.0f\n Y = %3.0f\n", cl_globallight_xpos.GetFloat(), cl_globallight_ypos.GetFloat());
            }
            else
                DevMsg("X = %3.0f\n Y = %3.0f\n", vPos.x, vPos.y);
        }
        if (cl_globallight_xpos.GetFloat() !=0 &&  cl_globallight_ypos.GetFloat() !=0) {
            vPos.x = cl_globallight_xpos.GetFloat();
            vPos.y = cl_globallight_ypos.GetFloat();
        }
        QAngle angAngles;
        VectorAngles( vDirection, angAngles );

        Vector vForward, vRight, vUp;
        AngleVectors( angAngles, &vForward, &vRight, &vUp );

        state.m_fHorizontalFOVDegrees = m_flFOV;
        state.m_fVerticalFOVDegrees = m_flFOV;

        state.m_vecLightOrigin = vPos;
        BasisToQuaternion( vForward, vRight, vUp, state.m_quatOrientation );

        state.m_fQuadraticAtten = 0.0f;
        state.m_fLinearAtten = m_flSunDistance * 2.0f;
        state.m_fConstantAtten = 0.0f;
        state.m_FarZAtten = m_flSunDistance * 2.0f;
        state.m_Color[0] = m_CurrentLinearFloatLightColor.x * ( 1.0f / 255.0f ) * m_flCurrentLinearFloatLightAlpha;
        state.m_Color[1] = m_CurrentLinearFloatLightColor.y * ( 1.0f / 255.0f ) * m_flCurrentLinearFloatLightAlpha;
        state.m_Color[2] = m_CurrentLinearFloatLightColor.z * ( 1.0f / 255.0f ) * m_flCurrentLinearFloatLightAlpha;
        state.m_Color[3] = 0.0f; // fixme: need to make ambient work m_flAmbient;
        state.m_NearZ = 4.0f;
        state.m_FarZ = m_flSunDistance * 2.0f;
        state.m_fBrightnessScale = 1.0f;
        state.m_bGlobalLight = true;

        float flOrthoSize = cl_globallight_orthosize.GetFloat();

        if ( flOrthoSize > 0 )
        {
            state.m_bOrtho = true;
            state.m_fOrthoLeft = -flOrthoSize;
            state.m_fOrthoTop = -flOrthoSize;
            state.m_fOrthoRight = flOrthoSize;
            state.m_fOrthoBottom = flOrthoSize;
        }
        else
        {
            state.m_bOrtho = false;
        }

        state.m_bDrawShadowFrustum = cl_globallight_drawfrustum.GetBool();
        state.m_flShadowSlopeScaleDepthBias =  1.0f;
        state.m_flShadowDepthBias = g_pMaterialSystemHardwareConfig->GetShadowDepthBias();
        state.m_bEnableShadows = m_bEnableShadows;
        state.m_pSpotlightTexture = m_SpotlightTexture;
        state.m_pProjectedMaterial = NULL; // don't complain cause we aren't using simple projection in this class
        state.m_nSpotlightTextureFrame = 0;
        state.m_flShadowFilterSize = 0.2f;
        //state.m_nShadowQuality = 1; // Allow entity to affect shadow quality
        state.m_bShadowHighRes = true;

        if ( m_bOldEnableShadows != m_bEnableShadows )
        {
            // If they change the shadow enable/disable, we need to make a new handle
            if ( m_LocalFlashlightHandle != CLIENTSHADOW_INVALID_HANDLE )
            {
                g_pClientShadowMgr->DestroyFlashlight( m_LocalFlashlightHandle );
                m_LocalFlashlightHandle = CLIENTSHADOW_INVALID_HANDLE;
            }

            m_bOldEnableShadows = m_bEnableShadows;
        }

        if( m_LocalFlashlightHandle == CLIENTSHADOW_INVALID_HANDLE )
        {
            m_LocalFlashlightHandle = g_pClientShadowMgr->CreateFlashlight( state );
        }
        else
        {
            g_pClientShadowMgr->UpdateFlashlightState( m_LocalFlashlightHandle, state );
            g_pClientShadowMgr->UpdateProjectedTexture( m_LocalFlashlightHandle, true );
        }

        bSupressWorldLights = m_bEnableShadows;
    }
    else if ( m_LocalFlashlightHandle != CLIENTSHADOW_INVALID_HANDLE )
    {
        g_pClientShadowMgr->DestroyFlashlight( m_LocalFlashlightHandle );
        m_LocalFlashlightHandle = CLIENTSHADOW_INVALID_HANDLE;
    }

    BaseClass::ClientThink();
}
void C_EnvProjectedTexture::UpdateLight( void )
{
	VPROF("C_EnvProjectedTexture::UpdateLight");
	bool bVisible = true;

	Vector vLinearFloatLightColor( m_LightColor.r, m_LightColor.g, m_LightColor.b );
	float flLinearFloatLightAlpha = m_LightColor.a;

	if ( m_bAlwaysUpdate )
	{
		m_bForceUpdate = true;
	}

	if ( m_CurrentLinearFloatLightColor != vLinearFloatLightColor || m_flCurrentLinearFloatLightAlpha != flLinearFloatLightAlpha )
	{
		float flColorTransitionSpeed = gpGlobals->frametime * m_flColorTransitionTime * 255.0f;

		m_CurrentLinearFloatLightColor.x = Approach( vLinearFloatLightColor.x, m_CurrentLinearFloatLightColor.x, flColorTransitionSpeed );
		m_CurrentLinearFloatLightColor.y = Approach( vLinearFloatLightColor.y, m_CurrentLinearFloatLightColor.y, flColorTransitionSpeed );
		m_CurrentLinearFloatLightColor.z = Approach( vLinearFloatLightColor.z, m_CurrentLinearFloatLightColor.z, flColorTransitionSpeed );
		m_flCurrentLinearFloatLightAlpha = Approach( flLinearFloatLightAlpha, m_flCurrentLinearFloatLightAlpha, flColorTransitionSpeed );

		m_bForceUpdate = true;
	}
	
	if ( !m_bForceUpdate )
	{
		bVisible = IsBBoxVisible();		
	}

	if ( m_bState == false || !bVisible )
	{
		// Spotlight's extents aren't in view
		ShutDownLightHandle();

		return;
	}

	if ( m_LightHandle == CLIENTSHADOW_INVALID_HANDLE || m_hTargetEntity != NULL || m_bForceUpdate )
	{
		Vector vForward, vRight, vUp, vPos = GetAbsOrigin();
		FlashlightState_t state;

		if ( m_hTargetEntity != NULL )
		{
			if ( m_bCameraSpace )
			{
				const QAngle &angles = GetLocalAngles();

				C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
				if( pPlayer )
				{
					const QAngle playerAngles = pPlayer->GetAbsAngles();

					Vector vPlayerForward, vPlayerRight, vPlayerUp;
					AngleVectors( playerAngles, &vPlayerForward, &vPlayerRight, &vPlayerUp );

					matrix3x4_t	mRotMatrix;
					AngleMatrix( angles, mRotMatrix );

					VectorITransform( vPlayerForward, mRotMatrix, vForward );
					VectorITransform( vPlayerRight, mRotMatrix, vRight );
					VectorITransform( vPlayerUp, mRotMatrix, vUp );

					float dist = (m_hTargetEntity->GetAbsOrigin() - GetAbsOrigin()).Length();
					vPos = m_hTargetEntity->GetAbsOrigin() - vForward*dist;

					VectorNormalize( vForward );
					VectorNormalize( vRight );
					VectorNormalize( vUp );
				}
			}
			else
			{
				vForward = m_hTargetEntity->GetAbsOrigin() - GetAbsOrigin();
				VectorNormalize( vForward );

				// JasonM - unimplemented
				Assert (0);

				//Quaternion q = DirectionToOrientation( dir );


				//
				// JasonM - set up vRight, vUp
				//

				//			VectorNormalize( vRight );
				//			VectorNormalize( vUp );
			}
		}
		else
		{
			AngleVectors( GetAbsAngles(), &vForward, &vRight, &vUp );
		}

		state.m_fHorizontalFOVDegrees = m_flLightFOV;
		state.m_fVerticalFOVDegrees = m_flLightFOV;

		state.m_vecLightOrigin = vPos;
		BasisToQuaternion( vForward, vRight, vUp, state.m_quatOrientation );
		state.m_NearZ = m_flNearZ;
		state.m_FarZ = m_flFarZ;

		// quickly check the proposed light's bbox against the view frustum to determine whether we
		// should bother to create it, if it doesn't exist, or cull it, if it does.
		if ( m_bSimpleProjection == false )
		{
#pragma message("OPTIMIZATION: this should be made SIMD")
			// get the half-widths of the near and far planes, 
			// based on the FOV which is in degrees. Remember that
			// on planet Valve, x is forward, y left, and z up. 
			const float tanHalfAngle = tan( m_flLightFOV * ( M_PI/180.0f ) * 0.5f );
			const float halfWidthNear = tanHalfAngle * m_flNearZ;
			const float halfWidthFar = tanHalfAngle * m_flFarZ;
			// now we can build coordinates in local space: the near rectangle is eg 
			// (0, -halfWidthNear, -halfWidthNear), (0,  halfWidthNear, -halfWidthNear), 
			// (0,  halfWidthNear,  halfWidthNear), (0, -halfWidthNear,  halfWidthNear)

			VectorAligned vNearRect[4] = { 
				VectorAligned( m_flNearZ, -halfWidthNear, -halfWidthNear), VectorAligned( m_flNearZ,  halfWidthNear, -halfWidthNear),
				VectorAligned( m_flNearZ,  halfWidthNear,  halfWidthNear), VectorAligned( m_flNearZ, -halfWidthNear,  halfWidthNear) 
			};

			VectorAligned vFarRect[4] = { 
				VectorAligned( m_flFarZ, -halfWidthFar, -halfWidthFar), VectorAligned( m_flFarZ,  halfWidthFar, -halfWidthFar),
				VectorAligned( m_flFarZ,  halfWidthFar,  halfWidthFar), VectorAligned( m_flFarZ, -halfWidthFar,  halfWidthFar) 
			};

			matrix3x4_t matOrientation( vForward, -vRight, vUp, vPos );

			enum
			{
				kNEAR = 0,
				kFAR = 1,
			};
			VectorAligned vOutRects[2][4];

			for ( int i = 0 ; i < 4 ; ++i )
			{
				VectorTransform( vNearRect[i].Base(), matOrientation, vOutRects[0][i].Base() );
			}
			for ( int i = 0 ; i < 4 ; ++i )
			{
				VectorTransform( vFarRect[i].Base(), matOrientation, vOutRects[1][i].Base() );
			}

			// now take the MIN and MAX extents for the bbox, and see if it is visible.
			Vector mins = **vOutRects; 
			Vector maxs = **vOutRects; 
			for ( int i = 1; i < 8 ; ++i )
			{
				VectorMin( mins, *(*vOutRects+i), mins );
				VectorMax( maxs, *(*vOutRects+i), maxs );
			}

#if 0 //for debugging the visibility frustum we just calculated
			NDebugOverlay::Triangle( vOutRects[0][0], vOutRects[0][1], vOutRects[0][2], 255, 0, 0, 100, true, 0.0f ); //first tri
			NDebugOverlay::Triangle( vOutRects[0][2], vOutRects[0][1], vOutRects[0][0], 255, 0, 0, 100, true, 0.0f ); //make it double sided
			NDebugOverlay::Triangle( vOutRects[0][2], vOutRects[0][3], vOutRects[0][0], 255, 0, 0, 100, true, 0.0f ); //second tri
			NDebugOverlay::Triangle( vOutRects[0][0], vOutRects[0][3], vOutRects[0][2], 255, 0, 0, 100, true, 0.0f ); //make it double sided

			NDebugOverlay::Triangle( vOutRects[1][0], vOutRects[1][1], vOutRects[1][2], 0, 0, 255, 100, true, 0.0f ); //first tri
			NDebugOverlay::Triangle( vOutRects[1][2], vOutRects[1][1], vOutRects[1][0], 0, 0, 255, 100, true, 0.0f ); //make it double sided
			NDebugOverlay::Triangle( vOutRects[1][2], vOutRects[1][3], vOutRects[1][0], 0, 0, 255, 100, true, 0.0f ); //second tri
			NDebugOverlay::Triangle( vOutRects[1][0], vOutRects[1][3], vOutRects[1][2], 0, 0, 255, 100, true, 0.0f ); //make it double sided

			NDebugOverlay::Box( vec3_origin, mins, maxs, 0, 255, 0, 100, 0.0f );
#endif
			
			bool bVisible = IsBBoxVisible( mins, maxs );
			if (!bVisible)
			{
				// Spotlight's extents aren't in view
				if ( m_LightHandle != CLIENTSHADOW_INVALID_HANDLE )
				{
					ShutDownLightHandle();
				}

				return;
			}
		}

		float flAlpha = m_flCurrentLinearFloatLightAlpha * ( 1.0f / 255.0f );

		state.m_fQuadraticAtten = 0.0;
		state.m_fLinearAtten = 100;
		state.m_fConstantAtten = 0.0f;
		state.m_FarZAtten = m_flFarZ;
		state.m_fBrightnessScale = m_flBrightnessScale;
		state.m_Color[0] = m_CurrentLinearFloatLightColor.x * ( 1.0f / 255.0f ) * flAlpha;
		state.m_Color[1] = m_CurrentLinearFloatLightColor.y * ( 1.0f / 255.0f ) * flAlpha;
		state.m_Color[2] = m_CurrentLinearFloatLightColor.z * ( 1.0f / 255.0f ) * flAlpha;
		state.m_Color[3] = 0.0f; // fixme: need to make ambient work m_flAmbient;
		state.m_flShadowSlopeScaleDepthBias = g_pMaterialSystemHardwareConfig->GetShadowSlopeScaleDepthBias();
		state.m_flShadowDepthBias = g_pMaterialSystemHardwareConfig->GetShadowDepthBias();
		state.m_bEnableShadows = m_bEnableShadows;
		state.m_pSpotlightTexture = m_SpotlightTexture;
		state.m_pProjectedMaterial = NULL; // only complain if we're using material projection
		state.m_nSpotlightTextureFrame = m_nSpotlightTextureFrame;
		state.m_flProjectionSize = m_flProjectionSize;
		state.m_flProjectionRotation = m_flRotation;

		state.m_nShadowQuality = m_nShadowQuality; // Allow entity to affect shadow quality

		if ( m_bSimpleProjection == true )
		{
			state.m_bSimpleProjection = true;
			state.m_bOrtho = true;
			state.m_fOrthoLeft = -m_flProjectionSize;
			state.m_fOrthoTop = -m_flProjectionSize;
			state.m_fOrthoRight = m_flProjectionSize;
			state.m_fOrthoBottom = m_flProjectionSize;
		}

		if( m_LightHandle == CLIENTSHADOW_INVALID_HANDLE )
		{
			// Hack: env projected textures don't work like normal flashlights; they're not assigned to a given splitscreen slot,
			// but the flashlight code requires this
			HACK_GETLOCALPLAYER_GUARD( "Env projected texture" );
			if ( m_bSimpleProjection == true )
			{
				m_LightHandle = g_pClientShadowMgr->CreateProjection( state );
			}
			else
			{
				m_LightHandle = g_pClientShadowMgr->CreateFlashlight( state );
			}

			if ( m_LightHandle != CLIENTSHADOW_INVALID_HANDLE )
			{
				m_bForceUpdate = false;
			}
		}
		else
		{
			if ( m_bSimpleProjection == true )
			{
				g_pClientShadowMgr->UpdateProjectionState( m_LightHandle, state );
			}
			else
			{
				g_pClientShadowMgr->UpdateFlashlightState( m_LightHandle, state );
			}
			m_bForceUpdate = false;
		}

		g_pClientShadowMgr->GetFrustumExtents( m_LightHandle, m_vecExtentsMin, m_vecExtentsMax );

		m_vecExtentsMin = m_vecExtentsMin - GetAbsOrigin();
		m_vecExtentsMax = m_vecExtentsMax - GetAbsOrigin();
	}

	if( m_bLightOnlyTarget )
	{
		g_pClientShadowMgr->SetFlashlightTarget( m_LightHandle, m_hTargetEntity );
	}
	else
	{
		g_pClientShadowMgr->SetFlashlightTarget( m_LightHandle, NULL );
	}

	g_pClientShadowMgr->SetFlashlightLightWorld( m_LightHandle, m_bLightWorld );

	if ( !asw_perf_wtf.GetBool() && !m_bForceUpdate )
	{
		g_pClientShadowMgr->UpdateProjectedTexture( m_LightHandle, true );
	}
}
float CPixelVisibilityQuery::GetFractionVisible( float fadeTimeInv )
{
	if ( !IsValid() )
		return 0.0f;

	if ( !m_wasQueriedThisFrame )
	{
		CMatRenderContextPtr pRenderContext( materials );
		m_wasQueriedThisFrame = true;
		int pixels = -1;
		int pixelsPossible = -1;
		if ( r_pixelvisibility_partial.GetBool() )
		{
			if ( m_frameIssued != -1 )
			{
				pixelsPossible = pRenderContext->OcclusionQuery_GetNumPixelsRendered( m_queryHandleCount );
				pixels = pRenderContext->OcclusionQuery_GetNumPixelsRendered( m_queryHandle );
			}

			if ( r_pixelvisibility_spew.GetBool() && CurrentViewID() == 0 ) 
			{
				DevMsg( 1, "Pixels visible: %d (qh:%d) Pixels possible: %d (qh:%d) (frame:%d)\n", pixels, (int)m_queryHandle, pixelsPossible, (int)m_queryHandleCount, gpGlobals->framecount );
			}

			if ( pixels < 0 || pixelsPossible < 0 )
			{
				m_failed = ( m_frameIssued >= 0 ) ? true : false;
				return m_brightnessTarget * m_clipFraction;
			}
			m_hasValidQueryResults = true;

			if ( pixelsPossible > 0 )
			{
				float target = (float)pixels / (float)pixelsPossible;
				target = (target >= 0.95f) ? 1.0f : (target < 0.0f) ? 0.0f : target;
				float rate = gpGlobals->frametime * fadeTimeInv;
				m_brightnessTarget = Approach( target, m_brightnessTarget, rate ); // fade in / out
			}
			else
			{
				m_brightnessTarget = 0.0f;
			}
		}
		else
		{
			if ( m_frameIssued != -1 )
			{
				pixels = pRenderContext->OcclusionQuery_GetNumPixelsRendered( m_queryHandle );
			}

			if ( r_pixelvisibility_spew.GetBool() && CurrentViewID() == 0 ) 
			{
				DevMsg( 1, "Pixels visible: %d (qh:%d) (frame:%d)\n", pixels, (int)m_queryHandle, gpGlobals->framecount );
			}

			if ( pixels < 0 )
			{
				m_failed = ( m_frameIssued >= 0 ) ? true : false;
				return m_brightnessTarget * m_clipFraction;
			}
			m_hasValidQueryResults = true;
			if ( m_frameIssued == gpGlobals->framecount-1 )
			{
				float rate = gpGlobals->frametime * fadeTimeInv;
				float target = 0.0f;
				if ( pixels > 0 )
				{
					// fade in slower than you fade out
					rate *= 0.5f;
					target = 1.0f;
				}
				m_brightnessTarget = Approach( target, m_brightnessTarget, rate ); // fade in / out
			}
			else
			{
				m_brightnessTarget = 0.0f;
			}
		}
	}

	return m_brightnessTarget * m_clipFraction;
}
示例#27
0
void CNB_Horiz_List::OnThink()
{
	BaseClass::OnThink();

	if ( MouseOverScrollbar() )
	{
		// No slidy auto scroll while using the scrollbar
		m_fScrollVelocity = 0.0f;
		m_fScrollChange = 0.0f;
	}
	else
	{
		int nMouseX, nMouseY;
		ASWInput()->GetFullscreenMousePos( &nMouseX, &nMouseY );
		ScreenToLocal( nMouseX, nMouseY );

		float fVelocityMax = 1200.0f;

		const float fAccelerationMax = 3000.0f;
		float fScrollAcceleration = 0.0f;

		if ( nMouseX > 0 && nMouseX < GetWide() && nMouseY > 0 && nMouseY < GetTall() )
		{
			const float fDeadZoneSize = 0.55f;
			float fMouseXInterp = static_cast<float>( nMouseX ) / GetWide();

			if ( fMouseXInterp > 0.5f + fDeadZoneSize * 0.5f )
			{
				fMouseXInterp = 0.25f + ( fMouseXInterp - ( 0.5f + fDeadZoneSize * 0.5f ) ) / ( ( 1.0f - fDeadZoneSize ) * 0.666666666f );
			}
			else if ( fMouseXInterp < 0.5f - fDeadZoneSize * 0.5f )
			{
				fMouseXInterp = -0.25f - ( ( 0.5f - fDeadZoneSize * 0.5f ) - fMouseXInterp ) / ( ( 1.0f - fDeadZoneSize ) * 0.666666666f );
			}
			else
			{
				fMouseXInterp = 0.0f;
			}

			fScrollAcceleration = fMouseXInterp * fAccelerationMax;
			fVelocityMax *= fabsf( fMouseXInterp );
		}

		if ( fScrollAcceleration == 0.0f )
		{
			// Dampen velocity in the dead zone
			m_fScrollVelocity = Approach( 0.0f, m_fScrollVelocity, gpGlobals->frametime * fAccelerationMax * 0.75f );
		}
		else
		{
			// Apply acceleration to the velocity
			m_fScrollVelocity = clamp( m_fScrollVelocity + fScrollAcceleration * gpGlobals->frametime, -fVelocityMax, fVelocityMax );
		}

		// Accumulate into a float for smaller than 1 changes
		m_fScrollChange += m_fScrollVelocity * gpGlobals->frametime;

		// Apply the integer amount
		int nScrollChange = m_fScrollChange;

		if ( nScrollChange <= -1 || nScrollChange >= 1 )
		{
			bool bChanged = ChangeScrollValue( nScrollChange );

			if ( bChanged )
			{
				m_fScrollChange -= nScrollChange;
			}
			else
			{
				// Hit the end
				m_fScrollVelocity = 0.0f;
				m_fScrollChange = 0.0f;
			}
		}
	}

	if ( m_bHighlightOnMouseOver )
	{
		for ( int i = 0; i < m_Entries.Count(); i++ )
		{
			if ( m_Entries[i]->IsCursorOver() )
			{
				SetHighlight( i );
				break;
			}
		}
	}

	vgui::Panel *pHighlighted = GetHighlightedEntry();
	if ( !pHighlighted )
		return;

	int x, y;
	pHighlighted->GetPos( x, y );
	m_flContainerTargetPos = YRES( 154 ) - x;

	if ( m_bInitialPlacement )
	{
		m_bInitialPlacement = false;
		m_flContainerPos = m_flContainerTargetPos;
	}
	else
	{
		if ( m_flContainerPos < m_flContainerTargetPos )
		{
			m_flContainerPos = MIN( m_flContainerPos + gpGlobals->frametime * SCROLL_SPEED, m_flContainerTargetPos );
		}
		else if ( m_flContainerPos > m_flContainerTargetPos )
		{
			m_flContainerPos = MAX( m_flContainerPos - gpGlobals->frametime * SCROLL_SPEED, m_flContainerTargetPos );
		}
	}
	//Msg( "m_flContainerPos = %f target = %f\n", m_flContainerPos, m_flContainerTargetPos );
	if ( !m_bShowScrollBar )
	{
		m_pChildContainer->SetPos( m_flContainerPos, 0 );
	}

	m_pLeftArrowButton->SetEnabled( m_nHighlightedEntry > 0 );
	m_pRightArrowButton->SetEnabled( m_nHighlightedEntry < m_Entries.Count() - 1 );
}
void CWalkerMiniStrider::WalkerThink()
{
	float dt = GetTimeDelta();

	BaseClass::WalkerThink();

	// Shoot the machine gun?
	if ( !m_bFiringLargeGun )
	{
		if ( m_LastButtons & IN_ATTACK )
		{
			if ( !m_bFiringMachineGun )
				StartFiringMachineGun();
		}
		else if ( m_bFiringMachineGun )
		{
			StopFiringMachineGun();
		}
	}

	// Fire the large gun?
	if ( !m_bFiringMachineGun )
	{
		if ( m_LastButtons & IN_ATTACK2 )
		{
			if ( !m_bFiringLargeGun )
				StartFiringLargeGun();
		}
	}


	UpdateCrouch();

	// Make sure it's crouched when there is no driver.
	if ( GetPassenger( VEHICLE_DRIVER ) )
	{
		if ( m_LastButtons & IN_DUCK )
		{
			Crouch();
		}
		else
		{
			UnCrouch();
		}
	}
	else
	{
		Crouch();
	}

	if ( m_bFiringMachineGun )
	{
		while ( gpGlobals->curtime > m_flNextShootTime )
		{
			FireMachineGun();
		}
	}
	
	UpdateLargeGun();

	// Move our torso within range of our feet.
	if ( m_flOriginToLowestLegHeight != -1 )
	{
		Vector vCenter = WorldSpaceCenter();

		//NDebugOverlay::EntityBounds( this, 255, 100, 0, 0 ,0 );
		//NDebugOverlay::Line( vCenter, vCenter-Vector(0,0,2000), 255,0,0, true, 0 );
		
		trace_t trace;
		UTIL_TraceLine( 
			vCenter, 
			vCenter - Vector( 0, 0, 2000 ),
			MASK_SOLID_BRUSHONLY, 
			this, 
			COLLISION_GROUP_NONE, 
			&trace );

		if ( trace.fraction < 1 )
		{
			m_flWantedZ = trace.endpos.z + m_flOriginToLowestLegHeight;
		}
		
		// Move our Z towards the wanted Z.
		if ( m_flWantedZ != -1 )
		{
			Vector vCur = vCenter;
			vCur.z = Approach( m_flWantedZ, vCur.z, STRIDER_TORSO_VERTICAL_SLIDE_SPEED * dt );
			SetAbsOrigin( GetAbsOrigin() + Vector( 0, 0, vCur.z - vCenter.z ) );
		}		
	}
}
void CDAViewModel::AddViewModelBob( CBasePlayer *owner, Vector& eyePosition, QAngle& eyeAngles )
{
	CSDKPlayer* pOwner = ToSDKPlayer(owner);
	if (!pOwner)
		return;

	CWeaponSDKBase* pWeapon = GetDAWeapon();
	if (pWeapon && pWeapon->IsThrowingGrenade())
	{
		float flThrowStart = GetDAWeapon()->GetGrenadeThrowStart();
		float flHolsterTime = GetDAWeapon()->GetGrenadeThrowWeaponHolsterTime();
		float flDeployTime = GetDAWeapon()->GetGrenadeThrowWeaponDeployTime();
		float flThrowEnd = GetDAWeapon()->GetGrenadeThrowEnd();

		float flGain = 0.7f;
		if (pOwner->GetCurrentTime() < flHolsterTime)
		{
			eyePosition -= Vector(0, 0, 1) * RemapGainedValClamped( pOwner->GetCurrentTime(), flGain, flThrowStart, flHolsterTime, 0, da_weapon_grenadethrow_drop.GetFloat());
			eyeAngles.x += RemapGainedValClamped( pOwner->GetCurrentTime(), flGain, flThrowStart, flHolsterTime, 0, da_weapon_grenadethrow_tilt.GetFloat());
		}
		else if (pOwner->GetCurrentTime() > flDeployTime)
		{
			eyePosition -= Vector(0, 0, 1) * RemapGainedValClamped( pOwner->GetCurrentTime(), flGain, flDeployTime, flThrowEnd, da_weapon_grenadethrow_drop.GetFloat(), 0);
			eyeAngles.x += RemapGainedValClamped( pOwner->GetCurrentTime(), flGain, flDeployTime, flThrowEnd, da_weapon_grenadethrow_tilt.GetFloat(), 0);
		}
	}

	// Offset it a tad so that it moves while looking around.
	eyePosition.x += da_weaponoffset.GetFloat();

	// For mysterious reasons that I don't care to investigate, the eye angles
	// are sometimes slammed to (0, 0, 0) for a frame or two. If this should
	// happen, use the previous eye angles instead.
	QAngle angEye = EyeAngles();

	if (angEye.x == 0 && angEye.y == 0 && angEye.z == 0)
		angEye = m_angLastPlayerEyeAngles;
	else
		m_angLastPlayerEyeAngles = angEye;

	Vector vecViewForward, vecViewRight, vecViewUp;
	AngleVectors(angEye, &vecViewForward, &vecViewRight, &vecViewUp);

	Vector vecViewDirection(vecViewForward.x, vecViewForward.y, 0);
	vecViewDirection.NormalizeInPlace();

	float flMaxVelocity = 100;
	Vector vecOwnerVelocity = pOwner->GetAbsVelocity();
	if (vecOwnerVelocity.LengthSqr() > flMaxVelocity*flMaxVelocity)
		vecOwnerVelocity = (vecOwnerVelocity / vecOwnerVelocity.Length()) * flMaxVelocity;

	m_vecPlayerVelocityLerp.x = Approach(vecOwnerVelocity.x, m_vecPlayerVelocityLerp.x, 1000*gpGlobals->frametime);
	m_vecPlayerVelocityLerp.y = Approach(vecOwnerVelocity.y, m_vecPlayerVelocityLerp.y, 1000*gpGlobals->frametime);
	m_vecPlayerVelocityLerp.z = Approach(vecOwnerVelocity.z, m_vecPlayerVelocityLerp.z, 1000*gpGlobals->frametime);

	Vector vecPlayerVelocityLerp = m_vecPlayerVelocityLerp;
	vecPlayerVelocityLerp.NormalizeInPlace();

	float flViewVelocityDot = fabs(vecPlayerVelocityLerp.Dot(vecViewRight));
	eyePosition += m_vecPlayerVelocityLerp * da_weaponlag.GetFloat() * flViewVelocityDot;

	if (pOwner->m_Shared.GetViewBobRamp() && pOwner->m_Shared.GetRunSpeed())
	{
		float flViewBobMagnitude = pOwner->m_Shared.GetViewBobRamp() * da_weaponbob.GetFloat();

		float flRunPeriod = M_PI * 3;
		float flRunUpBob = sin(pOwner->GetCurrentTime() * flRunPeriod * 2) * (flViewBobMagnitude / 2);
		float flRunRightBob = sin(pOwner->GetCurrentTime() * flRunPeriod) * flViewBobMagnitude;

		float flWalkPeriod = M_PI * 1.5f;
		float flWalkUpBob = sin(pOwner->GetCurrentTime() * flWalkPeriod * 2) * (flViewBobMagnitude / 2);
		float flWalkRightBob = sin(pOwner->GetCurrentTime() * flWalkPeriod) * flViewBobMagnitude;

		// 0 is walk, 1 is run.
		float flRunRamp = RemapValClamped(pOwner->m_Shared.GetViewBobRamp(), pOwner->m_Shared.GetAimInSpeed()/pOwner->m_Shared.GetRunSpeed(), 1.0f, 0.0f, 1.0f);

		float flRightBob = RemapValClamped(flRunRamp, 0, 1, flWalkRightBob, flRunRightBob);
		float flUpBob = RemapValClamped(flRunRamp, 0, 1, flWalkUpBob, flRunUpBob);

		eyePosition += vecViewRight * flRightBob + vecViewUp * (flUpBob - pOwner->m_Shared.GetViewBobRamp() * da_weapondrop.GetFloat());
	}

	if (pOwner->m_Shared.GetViewTilt())
	{
		Vector vecDiveRight = Vector(0, 0, 1).Cross(pOwner->m_Shared.GetDiveDirection());

		float flRightDot = vecViewDirection.Dot(vecDiveRight);
		float flUpDot = vecViewDirection.Dot(pOwner->m_Shared.GetDiveDirection());

		eyeAngles.z += flRightDot * pOwner->m_Shared.GetViewTilt() * da_weapontilt.GetFloat();;

		eyePosition += (vecViewUp * (flUpDot * 0.5f) + vecViewDirection * (flUpDot * 0.5f)) * pOwner->m_Shared.GetViewTilt();

		float flDiveBobMagnitude = 0.5f * pOwner->m_Shared.GetViewTilt();
		float flDiveBobPeriod = M_PI * 0.5f;
		float flDiveUpBob = sin(pOwner->GetCurrentTime() * flDiveBobPeriod * 2) * (flDiveBobMagnitude / 2);
		float flDiveRightBob = cos(pOwner->GetCurrentTime() * flDiveBobPeriod * 2) * (flDiveBobMagnitude / 2);

		eyePosition += vecViewRight * flDiveRightBob + vecViewUp * flDiveUpBob;
	}
}
示例#30
0
void CDABViewModel::AddViewModelBob( CBasePlayer *owner, Vector& eyePosition, QAngle& eyeAngles )
{
	CSDKPlayer* pOwner = ToSDKPlayer(owner);
	if (!pOwner)
		return;

	// Offset it a tad so that it moves while looking around.
	eyePosition.x += da_weaponoffset.GetFloat();

	Vector vecViewForward, vecViewRight, vecViewUp;
	AngleVectors(EyeAngles(), &vecViewForward, &vecViewRight, &vecViewUp);

	Vector vecViewDirection(vecViewForward.x, vecViewForward.y, 0);
	vecViewDirection.NormalizeInPlace();

	float flMaxVelocity = 100;
	Vector vecOwnerVelocity = pOwner->GetAbsVelocity();
	if (vecOwnerVelocity.LengthSqr() > flMaxVelocity*flMaxVelocity)
		vecOwnerVelocity = (vecOwnerVelocity / vecOwnerVelocity.Length()) * flMaxVelocity;

	m_vecPlayerVelocityLerp.x = Approach(vecOwnerVelocity.x, m_vecPlayerVelocityLerp.x, 1000*gpGlobals->frametime);
	m_vecPlayerVelocityLerp.y = Approach(vecOwnerVelocity.y, m_vecPlayerVelocityLerp.y, 1000*gpGlobals->frametime);
	m_vecPlayerVelocityLerp.z = Approach(vecOwnerVelocity.z, m_vecPlayerVelocityLerp.z, 1000*gpGlobals->frametime);

	Vector vecPlayerVelocityLerp = m_vecPlayerVelocityLerp;
	vecPlayerVelocityLerp.NormalizeInPlace();

	float flViewVelocityDot = fabs(vecPlayerVelocityLerp.Dot(vecViewRight));
	eyePosition += m_vecPlayerVelocityLerp * da_weaponlag.GetFloat() * flViewVelocityDot;

	if (pOwner->m_Shared.GetViewBobRamp() && pOwner->m_Shared.GetRunSpeed())
	{
		float flViewBobMagnitude = pOwner->m_Shared.GetViewBobRamp() * da_weaponbob.GetFloat();

		float flRunPeriod = M_PI * 3;
		float flRunUpBob = sin(pOwner->GetCurrentTime() * flRunPeriod * 2) * (flViewBobMagnitude / 2);
		float flRunRightBob = sin(pOwner->GetCurrentTime() * flRunPeriod) * flViewBobMagnitude;

		float flWalkPeriod = M_PI * 1.5f;
		float flWalkUpBob = sin(pOwner->GetCurrentTime() * flWalkPeriod * 2) * (flViewBobMagnitude / 2);
		float flWalkRightBob = sin(pOwner->GetCurrentTime() * flWalkPeriod) * flViewBobMagnitude;

		// 0 is walk, 1 is run.
		float flRunRamp = RemapValClamped(pOwner->m_Shared.GetViewBobRamp(), pOwner->m_Shared.GetAimInSpeed()/pOwner->m_Shared.GetRunSpeed(), 1.0f, 0.0f, 1.0f);

		float flRightBob = RemapValClamped(flRunRamp, 0, 1, flWalkRightBob, flRunRightBob);
		float flUpBob = RemapValClamped(flRunRamp, 0, 1, flWalkUpBob, flRunUpBob);

		eyePosition += vecViewRight * flRightBob + vecViewUp * (flUpBob - pOwner->m_Shared.GetViewBobRamp() * da_weapondrop.GetFloat());
	}

	if (pOwner->m_Shared.GetViewTilt())
	{
		Vector vecDiveRight = Vector(0, 0, 1).Cross(pOwner->m_Shared.GetDiveDirection());

		float flRightDot = vecViewDirection.Dot(vecDiveRight);
		float flUpDot = vecViewDirection.Dot(pOwner->m_Shared.GetDiveDirection());

		eyeAngles.z -= flRightDot * pOwner->m_Shared.GetViewTilt() * 8;

		eyePosition += (vecViewUp * (flUpDot * 0.5f) + vecViewDirection * (flUpDot * 0.5f)) * pOwner->m_Shared.GetViewTilt();

		float flDiveBobMagnitude = 0.5f * pOwner->m_Shared.GetViewTilt();
		float flDiveBobPeriod = M_PI * 0.5f;
		float flDiveUpBob = sin(pOwner->GetCurrentTime() * flDiveBobPeriod * 2) * (flDiveBobMagnitude / 2);
		float flDiveRightBob = cos(pOwner->GetCurrentTime() * flDiveBobPeriod * 2) * (flDiveBobMagnitude / 2);

		eyePosition += vecViewRight * flDiveRightBob + vecViewUp * flDiveUpBob;
	}
}