示例#1
0
        public void Play(Robot r, Action onComplete, int repeats, float speed)
        {
            //Console.WriteLine("here");
            Thread t = new Thread(() =>
            {
                repeats++;
                while (repeats > 0)
                {
                    long startT = Time.Millis();
                    long playT  = startT;
                    //Console.WriteLine(Keyframes.Count);
                    LinkedListNode <Keyframe> node = Keyframes.First;
                    while (node != null)
                    {
                        Keyframe k = node.Value;

                        lock (this)
                        {
                            if (!isPlaying)
                            {
                                break;
                            }
                        }

                        long currT = (long)((Time.Millis() - startT) * speed);

                        long nextT = k.GetTime();
                        if (currT < nextT)
                        {
                            long total   = nextT - playT;
                            long running = currT - playT;
                            k.Step((float)running / (float)total, r);
                            Thread.Sleep(16);
                            continue;
                        }
                        else
                        {
                            playT = currT;
                        }
                        //Console.WriteLine(k.ToString());
                        k.DoAction(r);
                        node = node.Next;
                    }

                    repeats--;
                }

                onComplete();
            });

            lock (this)
            {
                isPlaying = true;
            }
            t.Start();
        }
示例#2
0
        private static void SaveKeyframe(Keyframe frame, XmlWriter writer)
        {
            writer.WriteStartElement(TOKEN_KEYFRAME);

            writer.WriteAttributeString(TOKEN_TIME, frame.GetTime().ToString());

            writer.WriteStartElement(TOKEN_KEYFRAME_TRANSLATION);
            writer.WriteAttributeString("x", frame.GetTranslation().x.ToString());
            writer.WriteAttributeString("y", frame.GetTranslation().y.ToString());
            writer.WriteAttributeString("z", frame.GetTranslation().z.ToString());
            writer.WriteEndElement();

            writer.WriteStartElement(TOKEN_KEYFRAME_ROTATION);
            writer.WriteAttributeString("x", frame.GetRotation().x.ToString());
            writer.WriteAttributeString("y", frame.GetRotation().y.ToString());
            writer.WriteAttributeString("z", frame.GetRotation().z.ToString());
            writer.WriteAttributeString("w", frame.GetRotation().w.ToString());
            writer.WriteEndElement();

            writer.WriteEndElement();
        }
示例#3
0
        private static void SaveKeyframe(Keyframe frame, XmlWriter writer)
        {
            writer.WriteStartElement(TOKEN_KEYFRAME);

            writer.WriteAttributeString(TOKEN_TIME, frame.GetTime().ToString());

            writer.WriteStartElement(TOKEN_KEYFRAME_TRANSLATION);
            writer.WriteAttributeString("x", frame.GetTranslation().x.ToString());
            writer.WriteAttributeString("y", frame.GetTranslation().y.ToString());
            writer.WriteAttributeString("z", frame.GetTranslation().z.ToString());
            writer.WriteEndElement();

            writer.WriteStartElement(TOKEN_KEYFRAME_ROTATION);
            writer.WriteAttributeString("x", frame.GetRotation().x.ToString());
            writer.WriteAttributeString("y", frame.GetRotation().y.ToString());
            writer.WriteAttributeString("z", frame.GetRotation().z.ToString());
            writer.WriteAttributeString("w", frame.GetRotation().w.ToString());
            writer.WriteEndElement();

            writer.WriteEndElement();
        }