Example #1
0
        private void PrepareData()
        {
            //����Ǽ�
            root = new Skeleton(new Bone("root"), null);
            root.Bone.RefPosition = new Vector2D(0.5, 0.5);
            root.Bone.SetLocalMatrix(Matrix.Transform2D(0.5, 0.5));

            c00 = new Skeleton(new Bone("c00"), root);
            c00.Bone.RefPosition = new Vector2D(0.5, 0.5);

            c10 = new Skeleton(new Bone("c10"), c00);
            c10.Bone.RefPosition = new Vector2D(0.5, 0.35);

            c20 = new Skeleton(new Bone("c20"), c10);
            c20.Bone.RefPosition = new Vector2D(0.5, 0.2);

            IList<Bone> bones = new List<Bone>();
            bones.Add(c00.Bone);
            bones.Add(c10.Bone);
            bones.Add(c20.Bone);

            IList<double> weights;

            double w0, w1, w2, totalw;

            //������Ƥ
            //����������Ƥ�����ߣ�Ȩ�ؾ���Ϊ������ƽ��
            verts = new List<Vertex>();
            for(int i = 0; i < 48; ++i)
            {
                Vector2D posl = new Vector2D(0.49, 0.51 - i * 0.01);
                Vector2D posr = new Vector2D(0.51, 0.51 - i * 0.01);

                weights = new List<double>();

                w0 = 1.0 / Vector2D.Subtract(posl, c00.Bone.RefPosition).GetLengthSquared();
                w1 = 1.0 / Vector2D.Subtract(posl, c10.Bone.RefPosition).GetLengthSquared();
                w2 = 1.0 / Vector2D.Subtract(posl, c20.Bone.RefPosition).GetLengthSquared();

                totalw = w0 + w1 + w2;
                w0 /= totalw;
                w1 /= totalw;
                w2 /= totalw;

                weights.Add(w0);
                weights.Add(w1);
                weights.Add(w2);

                Vertex vertl = new Vertex(posl, bones, weights);
                Vertex vertr = new Vertex(posr, bones, weights);

                verts.Add(vertl);
                verts.Add(vertr);
            }
        }
Example #2
0
        //�ݹ�Ļ����Ǽ���
        public static void DrawSkeletonDeep(Graphics g, Skeleton sk, int width, int height)
        {
            DrawSkeleton(g, sk, width, height);

            IList<Skeleton> children = sk.Children;
            if(children != null)
            {
                foreach(Skeleton child in children)
                {
                    DrawSkeletonDeep(g, child, width, height);
                }
            }
        }
Example #3
0
        public static void DrawSkeleton(Graphics g, Skeleton sk, int width, int height)
        {
            Pen p = new Pen(Color.Black, 1);
            Vector2D skpos;

            if (sk.Parent == null)
            {
                skpos = sk.Bone.RefPosition;
            }
            else
            {
                skpos = sk.Parent.Bone.TransformPosition(sk.Bone.RefPosition);
            }

            //������ǰ�����ڵ�

            Font font = new Font("Tahoma", 8);
            g.DrawString(
                sk.Bone.Name,
                font,
                Brushes.Black,
                (float)(width * skpos.X),
                (float)(height * skpos.Y)
                );

            //���������Σ��ѹ�����y�����ʾ������
            double refPosx = sk.Bone.RefPosition.X;
            double refPosy = sk.Bone.RefPosition.Y;

            Vector2D tri0 = sk.Bone.TransformPosition(
                new Vector2D(refPosx - 0.02, sk.Bone.RefPosition.Y)
                );
            Vector2D tri1 = sk.Bone.TransformPosition(
                new Vector2D(refPosx + 0.02, sk.Bone.RefPosition.Y)
                );
            Vector2D tri2 = sk.Bone.TransformPosition(
                new Vector2D(refPosx, sk.Bone.RefPosition.Y - 0.1)
                );
            g.DrawLine(
                p,
                (float)(width * tri0.X),
                (float)(height * tri0.Y),
                (float)(width * tri1.X),
                (float)(height * tri1.Y)
                );
            g.DrawLine(
                p,
                (float)(width * tri0.X),
                (float)(height * tri0.Y),
                (float)(width * tri2.X),
                (float)(height * tri2.Y)
                );
            g.DrawLine(
                p,
                (float)(width * tri2.X),
                (float)(height * tri2.Y),
                (float)(width * tri1.X),
                (float)(height * tri1.Y)
                );
            //}
        }
Example #4
0
 public void RemoveChild(Skeleton child)
 {
     if (m_children == null) return;
     m_children.Remove(child);
 }
Example #5
0
 public void AddChild(Skeleton child)
 {
     if (m_children == null)
     {
         m_children = new List<Skeleton>();
     }
     m_children.Add(child);
     child.m_parent = this;
 }
Example #6
0
        public Skeleton(Bone bone, Skeleton parent)
        {
            m_bone = bone;
            m_parent = parent;
            m_children = null;

            if (m_parent != null)
            {
                m_parent.AddChild(this);
            }
        }
Example #7
0
 public Skeleton()
 {
     m_parent = null;
     m_bone = new Bone("tmp");
     m_children = null;
 }