void CPlayerRotation::ProcessForcedLookDirection( const Quat& lastViewQuat, float frameTime ) { const float forceLookLenSqr(m_forceLookVector.len2()); if (forceLookLenSqr < 0.001f) return; const float forceLookLen(sqrt_tpl(forceLookLenSqr)); Vec3 forceLook(m_forceLookVector); forceLook *= (float)__fres(forceLookLen); forceLook = lastViewQuat.GetInverted() * forceLook; const float smoothSpeed(6.6f * forceLookLen); float blendAmount = min(1.0f,frameTime*smoothSpeed); if(!m_bForcedLookAtBlendingEnabled) { blendAmount = 1.0f; } m_deltaAngles.x += asinf(forceLook.z) * blendAmount; m_deltaAngles.z += atan2_tpl(-forceLook.x,forceLook.y) * blendAmount; PR_CHECKQNAN_VEC(m_deltaAngles); }
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); }