Esempio n. 1
0
        /// <summary>
        /// Set the motion for this spline.
        /// </summary>
        /// <param name="target">The object the motion should target. Must be non-null and a reference type.</param>
        /// <param name="duration">How long the motion should take, in seconds.</param>
        /// <param name="points">The points that the motion should spline between.</param>
        /// <returns>A reference to this, for specifying additional parameters.</returns>
        public Spliner Spline <TTarget, TPoint>(TTarget target, float duration, params TPoint[] points) where TTarget : class
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            var targetType = target.GetType();

            if (targetType.IsValueType)
            {
                throw new ArgumentException("Target may not be a struct");
            }

            Target   = target;
            Duration = duration;

            var path  = new List <float[]>();               //	float[] here is one object's properties
            var cross = new List <float[]>();               //	float[] here is one property's value at each point

            GetDefinitions(target, points[0], out accessor, out var pointDef);
            buffer = new float[accessor.Length];

            for (int i = 0; i < points.Length; i++)
            {
                path.Add(new float[pointDef.Length]);
                for (int j = 0; j < pointDef.Length; j++)
                {
                    path[i][j] = pointDef[j].GetValue(points[i]);
                }
            }

            for (int i = 0; i < pointDef.Length; i++)
            {
                var splinePoints = new float[path.Count];
                cross.Add(splinePoints);
                for (int j = 0; j < path.Count; j++)
                {
                    splinePoints[j] = path[j][i];
                }
            }

            Splines.Clear();
            for (int i = 0; i < cross.Count; i++)
            {
                Splines.Add(new Spline(cross[i]));
            }

            return(this);
        }
Esempio n. 2
0
 /// <summary>
 /// Remove all splines from the group
 /// </summary>
 public override void Clear()
 {
     Splines.Clear();
     SetDirtyAll();
 }