From 5440734d820606b29a795c46172ade5d7eba8efb Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Mon, 3 Sep 2018 23:34:21 +0100 Subject: Initial commit --- .../Runtime/Components/CinemachineHardLookAt.cs | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Assets/Cinemachine/Base/Runtime/Components/CinemachineHardLookAt.cs (limited to 'Assets/Cinemachine/Base/Runtime/Components/CinemachineHardLookAt.cs') diff --git a/Assets/Cinemachine/Base/Runtime/Components/CinemachineHardLookAt.cs b/Assets/Cinemachine/Base/Runtime/Components/CinemachineHardLookAt.cs new file mode 100644 index 0000000..dfb3855 --- /dev/null +++ b/Assets/Cinemachine/Base/Runtime/Components/CinemachineHardLookAt.cs @@ -0,0 +1,42 @@ +using UnityEngine; + +namespace Cinemachine +{ + /// + /// This is a CinemachineComponent in the Aim section of the component pipeline. + /// Its job is to aim the camera hard at the LookAt target. + /// + [DocumentationSorting(23, DocumentationSortingAttribute.Level.UserRef)] + [AddComponentMenu("")] // Don't display in add component menu + [RequireComponent(typeof(CinemachinePipeline))] + [SaveDuringPlay] + public class CinemachineHardLookAt : CinemachineComponentBase + { + /// True if component is enabled and has a LookAt defined + public override bool IsValid { get { return enabled && LookAtTarget != null; } } + + /// Get the Cinemachine Pipeline stage that this component implements. + /// Always returns the Aim stage + public override CinemachineCore.Stage Stage { get { return CinemachineCore.Stage.Aim; } } + + /// Applies the composer rules and orients the camera accordingly + /// The current camera state + /// Used for calculating damping. If less than + /// zero, then target will snap to the center of the dead zone. + public override void MutateCameraState(ref CameraState curState, float deltaTime) + { + if (IsValid && curState.HasLookAt) + { + Vector3 dir = (curState.ReferenceLookAt - curState.CorrectedPosition); + if (dir.magnitude > Epsilon) + { + if (Vector3.Cross(dir.normalized, curState.ReferenceUp).magnitude < Epsilon) + curState.RawOrientation = Quaternion.FromToRotation(Vector3.forward, dir); + else + curState.RawOrientation = Quaternion.LookRotation(dir, curState.ReferenceUp); + } + } + } + } +} + -- cgit v1.2.1