Engines/FlatRedBallXNA/FlatRedBall/Math/Splines/Spline.cs
/// <summary>
/// Calculates the position along the spline given a time interval. 
/// The smaller the time interval, the smoother the spline. The larger the time interval, the
/// faster CalculateDistanceTimeRelationships will execute and the less internal memory will be used to store points.
/// </summary>
/// <param name="timeInterval">The time interval in seconds. 
/// For splines which have very sharp curves this value may need to be smaller to give a smoother curve. 
/// Trial and error may be required to get a smooth spline, but a value of 0.1 seconds is a good starting point.</param>
Calculates the position along the spline given a time interval.
The smaller the time interval, the smoother the spline. The larger the time interval, the
faster CalculateDistanceTimeRelationships will execute and the less internal memory will be used to store points.
Calculates the position along the spline given a time interval . The smaller the time interval the smoother the spline . The larger the time interval the faster CalculateDistanceTimeRelationships will execute and the less internal memory will be used to store points .
public void CalculateDistanceTimeRelationships(float timeInterval)
        {
            if (this.Count == 0)
            {
                return;
            }
#if DEBUG
            if (!mAccelerationsCalculated)
            {
                throw new InvalidOperationException("Spline.CalculateAccelerations() must be called before Spline.CalculateDistanceTimeRelationships()");
            }
#endif
            float currentTime = 0;
            Vector3 lastPosition = this[0].Position;
            Vector3 currentPosition;
            float runningDistance = 0;
            mDistanceToTimes.Clear();
            DistanceToTimeRelationship start = new DistanceToTimeRelationship();
            mDistanceToTimes.Add(start);
            while (currentTime < this.Duration)
            {
                currentTime += timeInterval;
                DistanceToTimeRelationship dttr = new DistanceToTimeRelationship();
                dttr.Time = currentTime;
                currentPosition = GetPositionAtTime(currentTime);
                runningDistance += (currentPosition - lastPosition).Length();
                System.Diagnostics.Debug.WriteLine(String.Format("Time: {0}\tDistance: {1}", currentTime, runningDistance));
                dttr.Distance = runningDistance;
                mDistanceToTimes.Add(dttr);
                lastPosition = currentPosition;
            }
        }
public void CalculateDistanceTimeRelationships ( float timeInterval ) { if ( this . Count == 0 ) { return ; } if DEBUG if ( ! mAccelerationsCalculated ) { throw new InvalidOperationException ( " " ) ; } endif float currentTime = 0 ; Vector3 lastPosition = this [ 0 ] . Position ; Vector3 currentPosition ; float runningDistance = 0 ; mDistanceToTimes . Clear ( ) ; DistanceToTimeRelationship start = new DistanceToTimeRelationship ( ) ; mDistanceToTimes . Add ( start ) ; while ( currentTime < this . Duration ) { currentTime += timeInterval ; DistanceToTimeRelationship dttr = new DistanceToTimeRelationship ( ) ; dttr . Time = currentTime ; currentPosition = GetPositionAtTime ( currentTime ) ; runningDistance += ( currentPosition - lastPosition ) . Length ( ) ; System . Diagnostics . Debug . WriteLine ( String . Format ( " \t " , currentTime , runningDistance ) ) ; dttr . Distance = runningDistance ; mDistanceToTimes . Add ( dttr ) ; lastPosition = currentPosition ; } }
Calculates the position along the spline given a time interval.
Calculates the position along the spline given a time interval .
timeInterval
float
The time interval in seconds.
For splines which have very sharp curves this value may need to be smaller to give a smoother curve.
Trial and error may be required to get a smooth spline, but a value of 0.1 seconds is a good starting point.
The time interval in seconds . For splines which have very sharp curves this value may need to be smaller to give a smoother curve . Trial and error may be required to get a smooth spline but a value of 0 . 1 seconds is a good starting point .