/// <summary>
        /// Function to add a track to the collection.
        /// </summary>
        /// <param name="track">Track to add.</param>
        /// <exception cref="ArgumentException"></exception>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="track"/> parameter is NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.ArgumentException">Thrown when the track parameter already exists in the collection.</exception>
        public void Add(GorgonAnimationTrack <T> track)
        {
            GorgonDebug.AssertNull(track, "track");

            if (Contains(track.Name))
            {
                throw new ArgumentException(string.Format(Resources.GORANM_TRACK_ALREADY_EXISTS, track.Name), "track");
            }

            AddItem(track);
        }
 /// <summary>
 /// Function to set an item in the collection.
 /// </summary>
 /// <param name="name">Name of the item to set.</param>
 /// <param name="value">Value to set.</param>
 protected override void SetItem(string name, GorgonAnimationTrack <T> value)
 {
     base.SetItem(name, value);
     value.Animation = _animation;
 }
 /// <summary>
 /// Function to add an item to a collection.
 /// </summary>
 /// <param name="value">Item to add.</param>
 protected override void AddItem(GorgonAnimationTrack <T> value)
 {
     base.AddItem(value);
     value.Animation = _animation;
 }
 /// <summary>
 /// Function to remove a track from the collection.
 /// </summary>
 /// <param name="track">Track to remove from the collection.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="track"/> parameter is NULL (Nothing in VB.Net).</exception>
 public void Remove(GorgonAnimationTrack <T> track)
 {
     RemoveItem(track);
 }
 /// <summary>
 /// Function to remove an item from a collection.
 /// </summary>
 /// <param name="item">Item to remove.</param>
 protected override void RemoveItem(GorgonAnimationTrack <T> item)
 {
     item.Animation = null;
     base.RemoveItem(item);
 }
Exemplo n.º 6
0
            /// <summary>
            /// Constructor.
            /// </summary>
            /// <param name="owner">Owning track.</param>
            /// <param name="requestedTime">Track time requested.</param>
            internal NearestKeys(GorgonAnimationTrack <T> owner, float requestedTime)
            {
                float animationLength = owner.Animation.Length;                     // Animation length.
                int   i;                                                            // Loop.

#if DEBUG
                if (owner.KeyFrames.Count < 1)
                {
                    throw new ArgumentException(Resources.GORANM_TRACK_HAS_NO_KEYS, "owner");
                }
#endif

                // Initialize.
                PreviousKeyIndex = 0;
                PreviousKey      = owner.KeyFrames[0];
                NextKeyIndex     = -1;
                NextKey          = null;
                KeyTimeDelta     = 0;

                // Wrap around.
                while (requestedTime > animationLength)
                {
                    requestedTime -= animationLength;
                }

                // Find previous key.
                if (owner.KeyFrames[0].Time <= requestedTime)
                {
                    for (i = 0; i < owner.KeyFrames.Count; i++)
                    {
                        if ((!(owner.KeyFrames[i].Time > requestedTime)) || (i <= 0))
                        {
                            continue;
                        }

                        PreviousKey      = owner.KeyFrames[i - 1];
                        PreviousKeyIndex = i - 1;
                        break;
                    }
                }
                else
                {
                    i = 1;
                }

                // Wrap to the first key if we went through the entire list.
                if (i >= owner.KeyFrames.Count)
                {
                    if (!owner.Animation.IsLooped)
                    {
                        NextKey      = owner.KeyFrames[owner.KeyFrames.Count - 1];
                        NextKeyIndex = owner.KeyFrames.Count - 1;
                    }
                    else
                    {
                        NextKey      = owner.KeyFrames[0];
                        NextKeyIndex = 0;
                    }
                    KeyTimeDelta = animationLength;
                }
                else
                {
                    NextKey      = owner.KeyFrames[i];
                    NextKeyIndex = i;
                    KeyTimeDelta = NextKey.Time;
                }

                // Same frame.
                if (PreviousKey.Time.EqualsEpsilon(KeyTimeDelta, 0.001f))
                {
                    KeyTimeDelta = 0;
                }
                else
                {
                    KeyTimeDelta = (requestedTime - PreviousKey.Time) / (KeyTimeDelta - PreviousKey.Time);
                }

                // We can't have negative time.
                if (KeyTimeDelta < 0)
                {
                    KeyTimeDelta = 0;
                }
                TrackTimePosition = requestedTime;
            }
 /// <summary>
 /// Initializes a new instance of the <see cref="GorgonAnimationKeyFrameCollection{T}" /> class.
 /// </summary>
 /// <param name="track">Track that owns this collection.</param>
 internal GorgonAnimationKeyFrameCollection(GorgonAnimationTrack <T> track)
 {
     _keyFrames = new List <IKeyFrame>();
     Times      = new SortedList <float, IKeyFrame>();
     _track     = track;
 }