void CVehicleSeatActionRotateTurret::MaintainPartRotationWorldSpace(EVehicleTurretRotationType eType) { CVehiclePartBase* pPart = m_rotations[eType].m_pPart; IVehiclePart* pParent = pPart->GetParent(); IActor* pActor = m_pSeat->GetPassengerActor(); bool remote = m_pSeat->GetCurrentTransition() == IVehicleSeat::eVT_RemoteUsage; bool worldSpace = m_rotations[eType].m_worldSpace && VehicleCVars().v_independentMountedGuns != 0; if (worldSpace && pParent && pActor && pActor->IsClient() && !remote) { // we want to keep the old worldspace rotation // therefore we're updating the local transform from it // NB: there is no need to clamp here, its done later Matrix34 localTM = pParent->GetWorldTM().GetInverted() * Matrix34(m_rotations[eType].m_prevWorldQuat); localTM.OrthonormalizeFast(); // precision issue const Matrix34 &baseTM = pPart->GetLocalBaseTM(); if (!Matrix34::IsEquivalent(baseTM,localTM)) { Ang3 anglesCurr(baseTM); Ang3 angles(localTM); if (eType == eVTRT_Pitch) { angles.y = anglesCurr.y; angles.z = anglesCurr.z; } else if (eType == eVTRT_Yaw) { angles.x = anglesCurr.x; angles.y = anglesCurr.y; } localTM.SetRotationXYZ(angles); localTM.SetTranslation(baseTM.GetTranslation()); pPart->SetLocalBaseTM(localTM); m_pSeat->ChangedNetworkState(CVehicle::ASPECT_PART_MATRIX); } #if ENABLE_VEHICLE_DEBUG if (VehicleCVars().v_debugdraw == eVDB_Parts) { float color[] = {1,1,1,1}; Ang3 a(localTM), aBase(baseTM); gEnv->pRenderer->Draw2dLabel(200,200,1.4f,color,false,"localAng: %.1f (real: %.1f)", RAD2DEG(a.z), RAD2DEG(aBase.z)); } #endif } }
//------------------------------------------------------------------------ void CGunTurret::UpdateOrientation(float deltaTime) { FUNCTION_PROFILER(GetISystem(), PROFILE_GAME); bool changed = false; bool searching = (m_targetId==0 && m_turretparams.searching); float speed = searching ? m_turretparams.search_speed : m_turretparams.turn_speed; assert(m_goalYaw >= 0.f && m_goalYaw <= gf_PI2); // update turret Matrix34 turretTM = GetEntity()->GetSlotLocalTM(eIGS_Aux0, false); Ang3 turretAngles(turretTM); if(turretAngles.z < 0.0f) turretAngles.z+=gf_PI2; if(cry_fabsf(m_goalYaw-turretAngles.z) > gf_PI) { if(m_goalYaw >= gf_PI) turretAngles.z += gf_PI2; else turretAngles.z -= gf_PI2; } if(m_turretparams.yaw_range < 360.f) { // reverse, to avoid forbidden range if(m_goalYaw > gf_PI && turretAngles.z < gf_PI) turretAngles.z += gf_PI2; else if(m_goalYaw < gf_PI && turretAngles.z > gf_PI) turretAngles.z -= gf_PI2; } if(cry_fabsf(turretAngles.z-m_goalYaw) > 0.001f) { Interp(turretAngles.z, m_goalYaw, speed, deltaTime, 0.25f*speed); if(m_turretSound == INVALID_SOUNDID && gEnv->IsClient()) m_turretSound = PlayAction(g_pItemStrings->turret); changed = true; } else if(m_turretSound != INVALID_SOUNDID) { StopSound(m_turretSound); m_turretSound = INVALID_SOUNDID; } if(changed) { turretTM.SetRotationXYZ(turretAngles,turretTM.GetTranslation()); GetEntity()->SetSlotLocalTM(eIGS_Aux0, turretTM); } // update weapon Matrix34 weaponTM = GetEntity()->GetSlotLocalTM(eIGS_ThirdPerson, false); Ang3 weaponAngles(weaponTM); weaponAngles.z = turretAngles.z; if(cry_fabsf(weaponAngles.x-m_goalPitch) > 0.001f) { Interp(weaponAngles.x, m_goalPitch, speed, deltaTime, 0.25f*speed); if(m_cannonSound == INVALID_SOUNDID && gEnv->IsClient()) m_cannonSound = PlayAction(g_pItemStrings->cannon); changed = true; } else if(m_cannonSound != INVALID_SOUNDID) { StopSound(m_cannonSound); m_cannonSound = INVALID_SOUNDID; } if(changed) { weaponTM.SetRotationXYZ(weaponAngles); Vec3 w_trans = turretTM.TransformPoint(m_radarHelperPos); //Vec3 w_trans = GetSlotHelperPos(eIGS_Aux0,m_radarHelper.c_str(),false); weaponTM.SetTranslation(w_trans); GetEntity()->SetSlotLocalTM(eIGS_ThirdPerson, weaponTM); if(GetEntity()->IsSlotValid(eIGS_Aux1)) { Vec3 b_trans = weaponTM.TransformPoint(m_barrelHelperPos); //Vec3 b_trans = GetSlotHelperPos(eIGS_ThirdPerson,m_barrelHelper.c_str(),false); weaponTM.SetTranslation(b_trans); GetEntity()->SetSlotLocalTM(eIGS_Aux1, weaponTM*m_barrelRotation); } if(gEnv->IsClient()) { for(TEffectInfoMap::const_iterator it=m_effects.begin(); it!=m_effects.end(); ++it) { Matrix34 tm(GetSlotHelperRotation(eIGS_ThirdPerson,it->second.helper.c_str(),true), GetSlotHelperPos(eIGS_ThirdPerson,it->second.helper.c_str(),true)); SetEffectWorldTM(it->first, tm); } } } UpdatePhysics(); if(g_pGameCVars->i_debug_turrets == eGTD_Basic) { DrawDebug(); //gEnv->pRenderer->DrawLabel(GetEntity()->GetWorldPos(), 1.4f, "%s yaw: %.2f, goalYaw: %.2f (%.2f), goalPitch: %.2f (%.2f/%.2f)", searching?"[search]":"", RAD2DEG(turretAngles.z), RAD2DEG(m_goalYaw), 0.5f*(m_turretparams.yaw_range), RAD2DEG(m_goalPitch), m_turretparams.min_pitch, m_turretparams.max_pitch); } }
//------------------------------------------------------------------------ void CViewSystem::Update(float frameTime) { FUNCTION_PROFILER(GetISystem(), PROFILE_ACTION); if (gEnv->IsDedicated()) return; CView* const __restrict pActiveView = static_cast<CView*>(GetActiveView()); TViewMap::const_iterator Iter(m_views.begin()); TViewMap::const_iterator const IterEnd(m_views.end()); for (; Iter != IterEnd; ++Iter) { CView* const __restrict pView = Iter->second; bool const bIsActive = (pView == pActiveView); pView->Update(frameTime, bIsActive); if (bIsActive) { CCamera &rCamera = pView->GetCamera(); pView->UpdateAudioListener(rCamera.GetMatrix()); SViewParams currentParams = *(pView->GetCurrentParams()); rCamera.SetJustActivated(currentParams.justActivated); currentParams.justActivated = false; pView->SetCurrentParams(currentParams); if (m_bOverridenCameraRotation) { // When camera rotation is overridden. Vec3 pos = rCamera.GetMatrix().GetTranslation(); Matrix34 camTM(m_overridenCameraRotation); camTM.SetTranslation(pos); rCamera.SetMatrix(camTM); } else { // Normal setting of the camera if (m_fCameraNoise > 0) { Matrix33 m = Matrix33(rCamera.GetMatrix()); m.OrthonormalizeFast(); Ang3 aAng1 = Ang3::GetAnglesXYZ(m); //Ang3 aAng2 = RAD2DEG(aAng1); Matrix34 camTM = rCamera.GetMatrix(); Vec3 pos = camTM.GetTranslation(); camTM.SetIdentity(); const float fScale = 0.1f; CPNoise3* pNoise = m_pSystem->GetNoiseGen(); float fRes = pNoise->Noise1D(gEnv->pTimer->GetCurrTime() * m_fCameraNoiseFrequency); aAng1.x += fRes * m_fCameraNoise * fScale; pos.z -= fRes * m_fCameraNoise * fScale; fRes = pNoise->Noise1D(17 + gEnv->pTimer->GetCurrTime() * m_fCameraNoiseFrequency); aAng1.y -= fRes * m_fCameraNoise * fScale; //aAng1.z+=fRes*0.025f; // left / right movement should be much less visible camTM.SetRotationXYZ(aAng1); camTM.SetTranslation(pos); rCamera.SetMatrix(camTM); } } m_pSystem->SetViewCamera(rCamera); } } // Display debug info on screen if (m_nViewSystemDebug) { DebugDraw(); } // perform dynamic color grading // Beni - Commented for console demo stuff /****************************************************************************************** if (!IsPlayingCutScene() && gEnv->pAISystem) { SAIDetectionLevels detection; gEnv->pAISystem->GetDetectionLevels(nullptr, detection); float factor = detection.puppetThreat; // marcok: magic numbers taken from Maciej's tweaked values (final - initial) { float percentage = (0.0851411f - 0.0509998f)/0.0509998f * factor; float amount = 0.0f; gEnv->p3DEngine->GetPostEffectParam("ColorGrading_GrainAmount", amount); gEnv->p3DEngine->SetPostEffectParam("ColorGrading_GrainAmount_Offset", amount*percentage); } { float percentage = (0.405521f - 0.256739f)/0.256739f * factor; float amount = 0.0f; gEnv->p3DEngine->GetPostEffectParam("ColorGrading_SharpenAmount", amount); //gEnv->p3DEngine->SetPostEffectParam("ColorGrading_SharpenAmount_Offset", amount*percentage); } { float percentage = (0.14f - 0.11f)/0.11f * factor; float amount = 0.0f; gEnv->p3DEngine->GetPostEffectParam("ColorGrading_PhotoFilterColorDensity", amount); gEnv->p3DEngine->SetPostEffectParam("ColorGrading_PhotoFilterColorDensity_Offset", amount*percentage); } { float percentage = (234.984f - 244.983f)/244.983f * factor; float amount = 0.0f; gEnv->p3DEngine->GetPostEffectParam("ColorGrading_maxInput", amount); //gEnv->p3DEngine->SetPostEffectParam("ColorGrading_maxInput_Offset", amount*percentage); } { float percentage = (239.984f - 247.209f)/247.209f * factor; float amount = 0.0f; gEnv->p3DEngine->GetPostEffectParam("ColorGrading_maxOutput", amount); //gEnv->p3DEngine->SetPostEffectParam("ColorGrading_maxOutput_Offset", amount*percentage); } { Vec4 dest(0.0f/255.0f, 22.0f/255.0f, 33.0f/255.0f, 1.0f); Vec4 initial(2.0f/255.0f, 154.0f/255.0f, 226.0f/255.0f, 1.0f); Vec4 percentage = (dest - initial)/initial * factor; Vec4 amount; gEnv->p3DEngine->GetPostEffectParamVec4("clr_ColorGrading_SelectiveColor", amount); //gEnv->p3DEngine->SetPostEffectParamVec4("clr_ColorGrading_SelectiveColor_Offset", amount*percentage); } { float percentage = (-5.0083 - -1.99999)/-1.99999 * factor; float amount = 0.0f; gEnv->p3DEngine->GetPostEffectParam("ColorGrading_SelectiveColorCyans", amount); //gEnv->p3DEngine->SetPostEffectParam("ColorGrading_SelectiveColorCyans_Offset", amount*percentage); } { float percentage = (10.0166 - -5.99999)/-5.99999 * factor; float amount = 0.0f; gEnv->p3DEngine->GetPostEffectParam("ColorGrading_SelectiveColorMagentas", amount); //gEnv->p3DEngine->SetPostEffectParam("ColorGrading_SelectiveColorMagentas_Offset", amount*percentage); } { float percentage = (10.0166 - 1.99999)/1.99999 * factor; float amount = 0.0f; gEnv->p3DEngine->GetPostEffectParam("ColorGrading_SelectiveColorYellows", amount); //gEnv->p3DEngine->SetPostEffectParam("ColorGrading_SelectiveColorYellows_Offset", amount*percentage); } } ********************************************************************************************/ }