Exemple #1
0
void CCameraView::UpdateSettings(SViewParams &viewParams)
{
	//cache some values for interpolation
	//float fLastDistance = m_curSettings.dist;

	ECamTypes eOldType = m_curSettings.camType;
	//get camera settings
	CCameraManager *pCamMan = g_pGame->GetCameraManager();
	CameraID iCurCam = pCamMan->GetActiveCameraId();
	pCamMan->GetCameraSettings(iCurCam, m_curSettings);

	if(eOldType != m_curSettings.camType)
	{
		m_bModeTransition = true;
		m_fTransitionTimeout = 1.0f;
	}

	//pre-calculations
	viewParams.fov = InterpolateTo(m_lastViewParams.fov, DEG2RAD(m_curSettings.FOV), 0.5f);

	//get frame time
	m_fFrameTime = max(gEnv->pTimer->GetFrameTime(), 0.0001f);

	// add cam offsets
	m_curSettings.dist = g_pGameCVars->cl_cam_orbit_distance;
// 	Vec3 camOffset(Vec3Constants<float>::fVec3_Zero);
	Vec3 camOffset = viewParams.rotation.GetColumn1().Cross(Vec3Constants<float>::fVec3_OneZ);
	camOffset.NormalizeFast();
	camOffset *= g_pGameCVars->cl_cam_orbit_offsetX;
	camOffset.z = g_pGameCVars->cl_cam_orbit_offsetZ;

	//update/interpolation position
	m_vTargetPosition = m_pTarget->GetWorldPos() + m_vTargetOffset + camOffset; //InterpolateTo(m_vTargetPosition, m_pTarget->GetWorldPos() + m_vTargetOffset, 0.1f);
}
void CCameraInputHelper::UpdatePitchYawDriver(float stickMag, float frameTimeNormalised)
{
	SCVars* pGameCVars = g_pGameCVars;

	//normal update
	CCameraManager *pCamMan = g_pGame->GetCameraManager();
	SCamModeSettings settings;
	pCamMan->GetCameraSettings(pCamMan->GetActiveCameraId(), settings);

	if (m_pHero->m_stats.flyMode == 0)
	{
		m_pHeroInput->m_deltaMovement=Vec3(0,1,0)*stickMag;
	}

	//camera flights overwrite everything
	CCameraFlight *pFlight = CCameraFlight::GetInstance();
	bool bFlightActive = pFlight->IsCameraFlightActive() || (pFlight->GetPaused() && pFlight->GetState() != eCFS_NONE);
	if(bFlightActive && !(pFlight->GetState() == eCFS_FADE_OUT && pFlight->GetFadeProgress() > 0.8f))
		return;

	//force settings overwrite inputs
	if(m_fForceSettings > 0.0f)
	{
		m_fYaw = m_fForceYaw;
		m_fPitch = m_fForcePitch;
		m_fForceSettings -= gEnv->pTimer->GetFrameTime();
		return;
	}

	// nav stick:
	static float g_fYawRotSpeed = 0.0f;
	static float g_fPitchRotSpeed = 0.0f;

	float fNewYawSpeed = m_pHeroInput->m_cameraStickLR * gf_PI * g_pGameCVars->cl_cam_rotation_speed;
	float fNewPitchSpeed = m_pHeroInput->m_cameraStickUD * gf_PI * g_pGameCVars->cl_cam_rotation_speed;

	//interpolate rotation acceleration
	if(g_pGameCVars->cl_cam_rotation_enable_acceleration)
	{

		if(fNewYawSpeed == 0.0f)
			g_fYawRotSpeed = 0.0f;
		else
		{
			g_fYawRotSpeed = InterpolateTo(g_fYawRotSpeed, fNewYawSpeed, g_pGameCVars->cl_cam_rotation_acceleration_time_yaw);
			if(g_fYawRotSpeed < 0.0f)
				g_fYawRotSpeed = min(g_fYawRotSpeed, -0.01f);
			else
				g_fYawRotSpeed = max(g_fYawRotSpeed, 0.01f);
		}
		if(fNewPitchSpeed == 0.0f)
			g_fPitchRotSpeed = 0.0f;
		else
		{
			g_fPitchRotSpeed = InterpolateTo(g_fPitchRotSpeed, fNewPitchSpeed, g_pGameCVars->cl_cam_rotation_acceleration_time_pitch);
			if(g_fPitchRotSpeed < 0.0f)
				g_fPitchRotSpeed = min(g_fPitchRotSpeed, -0.002f);
			else
				g_fPitchRotSpeed = max(g_fPitchRotSpeed, 0.002f);
		}
	}
	else
	{
		g_fYawRotSpeed = fNewYawSpeed;
		g_fPitchRotSpeed = fNewPitchSpeed;
	}

	//set delta yaw/pitch
	float deltaYawBase = g_fYawRotSpeed * frameTimeNormalised;
	deltaYawBase *= settings.m_fYawApplyRate; //apply yaw rate modifier
	float deltaPitchBase = g_fPitchRotSpeed * frameTimeNormalised;
	deltaPitchBase *= settings.m_fPitchApplyRate; //apply pitch rate modifier
	bool bHasYaw = abs(m_pHeroInput->m_cameraStickLR)>0.001f;
	bool bHasPitch = abs(m_pHeroInput->m_cameraStickUD)>0.001f;
	bool bAutoTracking = false;

	if(bHasYaw || bHasPitch)
		m_fLastUserInput = gEnv->pTimer->GetFrameStartTime().GetSeconds();

	//interpolate camera to target ***************
	if(UpdateTargetInterpolation())
		return;

	//if(settings.camType != ECT_CamFollow)
	{
		//handle auto rotation (simulated input)
		if(!bHasYaw && fabsf(m_fTrackingYawDelta) > 0.001f)
		{
			deltaYawBase = m_fTrackingYawDelta;
			m_fTrackingYawDelta = 0.0f;
			bAutoTracking = true;
		}
		if(!bHasPitch && fabsf(m_fTrackingPitchDelta) > 0.001f)
		{
			deltaPitchBase = m_fTrackingPitchDelta;
			m_fTrackingPitchDelta = 0.0f;
			bAutoTracking = true;
		}
	}

	if(g_pGameCVars->cl_cam_orbit != 0)
	{
		CCameraView *pCamView = g_pGame->GetCameraManager()->GetCamView();
		ECamTypes eLastType = pCamView->GetLastMode()->camType;
		if(eLastType != ECT_CamRear && eLastType != ECT_CamFirstPerson)
		{
			SetYawDelta(RetrieveYawDelta() - deltaYawBase);
			SetPitchDelta(RetrievePitchDelta() - deltaPitchBase);
		}
	}
	else if(!CCameraManager::ChangedCamera())
	{
		const float frameTime = max(gEnv->pTimer->GetFrameTime(),FLT_EPSILON);

		//add dampening to the rotation input
		static float yawDeltaDamped = 0.0f;
		float dampeningStrength = max(1.0f, pGameCVars->cl_cam_yaw_input_inertia / frameTime);

		yawDeltaDamped = yawDeltaDamped * (dampeningStrength-1.0f) + deltaYawBase;
		yawDeltaDamped /= dampeningStrength;
		if(bAutoTracking || bAutoTracking != m_bAutoTracking || fabsf(yawDeltaDamped) < fabsf(deltaYawBase))
			yawDeltaDamped = deltaYawBase;

		//wait for pull
		if(!m_bYawModified)
			m_fInputYawDelta = yawDeltaDamped;
		else
			m_fInputYawDelta += yawDeltaDamped;
		m_fYaw += yawDeltaDamped;
		if(fabsf(yawDeltaDamped) > 0.002f)
			m_bYawModified = true;

		//else
		//	m_bYawModified = false;

		//add dampening to the rotation input
		static float pitchDamped = 0.0f;
		dampeningStrength = max(1.0f, pGameCVars->cl_cam_pitch_input_inertia / frameTime);
		pitchDamped = pitchDamped * (dampeningStrength-1.0f) + deltaPitchBase;
		pitchDamped /= dampeningStrength;
		if(bAutoTracking != m_bAutoTracking || fabsf(pitchDamped) < fabsf(deltaPitchBase))
			pitchDamped = deltaPitchBase;

		//compute new pitch
		if(!m_bPitchModified)
			m_fInputPitchDelta = pitchDamped;
		else
			m_fInputPitchDelta += pitchDamped;
		if(fabsf(pitchDamped) > 0.002f)
			m_bPitchModified = true;
		//else
		//	m_bPitchModified = false;
		m_fPitch += pitchDamped;

		//clamp yaw to -pi .. pi
		ClampPiRange(m_fYaw);

		//clamp pitch
		m_fPitch = clamp(m_fPitch, pGameCVars->cl_cam_PitchMin, pGameCVars->cl_cam_PitchMax);
	}

	m_bAutoTracking = bAutoTracking;
}