private static void ConvertJointFrame(JointFrame jfDest, string jointName, FrameElement srcFrame)
        {
            Matrix3D matrix;

            switch (jointName)
            {
            case "hip":
                matrix = jfDest.Matrix;
                JointFrame jfRoot     = srcFrame.GetJointFrame("root");
                Matrix3D   rootMatrix = jfRoot.Matrix;
                rootMatrix.OffsetX *= 4;
                rootMatrix.OffsetY *= 4;
                rootMatrix.OffsetZ *= 4;
                rootMatrix.OffsetY += 12;
                matrix.Append(rootMatrix);
                jfDest.Matrix = matrix;
                break;

            case "abdomen":
                matrix = jfDest.Matrix;
                JointFrame jfLower     = srcFrame.GetJointFrame("lower_body");
                Matrix3D   lowerMatrix = jfLower.Matrix;
                lowerMatrix.Invert();
                matrix.Append(lowerMatrix);
                jfDest.Matrix = matrix;
                break;

            case "lShldr":
                matrix = jfDest.Matrix;
                matrix.RotatePrepend(new Quaternion(new Vector3D(0, 0, 1), -35));
                jfDest.Matrix = matrix;
                break;

            case "lForeArm":
            case "lHand":
                matrix = jfDest.Matrix;
                matrix.RotatePrepend(new Quaternion(new Vector3D(0, 0, 1), -35));
                matrix.Rotate(new Quaternion(new Vector3D(0, 0, 1), 35));
                jfDest.Matrix = matrix;
                break;

            case "rShldr":
                // jfDest.AddValue("Zrotation", 35);
                matrix = jfDest.Matrix;
                matrix.RotatePrepend(new Quaternion(new Vector3D(0, 0, 1), 35));
                jfDest.Matrix = matrix;
                break;

            case "rForeArm":
            case "rHand":
                matrix = jfDest.Matrix;
                matrix.RotatePrepend(new Quaternion(new Vector3D(0, 0, 1), 35));
                matrix.Rotate(new Quaternion(new Vector3D(0, 0, 1), -35));
                jfDest.Matrix = matrix;
                break;
            }
        }
        private void UpdateFrame()
        {
            if (m_bvh == null)
            {
                return;
            }

            FrameElement frame = m_bvh.FrameList[(int)slider1.Value];

            foreach (CompositeElement joint in m_bvh.JointList)
            {
                JointFrame        jf        = frame.GetJointFrame(joint.Name);
                Transform3DGroup  tg        = (Transform3DGroup)joint.Visual.Transform;
                MatrixTransform3D transform = (MatrixTransform3D)tg.Children[0];
                transform.Matrix = jf.Matrix;
            }
        }
        public BVH Convert()
        {
            BVH dest = SLTemplate();

            dest.Frames.Value    = m_src.Frames.Value + 1;
            dest.FrameTime.Value = m_src.FrameTime.Value;
            dest.FrameList.Clear();

            FrameElement firstFrame = new FrameElement(dest);

            firstFrame.GetJointFrame("hip").SetValue("Yposition", 43.5285);
            dest.FrameList.Add(firstFrame);

            foreach (FrameElement frame in m_src.FrameList)
            {
                dest.FrameList.Add(ConvertFrame(dest, frame));
            }

            return(dest);
        }
        private FrameElement ConvertFrame(BVH dest, FrameElement srcFrame)
        {
            FrameElement destFrame = new FrameElement(dest);

            foreach (CompositeElement joint in dest.JointList)
            {
                JointFrame jfDest = destFrame.GetJointFrame(joint.Name);
                JointFrame jfSrc  = srcFrame.GetJointFrame(GetSrcJointName(joint.Name));
                if (jfSrc == null)
                {
                    continue;
                }

                foreach (string channel in new string[] { "Zrotation", "Xrotation", "Yrotation" })
                {
                    jfDest.SetValue(channel, jfSrc.GetValue(channel));
                }

                ConvertJointFrame(jfDest, joint.Name, srcFrame);
            }
            return(destFrame);
        }