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); }
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); // 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); }