Пример #1
0
SCameraFlightPoint CCameraFlight::GetSplinePoint(float t)
{
	if(m_cameraCourse.size() < 3)
		return SCameraFlightPoint();

	//clamp to 0..1 range
	CRY_ASSERT( t >= 0.0f && t <= 1.0f );
	t = clamp(t, 0.0f, 1.0f);

	m_tempCourseA = m_cameraCourse;
	m_tempCourseB.clear();

	//generate spline points
	do
	{
		for(int p = 0; p < m_tempCourseA.size()-1; ++p)
		{
			m_tempCourseB.push_back(m_tempCourseA[p]*(1.0f-t) + m_tempCourseA[p+1]*t);
		}
		m_tempCourseA = m_tempCourseB;
		m_tempCourseB.clear();
	}
	while (m_tempCourseA.size() > 1);

	//all points are relative to m_vRefPos (which can be ZERO)
	return m_tempCourseA[0] + m_vRefPos;
}
Пример #2
0
SCameraFlightPoint CCameraFlight::GetTrackPoint(float t)
{
	//clamp to 0..1 range
	CRY_ASSERT(t >= 0.0f && t <= 1.0f);
	t = clamp(t, 0.0f, 1.0f);

	float fLength = GetCourseLength();
	float fPositionOffset = fLength * t;

	CRY_ASSERT(!m_cameraCourse.empty());
	std::vector<SCameraFlightPoint>::const_iterator iter = m_cameraCourse.begin();
	// iterate to the second position
	++iter;
	std::vector<SCameraFlightPoint>::const_iterator end = m_cameraCourse.end();

	float fMoveDistance = 0.0f;
	float fLastMoveDistance = 0.0f;
	Vec3 vTempPos = m_cameraCourse[0].m_vCamPos;
	Vec3 vLastLookAt = m_cameraCourse[0].m_vCamLookAt;

	//compute track position for t
	for(; iter != end; ++iter)
	{
		fLastMoveDistance = fMoveDistance;
		Vec3 vEdge = iter->m_vCamPos - vTempPos;
		float fEdgeDistance = vEdge.len();
		fMoveDistance += fEdgeDistance;

		if(fMoveDistance > fPositionOffset)
		{
			float fEdgeDelta = fPositionOffset - fLastMoveDistance;
			Vec3 vLookDelta = (iter->m_vCamLookAt - vLastLookAt).normalized();
			return SCameraFlightPoint(vTempPos + fEdgeDelta * vEdge.normalized(), vLastLookAt + fEdgeDelta * vLookDelta) + m_vRefPos;
		}

		//update last Pos
		vLastLookAt = iter->m_vCamLookAt;
		vTempPos = iter->m_vCamPos;
	}

	//all points are relative to m_vRefPos (which can be ZERO)
	return m_cameraCourse[0] + m_vRefPos;
}
Пример #3
0
void CCameraFlight::UpdateFlight(SViewParams &viewParams)
{
	if(m_eMovementMode != eCFM_FREE_FLIGHT &&
		(m_fFlightProgress >= 1.0f || m_eMovementMode == eCFM_NONE || m_cameraCourse.size() < 3))
	{
		//update free fly point while not in free fly
		m_freeFlyPoint.m_vCamPos = viewParams.position;
		m_freeFlyPoint.m_vCamLookAt = viewParams.position + Vec3Constants<float>::fVec3_OneY;
		m_eState = eCFS_NONE;
		//nothing else to do
		return;
	}

	m_eState = eCFS_RUNNING;

	//update ref pos
	if(m_pRefEnt)
		m_vRefPos = m_pRefEnt->GetWorldPos();
	//if refPos2 is set, find middle
	if(m_vRefPos2.len2() > 0.0f)
		m_vRefPos = (m_vRefPos + m_vRefPos2) * 0.5f;

	//find target
	SCameraFlightPoint targetPoint = SCameraFlightPoint();

	switch(m_eMovementMode)
	{
	case eCFM_FREE_FLIGHT:
		targetPoint = m_freeFlyPoint;
		break;
	case eCFM_SPLINE:
		targetPoint = GetSplinePoint(m_fFlightProgress);
		break;
	case eCFM_LINE:
		targetPoint = GetTrackPoint(m_fFlightProgress);
		break;
	default:
		break;
	}

	//compute new dir/pos
	m_vLookingDirection = targetPoint.m_vCamLookAt - targetPoint.m_vCamPos;
	if(m_bUseRefDir)
	{
		m_vLookingDirection = m_vRefDir;
		m_qFadeOrientation = Quat::CreateRotationVDir(m_vLookingDirection, 0.0f);
	}
	m_vLookingDirection.NormalizeSafe();
	Quat qTempDirection = Quat::CreateRotationVDir(m_vLookingDirection, 0.0f);
	Vec3 vTempPos = targetPoint.m_vCamPos;

	bool bFading = false;

	//compute fading
	if(m_eMovementMode != eCFM_FREE_FLIGHT)
	{
		if(m_fFlightProgress > m_fFadeOutTime && (m_eFadeMode == eCFFM_OUT || m_eFadeMode == eCFFM_INOUT))
		{
			//fade position
			m_fFadeProgress = InterpolateTo(m_fFadeProgress, 1.0f, m_fFadeTime);
			m_vTargetFadePos = vTempPos * (1.0f - m_fFadeProgress) + viewParams.position * m_fFadeProgress;
			//fade orientation
			qTempDirection = Quat_tpl<float>::CreateNlerp(m_qFadeOrientation, viewParams.rotation, m_fFadeProgress);
			if(m_fFadeProgress < 0.998f)
			{
				bFading = true;
				m_eState = eCFS_FADE_OUT;
			}
		}
		else if(m_fFlightProgress < m_fFadeInTime && (m_eFadeMode == eCFFM_IN || m_eFadeMode == eCFFM_INOUT))
		{
			//fade position
			m_fFadeProgress = InterpolateTo(m_fFadeProgress, 1.0f, m_fFadeTime);
			m_vTargetFadePos = viewParams.position * (1.0f - m_fFadeProgress) + vTempPos * m_fFadeProgress;
			//fade orientation
			qTempDirection = Quat_tpl<float>::CreateNlerp(viewParams.rotation, qTempDirection, m_fFadeProgress);
			if(m_fFadeProgress < 0.998f)
			{
				bFading = true;
				m_eState = eCFS_FADE_IN;
			}
		}
		else
		{
			m_vTargetFadePos = vTempPos;
			//m_vTargetFadeLookAt = targetPoint.m_vCamLookAt;
			m_qFadeOrientation = qTempDirection;
			m_fFadeProgress = 0.0f;
			m_eState = eCFS_RUNNING;
		}
	}
	else
	{
		m_vTargetFadePos = vTempPos;
	}

	//update dir
	m_vLookingDirection = qTempDirection.GetColumn1();

	//raycast to prevent clipping during flight
	if(m_eMovementMode != eCFM_FREE_FLIGHT)
		DetectCollisions();

	//set position and rotation to viewparams
	viewParams.rotation = qTempDirection;
	viewParams.position = m_vTargetFadePos;//InterpolateTo(m_vTargetFadePos, viewParams.position, 1.0f);

	//progress flight
	if(m_eMovementMode != eCFM_FREE_FLIGHT && !bFading)
	{
		if(m_bPaused && m_fFlightProgress < 0.2f)
		{
			m_fFlightProgress += gEnv->pTimer->GetFrameTime() * m_fFlightSpeed;
			m_fFlightProgress = min(0.2f, m_fFlightProgress);
		}
		else if (!m_bPaused)
			m_fFlightProgress += gEnv->pTimer->GetFrameTime() * m_fFlightSpeed;
	}
}