/// <summary> /// Returns the local position of the camera along the spline used to connect the /// three camera rigs. Does not take into account the current heading of the /// camera (or its target) /// </summary> /// <param name="t">The t-value for the camera on its spline. Internally clamped to /// the value [0,1]</param> /// <returns>The local offset (back + up) of the camera WRT its target based on the /// supplied t-value</returns> public Vector3 GetLocalPositionForCameraFromInput(float t) { if (mOrbitals == null) { return(Vector3.zero); } UpdateCachedSpline(); int n = 1; if (t > 0.5f) { t -= 0.5f; n = 2; } return(SplineHelpers.Bezier3( t * 2f, m_CachedKnots[n], m_CachedCtrl1[n], m_CachedCtrl2[n], m_CachedKnots[n + 1])); }
/// <summary> /// 根据序号获取路径上的方向 /// </summary> /// <param name="pos">序号</param> /// <returns>全局方向</returns> public override Vector3 EvaluateTangent(float pos) { Vector3 result = transform.rotation * Vector3.forward; if (m_Waypoints.Length > 1) { UpdateControlPoints(); pos = GetBoundingIndices(pos, out int indexA, out int indexB); if (!Looped && indexA == m_Waypoints.Length - 1) { --indexA; } result = SplineHelpers.BezierTangent3(pos - indexA, m_Waypoints[indexA].position, m_ControlPoints1[indexA].position, m_ControlPoints2[indexA].position, m_Waypoints[indexB].position); } return(transform.TransformDirection(result)); }
public override Vector3 EvaluateTangent(float pos) { Vector3 direction = base.transform.rotation * Vector3.forward; if (this.m_Waypoints.Length > 1) { this.UpdateControlPoints(); int num; int num2; pos = this.GetBoundingIndices(pos, out num, out num2); if (!this.Looped && num == this.m_Waypoints.Length - 1) { num--; } direction = SplineHelpers.BezierTangent3(pos - (float)num, this.m_Waypoints[num].position, this.m_ControlPoints1[num].position, this.m_ControlPoints2[num].position, this.m_Waypoints[num2].position); } return(base.transform.TransformDirection(direction)); }
/// <summary> /// Returns the local position of the camera along the spline used to connect the /// three camera rigs. Does not take into account the current heading of the /// camera (or its target) /// </summary> /// <param name="t">The t-value for the camera on its spline. Internally clamped to /// the value [0,1]</param> /// <returns>The local offset (back + up) of the camera WRT its target based on the /// supplied t-value</returns> public Vector3 GetLocalPositionForCameraFromInput(float t) { //UnityEngine.Profiling.Profiler.BeginSample("CinemachineFreeLook.GetLocalPositionForCameraFromInput"); if (mOrbitals == null) { //UnityEngine.Profiling.Profiler.EndSample(); return(Vector3.zero); } UpdateCachedSpline(); int n = 1; if (t > 0.5f) { t -= 0.5f; n = 2; } //UnityEngine.Profiling.Profiler.EndSample(); return(SplineHelpers.Bezier3( t * 2f, m_CachedKnots[n], m_CachedCtrl1[n], m_CachedCtrl2[n], m_CachedKnots[n + 1])); }
public override Vector3 EvaluatePosition(float pos) { Vector3 position = Vector3.zero; if (this.m_Waypoints.Length != 0) { this.UpdateControlPoints(); int num; int num2; pos = this.GetBoundingIndices(pos, out num, out num2); if (num == num2) { position = this.m_Waypoints[num].position; } else { position = SplineHelpers.Bezier3(pos - (float)num, this.m_Waypoints[num].position, this.m_ControlPoints1[num].position, this.m_ControlPoints2[num].position, this.m_Waypoints[num2].position); } } return(base.transform.TransformPoint(position)); }
/// <summary>Get a worldspace position of a point along the path</summary> /// <param name="pos">Position along the path. Need not be normalized.</param> /// <returns>World-space position of the point along at path at pos</returns> public override Vector3 EvaluatePosition(float pos) { Vector3 result = Vector3.zero; if (m_Waypoints.Length > 0) { UpdateControlPoints(); int indexA, indexB; pos = GetBoundingIndices(pos, out indexA, out indexB); if (indexA == indexB) { result = m_Waypoints[indexA].position; } else { result = SplineHelpers.Bezier3(pos - indexA, m_Waypoints[indexA].position, m_ControlPoints1[indexA].position, m_ControlPoints2[indexA].position, m_Waypoints[indexB].position); } } return(transform.TransformPoint(result)); }
/// <summary>Get the tangent of the curve at a point along the path.</summary> /// <param name="pos">Postion along the path. Need not be normalized.</param> /// <returns>World-space direction of the path tangent. /// Length of the vector represents the tangent strength</returns> public override Vector3 EvaluateTangent(float pos) { Vector3 result = new Vector3(); if (m_Waypoints.Length == 0) result = transform.rotation * Vector3.forward; else { int indexA, indexB; pos = GetBoundingIndices(pos, out indexA, out indexB); if (indexA == indexB) result = m_Waypoints[indexA].tangent; else { Waypoint wpA = m_Waypoints[indexA]; Waypoint wpB = m_Waypoints[indexB]; result = SplineHelpers.BezierTangent3(pos - indexA, m_Waypoints[indexA].position, wpA.position + wpA.tangent, wpB.position - wpB.tangent, wpB.position); } } return transform.TransformDirection(result); }
/// <summary>Get a worldspace position of a point along the path</summary> /// <param name="pos">Postion along the path. Need not be normalized.</param> /// <returns>World-space position of the point along at path at pos</returns> public override Vector3 EvaluatePosition(float pos) { Vector3 result = new Vector3(); if (m_Waypoints.Length == 0) result = transform.position; else { int indexA, indexB; pos = GetBoundingIndices(pos, out indexA, out indexB); if (indexA == indexB) result = m_Waypoints[indexA].position; else { // interpolate Waypoint wpA = m_Waypoints[indexA]; Waypoint wpB = m_Waypoints[indexB]; result = SplineHelpers.Bezier3(pos - indexA, m_Waypoints[indexA].position, wpA.position + wpA.tangent, wpB.position - wpB.tangent, wpB.position); } } return transform.TransformPoint(result); }
private void UpdateControlPoints() { var numPoints = m_Waypoints == null ? 0 : m_Waypoints.Length; if (numPoints > 1 && (Looped != m_IsLoopedCache || m_ControlPoints1 == null || m_ControlPoints1.Length != numPoints || m_ControlPoints2 == null || m_ControlPoints2.Length != numPoints)) { var p1 = new Vector4[numPoints]; var p2 = new Vector4[numPoints]; var K = new Vector4[numPoints]; for (var i = 0; i < numPoints; ++i) { K[i] = m_Waypoints[i].AsVector4; } if (Looped) { SplineHelpers.ComputeSmoothControlPointsLooped(ref K, ref p1, ref p2); } else { SplineHelpers.ComputeSmoothControlPoints(ref K, ref p1, ref p2); } m_ControlPoints1 = new Waypoint[numPoints]; m_ControlPoints2 = new Waypoint[numPoints]; for (var i = 0; i < numPoints; ++i) { m_ControlPoints1[i] = Waypoint.FromVector4(p1[i]); m_ControlPoints2[i] = Waypoint.FromVector4(p2[i]); } m_IsLoopedCache = Looped; } }