/// <summary> /// Create a camera state based on the current transform of this vcam /// </summary> /// <param name="worldUp">Current World Up direction, as provided by the brain</param> /// <param name="lens">Lens settings to serve as base, will be combined with lens from brain, if any</param> /// <returns></returns> protected CameraState PullStateFromVirtualCamera(Vector3 worldUp, ref LensSettings lens) { CameraState state = CameraState.Default; state.RawPosition = TargetPositionCache.GetTargetPosition(transform); state.RawOrientation = TargetPositionCache.GetTargetRotation(transform); state.ReferenceUp = worldUp; CinemachineBrain brain = CinemachineCore.Instance.FindPotentialTargetBrain(this); if (brain != null) { lens.SnapshotCameraReadOnlyProperties(brain.OutputCamera); } state.Lens = lens; return(state); }
Quaternion CalculateAverageOrientation() { if (mMaxWeight <= UnityVectorExtensions.Epsilon) { return(transform.rotation); } float weightedAverage = 0; Quaternion r = Quaternion.identity; for (int i = 0; i < m_Targets.Length; ++i) { if (m_Targets[i].target != null) { float scaledWeight = m_Targets[i].weight / mMaxWeight; var rot = TargetPositionCache.GetTargetRotation(m_Targets[i].target); r *= Quaternion.Slerp(Quaternion.identity, rot, scaledWeight); weightedAverage += scaledWeight; } } return(Quaternion.Slerp(Quaternion.identity, r, 1.0f / weightedAverage)); }