Esempio n. 1
0
        /// <summary>Get the orientation the curve at a point along the path.</summary>
        /// <param name="pos">Position along the path.  Need not be normalized.</param>
        /// <returns>World-space orientation of the path, as defined by tangent, up, and roll.</returns>
        public override Quaternion EvaluateOrientation(float pos)
        {
            Quaternion transformRot = transform.rotation;
            Vector3    transformUp  = transformRot * Vector3.up;
            Quaternion result       = transformRot;

            if (m_Waypoints.Length > 0)
            {
                float roll = 0;
                int   indexA, indexB;
                pos = GetBoundingIndices(pos, out indexA, out indexB);
                if (indexA == indexB)
                {
                    roll = m_Waypoints[indexA].roll;
                }
                else
                {
                    UpdateControlPoints();
                    roll = SplineHelpers.Bezier1(pos - indexA,
                                                 m_Waypoints[indexA].roll, m_ControlPoints1[indexA].roll,
                                                 m_ControlPoints2[indexA].roll, m_Waypoints[indexB].roll);
                }

                Vector3 fwd = EvaluateTangent(pos);
                if (!fwd.AlmostZero())
                {
                    Quaternion q = Quaternion.LookRotation(fwd, transformUp);
                    result = q * RollAroundForward(roll);
                }
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>Get the orientation the curve at a point along the path.</summary>
        /// <param name="pos">Postion along the path.  Need not be normalized.</param>
        /// <returns>World-space orientation of the path, as defined by tangent, up, and roll.</returns>
        public override Quaternion EvaluateOrientation(float pos)
        {
            var result = transform.rotation;

            if (m_Waypoints.Length > 0)
            {
                float roll = 0;
                int   indexA, indexB;
                pos = GetBoundingIndices(pos, out indexA, out indexB);
                if (indexA == indexB)
                {
                    roll = m_Waypoints[indexA].roll;
                }
                else
                {
                    UpdateControlPoints();
                    roll = SplineHelpers.Bezier1(pos - indexA,
                                                 m_Waypoints[indexA].roll, m_ControlPoints1[indexA].roll,
                                                 m_ControlPoints2[indexA].roll, m_Waypoints[indexB].roll);
                }

                var fwd = EvaluateTangent(pos);
                if (!fwd.AlmostZero())
                {
                    var up = transform.rotation * Vector3.up;
                    var q  = Quaternion.LookRotation(fwd, up);
                    result = q * Quaternion.AngleAxis(roll, Vector3.forward);
                }
            }

            return(result);
        }
Esempio n. 3
0
        public override Quaternion EvaluateOrientation(float pos)
        {
            Quaternion result = base.transform.rotation;

            if (this.m_Waypoints.Length != 0)
            {
                int num;
                int num2;
                pos = this.GetBoundingIndices(pos, out num, out num2);
                float angle;
                if (num == num2)
                {
                    angle = this.m_Waypoints[num].roll;
                }
                else
                {
                    this.UpdateControlPoints();
                    angle = SplineHelpers.Bezier1(pos - (float)num, this.m_Waypoints[num].roll, this.m_ControlPoints1[num].roll, this.m_ControlPoints2[num].roll, this.m_Waypoints[num2].roll);
                }
                Vector3 vector = this.EvaluateTangent(pos);
                if (!vector.AlmostZero())
                {
                    Vector3 upwards = base.transform.rotation * Vector3.up;
                    result = Quaternion.LookRotation(vector, upwards) * Quaternion.AngleAxis(angle, Vector3.forward);
                }
            }
            return(result);
        }
        internal static float EvaluateDissipationScale(float spread, float normalizedDistance)
        {
            const float kMin = -0.8f;
            const float kMax = 0.8f;
            var         b    = kMin + (kMax - kMin) * (1f - spread);

            b = (1f - b) * 0.5f;
            var t = Mathf.Clamp01(normalizedDistance) / ((((1f / Mathf.Clamp01(b)) - 2f) * (1f - normalizedDistance)) + 1f);

            return(1 - SplineHelpers.Bezier1(t, 0, 0, 1, 1));
        }