public SnapShot GetSnapshot(ulong timestep)
        {
            SnapShot lower;
            SnapShot upper;

            if (FindSnapshots(timestep, out lower, out upper))
            {
                float t = (timestep - lower.tick) / (float)(upper.tick - lower.tick);

                //Debug.LogFormat("UpdateSnapshot: {0} {1} {2} {3}", t, lower.tick, timestep, upper.tick);
                return(new SnapShot()
                {
                    tick = timestep,
                    position = InterpolateVector3.Interpolate(lower.position, upper.position, t),
                    rotation = InterpolateQuaternion.Interpolate(lower.rotation, upper.rotation, t),
                    velocity = InterpolateVector3.Interpolate(lower.velocity, upper.velocity, t),
                    Health = Interpolated <int> .Interpolate(lower.Health, upper.Health, t),
                    LastCommand = Interpolated <ulong> .Interpolate(lower.LastCommand, upper.LastCommand, t),
                });
            }
            else
            {
                ulong start;
                ulong end;
                int   count;
                GetSnapShotWindow(out start, out end, out count);
                float t = (timestep - start) / (float)(end - start);
                Debug.LogFormat("UpdateSnapshot: {0} {1} {2} {3} {4}", t, start, timestep, end, count);
            }

            return(new SnapShot());
        }
示例#2
0
        public virtual void numTotalFrames_ValueChanged(object sender, EventArgs e)
        {
            if (TargetAnimation == null || _updating)
            {
                return;
            }

            int max = (int)PlaybackPanel.numTotalFrames.Value;

            PlaybackPanel.numFrameIndex.Maximum = max;

            if (Interpolated.Contains(TargetAnimation.GetType()) && TargetAnimation.Loop)
            {
                max--;
            }

            _maxFrame = max;
            TargetAnimation.FrameCount = max;
        }
示例#3
0
        public virtual void SetFrame(int index)
        {
            if (index < 0)
            {
                return;
            }

            NW4RAnimationNode node = TargetAnimation;
            int loopMax            = _maxFrame + (node != null && node.Loop && Interpolated.Contains(node.GetType()) ? 1 : 0);

            if (index > loopMax)
            {
                return;
            }

            CurrentFrame = index;

            if (PlaybackPanel != null)
            {
                if (PlaybackPanel.InvokeRequired)
                {
                    Action <int, int> d = new Action <int, int>(PlaybackPanel.UpdateInterface);
                    this.Invoke(d, new object[] { _animFrame, loopMax });
                }
                else
                {
                    PlaybackPanel.UpdateInterface(_animFrame, loopMax);
                }
            }

            if (!_playing)
            {
                if (InterpolationEditor != null && InterpolationEditor.Visible)
                {
                    InterpolationEditor.Frame = CurrentFrame;
                }

                if (KeyframePanel != null)
                {
                    KeyframePanel.numFrame_ValueChanged();
                }
            }
        }
示例#4
0
        /// <summary>
        /// Read
        /// </summary>
        /// <param name="type">Type</param>
        /// <param name="st">Statement</param>
        /// <param name="netlist">Netlist</param>
        /// <returns></returns>
        public override bool Read(string type, Statement st, Netlist netlist)
        {
            Interpolated ip = new Interpolated();

            if (st.Parameters.Count < 4)
            {
                throw new ParseException(st.Parameters[st.Parameters.Count - 1], "At least 2 points expected", false);
            }
            if (st.Parameters.Count % 2 != 0)
            {
                throw new ParseException(st.Parameters[st.Parameters.Count - 1], "Value expected", false);
            }
            ip.Time  = new double[st.Parameters.Count / 2];
            ip.Value = new double[st.Parameters.Count / 2];
            for (int i = 0; i < st.Parameters.Count / 2; i++)
            {
                ip.Time[i]  = netlist.ParseDouble(st.Parameters[i * 2]);
                ip.Value[i] = netlist.ParseDouble(st.Parameters[i * 2 + 1]);
            }

            Generated = ip;
            return(true);
        }
 void Start()
 {
     interpolated = gameObject.AddComponent <Interpolated>();
 }
示例#6
0
 /// Linear interpolation of XPos.
 public static XPos Lerp(this Interpolated <XPos> lerp, float alpha)
 {
     return(XPos.Lerp(alpha, lerp.V0, lerp.V1));
 }
示例#7
0
 /// Linear interpolation of float.
 public static float Lerp(this Interpolated <float> lerp, float alpha)
 {
     return(lerp.V0 * (1 - alpha) + lerp.V1 * alpha);
 }
示例#8
0
        /// <summary>
        /// Updates controls when the target animation has changed.
        /// Does nothing if the type does not match the current target type.
        /// </summary>
        public void AnimChanged(NW4RAnimType type)
        {
            if (type != TargetAnimType && type != NW4RAnimType.None)
            {
                return;
            }

            UpdateEditor();
            UpdateKeyframePanel();

            NW4RAnimationNode node = GetAnimation(type);

            if (node == null)
            {
                _maxFrame           = 0;
                EnableTransformEdit = true;

                _updating = true;

                PlaybackPanel.numFrameIndex.Maximum            = _maxFrame;
                PlaybackPanel.numTotalFrames.Minimum           = 0;
                PlaybackPanel.numTotalFrames.Value             = 0;
                PlaybackPanel.btnPlay.Enabled                  =
                    PlaybackPanel.numTotalFrames.Enabled       =
                        PlaybackPanel.numFrameIndex.Enabled    =
                            PlaybackPanel.btnLast.Enabled      =
                                PlaybackPanel.btnFirst.Enabled =
                                    PlaybackPanel.Enabled      = false;

                _updating = false;

                GetFiles(NW4RAnimType.None);
                SetFrame(0);
            }
            else
            {
                int loopBias = node.Loop && Interpolated.Contains(node.GetType()) ? 1 : 0;

                _maxFrame           = node.FrameCount;
                EnableTransformEdit = !_playing;

                _updating = true;

                PlaybackPanel.btnPlay.Enabled                =
                    PlaybackPanel.numFrameIndex.Enabled      =
                        PlaybackPanel.numTotalFrames.Enabled =
                            PlaybackPanel.Enabled            = true;
                PlaybackPanel.numTotalFrames.Minimum         = loopBias + 1;
                PlaybackPanel.numTotalFrames.Value           = (decimal)(_maxFrame + loopBias);
                PlaybackPanel.numFrameIndex.Maximum          = (decimal)(_maxFrame + loopBias);

                _updating = false;

                GetFiles(TargetAnimType);
                SetFrame(1);
            }

            //UpdateModel();
            //UpdatePropDisplay();
            OnAnimationChanged();
        }