Ejemplo n.º 1
0
        void timer_Tick(object sender, EventArgs e)
        {
            if (OpenedFrames != null)
            {
                var frame = OpenedFrames[index];
                var frame_old = OpenedFrames[index-1];

                double x = frame.X - frame_old.X;
                double y = frame.Y - frame_old.Y;

                canvas1.Children.Clear();
                canvas2.Children.Clear();
                Ellipse el = new Ellipse();
                el.Width = 10;
                el.Height = 10;
                el.Fill = new SolidColorBrush(Colors.Green);
                Canvas.SetLeft(el, off_x +   x / c_max);
                Canvas.SetTop(el, off_y +   y / c_max);
                el.InvalidateVisual();
                canvas1.Children.Add(el);

                int center = (int)JointType.HipCenter;
                var hip = frame.Nodes.FirstOrDefault(o=>o.NodeType==center);


                //frame.Nodes.Where(o=>legs_int.Contains(o.NodeType)).Zip(frame_old.Nodes.Where(o=>legs_int.Contains(o.NodeType)), (e1, e2) =>
                //{

                //    SkeletonNode n = new SkeletonNode();

                //    double deg = Math.PI / 2;

                //    n.X = (e1.X + e1.Z * Math.Tan(deg)) / Math.Sqrt(1 + Math.Tan(deg) * Math.Tan(deg));
                //    n.Y = e1.Y ;


                //    Point a = new Point();
                //    a.X = e1.X - x;
                //    a.Y = e1.Y - y;
                //    //a.X = e1.X - x - hip.X;
                //    //a.Y = e1.Y - y - hip.Y;
                //    //rotation

                //    a.X = n.X - x;
                //    a.Y = n.Y - y;

                //    SolidColorBrush b = new SolidColorBrush(Colors.Black);
                //    if(leg_right.Contains(e1.NodeType))
                //        b = new SolidColorBrush(Colors.Red);
                //    else
                //        b = new SolidColorBrush(Colors.Blue);
                //    return new { X=a.X,Y=a.Y,br=b };
                //}).ToList().ForEach(o =>
                //{
                //    el = new Ellipse();
                //    el.Width = 10;
                //    el.Height = 10;
                //    el.Fill = o.br;
                //    Canvas.SetLeft(el, off_x +  o.X * 100);
                //    Canvas.SetTop(el, off_y -  o.Y * 100);
                //    canvas1.Children.Add(el);
                    
                //});


                frame.Nodes.Where(o => legs_int.Contains(o.NodeType)).ToList().ForEach(o =>
                {
                    SkeletonNode n = new SkeletonNode();
                    SkeletonNode nhip = new SkeletonNode();

                    double deg =  Math.PI / 2;

                    n.X = (o.X + o.Z * Math.Tan(deg)) / Math.Sqrt(1 + Math.Tan(deg) * Math.Tan(deg));
                    n.Y = o.Y;


                    nhip.X = (hip.X + hip.Z * Math.Tan(deg)) / Math.Sqrt(1 + Math.Tan(deg) * Math.Tan(deg));
                    nhip.Y = hip.Y;


                    Point a = new Point();
                    Point a1 = new Point();
                    a.X = o.X - x;
                    a.Y = o.Y - y;
                    a.X = o.X  - hip.X;
                    a.Y = o.Y  - hip.Y;
                    //rotation


                    a1.X = n.X  -nhip.X;
                    a1.Y = n.Y  - nhip.Y;

                    SolidColorBrush b = new SolidColorBrush(Colors.Black);
                   
                    if (leg_right.Contains(o.NodeType))
                        b = new SolidColorBrush(Colors.Red);
                    else
                        b = new SolidColorBrush(Colors.Blue);

                    el = new Ellipse();
                    el.Width = 10;
                    el.Height = 10;
                    el.Fill = b;
                    Canvas.SetLeft(el, off_x + a.X * 100);
                    Canvas.SetTop(el, off_y - a.Y * 100);
                    canvas1.Children.Add(el);

                    el = new Ellipse();
                    el.Width = 10;
                    el.Height = 10;
                    el.Fill = b;
                    Canvas.SetLeft(el, off_x + a1.X * 100);
                    Canvas.SetTop(el, off_y - a1.Y * 100);
                    canvas2.Children.Add(el);

                });

                
                
                label1.Content = index++;
                UpdateLayout();
            }
        }