Exemple #1
0
void CPlayerRotation::Process()
{
	//FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);

	//
	float forceLookLen2(m_player.m_stats.forceLookVector.len2());
	if (forceLookLen2>0.001f && !g_vr->initialized()) // no forced look in VR please
	{
		float forceLookLen(cry_sqrtf(forceLookLen2));
		Vec3 forceLook(m_player.m_stats.forceLookVector);
		forceLook *= 1.0f/forceLookLen;
		forceLook = m_player.m_viewQuatFinal.GetInverted() * forceLook;

		float smoothSpeed(6.6f * forceLookLen);
		m_deltaAngles.x += asin(forceLook.z) * min(1.0f,m_frameTime*smoothSpeed);
		m_deltaAngles.z += cry_atan2f(-forceLook.x,forceLook.y) * min(1.0f,m_frameTime*smoothSpeed);

		CHECKQNAN_VEC(m_deltaAngles);
	}

	ProcessAngularImpulses();
	ProcessLean();
	
	if (m_stats.inAir && m_stats.inZeroG)
		ProcessFlyingZeroG();
	else if (m_stats.inFreefall.Value()==1)
		ProcessFreeFall();
	else if (m_stats.inFreefall.Value()==2)
		ProcessParachute();
	else
	{
		if(!g_vr->initialized())
		{
			ProcessNormalRoll();
			ClampAngles();
		}
		ProcessNormal();
	}

	//CHECKQNAN_MAT33(m_viewMtx);

	//update freelook when linked to an entity
	SLinkStats *pLinkStats = &m_player.m_linkStats;
	if (pLinkStats->linkID)
	{
		IEntity *pLinked = pLinkStats->GetLinked();
		if (pLinked)
		{
			//at this point m_baseQuat and m_viewQuat contain the previous frame rotation, I'm using them to calculate the delta rotation.
			m_baseQuatLinked *= m_player.m_baseQuat.GetInverted() * m_baseQuat;
			m_viewQuatLinked *= m_player.m_viewQuat.GetInverted() * m_viewQuat;

			m_baseQuat = pLinked->GetRotation() * m_baseQuatLinked;
			m_viewQuat = pLinked->GetRotation() * m_viewQuatLinked;
		}
	}
	//

	m_viewQuatFinal = m_viewQuat; //TEST:  * Quat::CreateRotationXYZ(m_player.m_viewAnglesOffset);
}
void CPlayerRotation::ProcessNormal()
{
	m_upVector = Vec3::CreateSlerp(m_upVector, m_stats.upVector, min(5.0f * m_frameTime, 1.0f));
	//create a matrix perpendicular to the ground
	Vec3 up(m_upVector);
	//..or perpendicular to the linked object Z
	SLinkStats *pLinkStats = &m_player.m_linkStats;

	if (pLinkStats->linkID && pLinkStats->flags & LINKED_FREELOOK)
	{
		IEntity *pLinked = pLinkStats->GetLinked();

		if (pLinked)
		{
			up = pLinked->GetRotation().GetColumn2();
		}
	}

	Vec3 right(m_baseQuat.GetColumn0());
	Vec3 forward((up % right).GetNormalized());
	CHECKQNAN_VEC(up);
	CHECKQNAN_VEC(right);
	CHECKQNAN_VEC(forward);
	m_baseQuat = Quat(Matrix33::CreateFromVectors(forward % up, forward, up));
	//CHECKQNAN_MAT33(m_baseMtx);
	m_baseQuat *= Quat::CreateRotationZ(m_deltaAngles.z);
	//m_baseQuat.Normalize();
	m_viewQuat = m_baseQuat *
				 Quat::CreateRotationX(GetLocalPitch() + m_deltaAngles.x) *
				 Quat::CreateRotationY(m_viewRoll);
	//m_viewQuat.Normalize();
	//CHECKQNAN_MAT33(m_viewMtx);
}
Exemple #3
0
void CPlayerRotation::ProcessNormal( float frameTime )
{
#ifdef ENABLE_NAN_CHECK
	//create a matrix perpendicular to the ground
	Vec3 up(0,0,1);
	//..or perpendicular to the linked object Z
	SLinkStats *pLinkStats = &m_player.m_linkStats;
	if (pLinkStats->linkID && pLinkStats->flags & SLinkStats::LINKED_FREELOOK)
	{
		IEntity *pLinked = pLinkStats->GetLinked();
		if (pLinked)
			up = pLinked->GetRotation().GetColumn2();
	}
	
	const Vec3 right(m_baseQuat.GetColumn0());
	const Vec3 forward((up % right).GetNormalized());

	PR_CHECKQNAN_VEC(up);
	PR_CHECKQNAN_VEC(right);
#endif //ENABLE_NAN_CHECK

	const Ang3 vNewDeltaAngles = m_deltaAngles * m_player.m_stats.flashBangStunMult;

#ifdef PLAYER_MOVEMENT_DEBUG_ENABLED
	m_player.DebugGraph_AddValue("AimDeltaH", vNewDeltaAngles.z);
	m_player.DebugGraph_AddValue("AimDeltaV", vNewDeltaAngles.x);
#endif

	Ang3 newViewAngles;
	newViewAngles.Set(m_viewAngles.x + vNewDeltaAngles.x, m_viewAngles.y, m_viewAngles.z + vNewDeltaAngles.z);
	newViewAngles += m_externalAngles;

	//These values need to be used because the player rotation is a quat and quaternions wrap on 720 degrees
	newViewAngles.z = (float)__fsel(  newViewAngles.z - (2.0f * gf_PI2),  newViewAngles.z - (4.0f * gf_PI2), newViewAngles.z);
	newViewAngles.z = (float)__fsel(-(newViewAngles.z + (2.0f * gf_PI2)), newViewAngles.z + (4.0f * gf_PI2), newViewAngles.z);
	
	m_viewAngles = newViewAngles;
		
	if (m_player.CanTurnBody())
	{
		m_baseQuat = Quat::CreateRotationZ(newViewAngles.z);
	}
	
	newViewAngles.y += m_viewRoll;
	m_viewQuat.SetRotationXYZ(newViewAngles);
	
	m_deltaAngles = vNewDeltaAngles;

	if(!m_player.GetLinkedVehicle())
	{
		CHANGED_NETWORK_STATE_REF(m_player, CPlayer::ASPECT_INPUT_CLIENT);
	}
}
Exemple #4
0
void CPlayerRotation::ProcessNormal()
{
	m_upVector = Vec3::CreateSlerp(m_upVector,m_stats.upVector,min(5.0f*m_frameTime, 1.0f));

	//create a matrix perpendicular to the ground
	Vec3 up(m_upVector);
	//..or perpendicular to the linked object Z
	SLinkStats *pLinkStats = &m_player.m_linkStats;
	if (pLinkStats->linkID && pLinkStats->flags & LINKED_FREELOOK)
	{
		IEntity *pLinked = pLinkStats->GetLinked();
		if (pLinked)
			up = pLinked->GetRotation().GetColumn2();
	}
	
	Vec3 right(m_baseQuat.GetColumn0());
	Vec3 forward((up % right).GetNormalized());

	CHECKQNAN_VEC(up);
	CHECKQNAN_VEC(right);
	CHECKQNAN_VEC(forward);

	m_baseQuat = Quat(Matrix33::CreateFromVectors(forward % up,forward,up));
	
	
	//CHECKQNAN_MAT33(m_baseMtx);

	// todo: if this works apply the delta yaw from VR input as well...
	//CryLogAlways("Engine Delta yaw: %f", m_deltaAngles.z);

	
	 m_baseQuat *= Quat::CreateRotationZ(m_deltaAngles.z);
	//m_baseQuat.Normalize();

	m_viewQuat = m_baseQuat * 
		Quat::CreateRotationX(GetLocalPitch() + m_deltaAngles.x) * 
		Quat::CreateRotationY(m_viewRoll);


	

	// Apply view data from trackers, base matrix probably includes yaw orientation already... (not totally ok but for now)
	if (m_player.IsClient() && g_vr->initialized())
	{	
		// base engine yaw that new read deltas should be applied onto for all tracking devices
		float baseYaw = m_baseQuat.GetRotZ();
		
		g_vr->update(baseYaw);	

		Ang3 angle;
		
		g_vr->headOrientation(angle);

		// apply the tracked yaw delta 
		m_baseQuat *= Quat::CreateRotationZ(angle.z - baseYaw);

		float baseYawAfter = m_baseQuat.GetRotZ();
		
		m_viewQuat = m_baseQuat * 
			Quat::CreateRotationX(angle.x) * 
			Quat::CreateRotationY(angle.y);
	}
	
	//m_viewQuat.Normalize();

	//CHECKQNAN_MAT33(m_viewMtx);
}
Exemple #5
-19
void CPlayerRotation::ProcessLinkedState( SLinkStats& linkStats, const Quat& lastBaseQuat, const Quat& lastViewQuat )
{
	if (!linkStats.linkID)
		return;
	
	IEntity *pLinked = linkStats.GetLinked();
	if (pLinked)
	{
		//at this point m_baseQuat and m_viewQuat contain the previous frame rotation, I'm using them to calculate the delta rotation.
		m_baseQuatLinked *= lastBaseQuat.GetInverted() * m_baseQuat;
		m_viewQuatLinked *= lastViewQuat.GetInverted() * m_viewQuat;

		m_baseQuatLinked.Normalize();
		m_viewQuatLinked.Normalize();

		const Quat qLinkedRotation = pLinked->GetRotation();

		m_baseQuat = qLinkedRotation * m_baseQuatLinked;
		m_viewQuat = qLinkedRotation * m_viewQuatLinked;
	}
}