Пример #1
0
 /// <summary>
 /// Gets a SkeletonSet for the standing Skeleton.
 /// </summary>
 /// <returns>A SkeletonSet for the standing Skeleton.</returns>
 public static SkeletonSet GetStandingSkeletonSet()
 {
     var newSkeleton = new Skeleton(StandingSkeletonName, ContentPaths.Dev);
     var nFrame0 = new SkeletonFrame(StandingSkeletonName, newSkeleton);
     var newSet = new SkeletonSet(new[] { nFrame0 });
     return newSet;
 }
Пример #2
0
        /// <summary>
        /// Changes the SkeletonSet used to animate.
        /// </summary>
        /// <param name="newSet">New SkeletonSet to use.</param>
        public void ChangeSet(SkeletonSet newSet)
        {
            if (newSet == null)
            {
                Debug.Fail("newSet is null.");
                return;
            }
            if (newSet.KeyFrames.Length == 0)
            {
                Debug.Fail("newSet contains no KeyFrames.");
                return;
            }

            // Set the new animation and clear the frame count
            _frame     = 0;
            _nextFrame = newSet.KeyFrames[0];
            _skelSet   = newSet;

            // Create a temporary new current keyframe by duplicating the current state and making
            // that our new current keyframe, resulting in a smooth translation to the next animation
            float delay;

            if (CurrentFrame.Delay == 0)
            {
                delay = _nextFrame.Delay;
            }
            else
            {
                delay = CurrentFrame.Delay;
            }

            _currFrame = new SkeletonFrame("_worker_", _skel.DeepCopy(), delay);
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SkeletonAnimation"/> class.
        /// </summary>
        /// <param name="currentTime">The current time.</param>
        /// <param name="skeletonSet"><see cref="SkeletonSet"/> to use for the keyframes.</param>
        /// <exception cref="ArgumentNullException"><paramref name="skeletonSet" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">skeletonSet contains no KeyFrames.</exception>
        public SkeletonAnimation(TickCount currentTime, SkeletonSet skeletonSet)
        {
            if (skeletonSet == null)
                throw new ArgumentNullException("skeletonSet");
            if (skeletonSet.KeyFrames.Length == 0)
                throw new ArgumentException("skeletonSet contains no KeyFrames.", "skeletonSet");

            _lastTime = currentTime;
            _skelSet = skeletonSet;
            _currFrame = _skelSet.KeyFrames[0];
            _nextFrame = _skelSet.KeyFrames.Length > 1 ? _skelSet.KeyFrames[1] : _skelSet.KeyFrames[0];
            _skel = CurrentFrame.Skeleton.DeepCopy();
        }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SkeletonAnimation"/> class.
        /// </summary>
        /// <param name="currentTime">The current time.</param>
        /// <param name="skeletonSet"><see cref="SkeletonSet"/> to use for the keyframes.</param>
        /// <exception cref="ArgumentNullException"><paramref name="skeletonSet" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">skeletonSet contains no KeyFrames.</exception>
        public SkeletonAnimation(TickCount currentTime, SkeletonSet skeletonSet)
        {
            if (skeletonSet == null)
            {
                throw new ArgumentNullException("skeletonSet");
            }
            if (skeletonSet.KeyFrames.Length == 0)
            {
                throw new ArgumentException("skeletonSet contains no KeyFrames.", "skeletonSet");
            }

            _lastTime  = currentTime;
            _skelSet   = skeletonSet;
            _currFrame = _skelSet.KeyFrames[0];
            _nextFrame = _skelSet.KeyFrames.Length > 1 ? _skelSet.KeyFrames[1] : _skelSet.KeyFrames[0];
            _skel      = CurrentFrame.Skeleton.DeepCopy();
        }
Пример #5
0
        /// <exception cref="ArgumentNullException"><paramref name="set" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="skel" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException"><paramref name="set"/> contians no KeyFrames.</exception>
        public static SkeletonSet CreateSmoothedSet(SkeletonSet set, Skeleton skel)
        {
            if (set == null)
            {
                throw new ArgumentNullException("set");
            }
            if (skel == null)
            {
                throw new ArgumentNullException("skel");
            }
            if (set.KeyFrames.Length == 0)
            {
                throw new ArgumentException("Parameter `set` contians no KeyFrames.", "set");
            }

            // Create the new frames
            var frames = new SkeletonFrame[set.KeyFrames.Length + 2];

            // Move the old frames into the new frames array
            for (var i = 0; i < set.KeyFrames.Length; i++)
            {
                frames[i + 1] = set.KeyFrames[i];
            }

            // Set the first and last frame to the skeleton
            var lastFrame = frames.Length - 1;

            frames[0]         = new SkeletonFrame(string.Empty, skel, frames[1].Delay);
            frames[lastFrame] = new SkeletonFrame(string.Empty, skel, frames[lastFrame - 1].Delay);

            // Copy over the IsModifier properties from the last frame from the old set
            // This is required to properly animate the new skeleton set
            // The last frame is used instead of the first since it is more important that
            // we transist out of the animation smoother than translating in, under the rare
            // and undesirable case that all IsModifier properties are not equal
            frames[0].Skeleton.CopyIsModifier(frames[lastFrame - 1].Skeleton);

            return(new SkeletonSet(frames));
        }
Пример #6
0
        /// <summary>
        /// Handles the Click event of the btnInterpolate control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void btnInterpolate_Click(object sender, EventArgs e)
        {
            var result = GetLoadSkeletonDialogResult(_filterFrame);

            if (result == null || result.Length <= 1)
                return;

            var frame1Skeleton = SkeletonLoader.LoadSkeleton(result);
            var frame1 = new SkeletonFrame(result, frame1Skeleton, 10);

            result = GetLoadSkeletonDialogResult(_filterFrame);

            if (result == null || result.Length <= 1)
                return;

            var frame2Skeleton = SkeletonLoader.LoadSkeleton(result);
            var frame2 = new SkeletonFrame(result, frame2Skeleton, 10);

            var frames = new[] { frame1, frame2 };

            var ss = new SkeletonSet(frames);
            var sa = new SkeletonAnimation(GetTime(), ss);

            sa.Update(5);
            LoadFrame(sa.Skeleton);
        }
Пример #7
0
        /// <summary>
        /// Handles the Click event of the btnFall control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void btnFall_Click(object sender, EventArgs e)
        {
            if (!radioAnimate.Checked)
                return;

            var newSet = new SkeletonSet(SkeletonLoader.FallingSkeletonSetName, ContentPaths.Dev);
            _skeletonAnim.ChangeSet(newSet);
        }
Пример #8
0
        /// <summary>
        /// Loads a SkeletonSet from the given FilePath. Assumes the loading is from the ContentPaths.Dev.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <returns>The loaded SkeletonSet, or null if the SkeletonSet failed to load.</returns>
        public static SkeletonSet LoadSkeletonSet(string filePath)
        {
            var skeletonSetName = Path.GetFileNameWithoutExtension(filePath);
            var realFilePath = SkeletonSet.GetFilePath(skeletonSetName, ContentPaths.Dev);

            // Make sure the file exists
            if (!File.Exists(realFilePath))
            {
                const string errmsg = "Failed to load SkeletonSet `{0}` from `{1}` - file does not exist.";
                var err = string.Format(errmsg, skeletonSetName, filePath);
                MessageBox.Show(err);
                return null;
            }

            // Try to load the skeleton
            SkeletonSet ret;
            try
            {
                ret = new SkeletonSet(skeletonSetName, ContentPaths.Dev);
            }
            catch (Exception ex)
            {
                const string errmsg = "Failed to load SkeletonSet `{0}` from `{1}`:{2}{3})";
                var err = string.Format(errmsg, skeletonSetName, filePath, Environment.NewLine, ex);
                MessageBox.Show(err);
                return null;
            }

            return ret;
        }
Пример #9
0
        /// <exception cref="ArgumentNullException"><paramref name="set" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="skel" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException"><paramref name="set"/> contians no KeyFrames.</exception>
        public static SkeletonSet CreateSmoothedSet(SkeletonSet set, Skeleton skel)
        {
            if (set == null)
                throw new ArgumentNullException("set");
            if (skel == null)
                throw new ArgumentNullException("skel");
            if (set.KeyFrames.Length == 0)
                throw new ArgumentException("Parameter `set` contians no KeyFrames.", "set");

            // Create the new frames
            var frames = new SkeletonFrame[set.KeyFrames.Length + 2];

            // Move the old frames into the new frames array
            for (var i = 0; i < set.KeyFrames.Length; i++)
            {
                frames[i + 1] = set.KeyFrames[i];
            }

            // Set the first and last frame to the skeleton
            var lastFrame = frames.Length - 1;
            frames[0] = new SkeletonFrame(string.Empty, skel, frames[1].Delay);
            frames[lastFrame] = new SkeletonFrame(string.Empty, skel, frames[lastFrame - 1].Delay);

            // Copy over the IsModifier properties from the last frame from the old set
            // This is required to properly animate the new skeleton set
            // The last frame is used instead of the first since it is more important that
            // we transist out of the animation smoother than translating in, under the rare
            // and undesirable case that all IsModifier properties are not equal
            frames[0].Skeleton.CopyIsModifier(frames[lastFrame - 1].Skeleton);

            return new SkeletonSet(frames);
        }
Пример #10
0
        /// <summary>
        /// Changes the SkeletonSet used to animate.
        /// </summary>
        /// <param name="newSet">New SkeletonSet to use.</param>
        public void ChangeSet(SkeletonSet newSet)
        {
            if (newSet == null)
            {
                Debug.Fail("newSet is null.");
                return;
            }
            if (newSet.KeyFrames.Length == 0)
            {
                Debug.Fail("newSet contains no KeyFrames.");
                return;
            }

            // Set the new animation and clear the frame count
            _frame = 0;
            _nextFrame = newSet.KeyFrames[0];
            _skelSet = newSet;

            // Create a temporary new current keyframe by duplicating the current state and making
            // that our new current keyframe, resulting in a smooth translation to the next animation
            float delay;
            if (CurrentFrame.Delay == 0)
                delay = _nextFrame.Delay;
            else
                delay = CurrentFrame.Delay;

            _currFrame = new SkeletonFrame("_worker_", _skel.DeepCopy(), delay);
        }