/// <summary>Applies the composer rules and orients the camera accordingly</summary> /// <param name="curState">The current camera state</param> /// <param name="statePrevFrame">The camera state on the previous frame (unused)</param> /// <param name="deltaTime">Used for calculating damping. If less than /// or equal to zero, then target will snap to the center of the dead zone.</param> /// <returns>curState with RawOrientation applied</returns> public CameraState MutateCameraState( CameraState curState, CameraState statePrevFrame, float deltaTime) { if (!IsValid || !curState.HasLookAt) { return(curState); } CameraState newState = curState; newState.ReferenceLookAt = GetTrackedPoint(newState.ReferenceLookAt); if ((newState.ReferenceLookAt - newState.CorrectedPosition).AlmostZero()) { return(newState); // navel-gazing, get outa here } CinemachineBrain brain = CinemachineCore.Instance.FindPotentialTargetBrain(VirtualCamera); float aspect = brain != null ? brain.OutputCamera.aspect : 1; float fovH = CameraUtilities.CalculateHorizontalFOV(newState.Lens.FieldOfView, aspect); Rect softGuideFOV = ScreenToFOV(SoftGuideRect, newState.Lens.FieldOfView, fovH, aspect); if (deltaTime <= 0) { // No damping, just snap to central bounds, skipping the soft zone Rect rect = new Rect(softGuideFOV.center, Vector2.zero); // Force to center newState.RawOrientation = PlaceWithinScreenBounds( ref newState, rect, newState.RawOrientation, fovH, 0); } else { // Start with previous frame's orientation (but with current up) Quaternion rigOrientation = Quaternion.LookRotation( statePrevFrame.RawOrientation * Vector3.forward, newState.ReferenceUp); // First force the previous rotation into the hard bounds, no damping Rect hardGuideFOV = ScreenToFOV(HardGuideRect, newState.Lens.FieldOfView, fovH, aspect); newState.RawOrientation = PlaceWithinScreenBounds( ref newState, hardGuideFOV, rigOrientation, fovH, 0); // Now move it through the soft zone, with damping newState.RawOrientation = PlaceWithinScreenBounds( ref newState, softGuideFOV, newState.RawOrientation, fovH, deltaTime); } newState.RawOrientation = UnityQuaternionExtensions.Normalized(newState.RawOrientation); return(newState); }