Esempio n. 1
0
        /// <summary>
        /// Gets the <see cref="SansyHuman.UDE.Util.Math.UDEMath.CartesianTimeFunction"/> of the curve.
        /// </summary>
        /// <returns>Cartesian function of the curve</returns>
        public UDEMath.CartesianTimeFunction GetFunctionOfCurve()
        {
            switch (type)
            {
            case CurveType.BEZIER:
                return(UDEMath.GetBezierCurve(points));

            case CurveType.CUBIC_SPLINE:
                return(UDEMath.GetNaturalCubicSplineCurve(points));

            case CurveType.CATMULL_ROM:
                return(UDEMath.GetCatmullRomSplineCurve(points));

            default:
                return(null);
            }
        }
Esempio n. 2
0
        private void OnDrawGizmosSelected()
        {
            if (points == null)
            {
                return;
            }

            Gizmos.color = Color.white;

            try
            {
                switch (type)
                {
                case CurveType.BEZIER:
                    var bezier = UDEMath.GetBezierCurve(points);
                    for (int i = 0; i < precision; i++)
                    {
                        Gizmos.DrawLine(bezier((float)i / precision).ToVector2(), bezier((float)(i + 1) / precision).ToVector2());
                    }
                    break;

                case CurveType.CUBIC_SPLINE:
                    var spline = UDEMath.GetNaturalCubicSplineCurve(points);
                    for (int i = 0; i < precision; i++)
                    {
                        Gizmos.DrawLine(spline((float)i / precision).ToVector2(), spline((float)(i + 1) / precision).ToVector2());
                    }
                    break;

                case CurveType.CATMULL_ROM:
                    var catmull = UDEMath.GetCatmullRomSplineCurve(points);
                    for (int i = 0; i < precision; i++)
                    {
                        Gizmos.DrawLine(catmull((float)i / precision).ToVector2(), catmull((float)(i + 1) / precision).ToVector2());
                    }
                    break;
                }
            }
            catch (System.Exception) { }

            Gizmos.color = Color.yellow;
            for (int i = 0; i < points.Length - 1; i++)
            {
                Gizmos.DrawLine(points[i], points[i + 1]);
            }
        }