public void TestPlayAnimation()
        {
            var controller = new AnimationControllerSkeleton(null);

            Skeleton skeleton;

            TheWizards.Animation.Animation animation;
            CreateTestAnimation(out skeleton, out animation);

            controller.SetAnimation(0, animation);

            var p = new Vector3(4, 5, 4);

            var m1 = Matrix.RotationAxis(Vector3.Normalize(new Vector3(-1, 4, 3)), 4) * Matrix.Translation(p);
            var m2 = Matrix.RotationAxis(Vector3.Normalize(new Vector3(3, 2, 8)), 4) * Matrix.Translation(p);

            var game       = new DX11Game();
            var visualizer = new SkeletonVisualizer();

            game.GameLoopEvent += delegate
            {
                controller.ProgressTime(game.Elapsed);
                controller.UpdateSkeleton();
                skeleton.UpdateAbsoluteMatrices();
                visualizer.VisualizeSkeleton(game, skeleton);
            };

            game.Run();
        }
        public void TestImportAMCCreateRelativeMatrices()
        {
            AMCParser parser = new AMCParser();

            using (var strm = EmbeddedFile.GetStream("MHGameWork.TheWizards.Tests.Features.Simulation.Animation.Files.TestAnimation02.amc"))
            {
                parser.ImportAMC(strm);
            }

            // Import skeleton
            var asfParser = new ASFParser();

            using (var strm = EmbeddedFile.GetStream("MHGameWork.TheWizards.Tests.Features.Simulation.Animation.Files.TestSkeleton02.asf"))
            {
                asfParser.ImportASF(strm);
            }
            var skeleton = asfParser.ImportSkeleton();


            var game = new DX11Game();
            var vis  = new SkeletonVisualizer();

            for (int i = 0; i < skeleton.Joints.Count; i++)
            {
                skeleton.Joints[i].RelativeMatrix = Matrix.Identity;
            }

            float time  = 0;
            float speed = 1;

            game.GameLoopEvent += delegate
            {
                game.LineManager3D.DrawGroundShadows = true;

                time += game.Elapsed;
                var sampleNum = (int)(time * 120 * speed) % parser.Samples.Count;

                for (int i = 0; i < parser.Samples[sampleNum].Segments.Count; i++)
                {
                    var seg = parser.Samples[sampleNum].Segments[i];

                    var asfJoint = asfParser.Joints.Find(j => j.name == seg.JointName);
                    var joint    = skeleton.Joints.Find(j => j.Name == seg.JointName);

                    Matrix relativeMat = parser.CalculateRelativeMatrix(seg, asfJoint);

                    joint.RelativeMatrix = relativeMat;
                }
                skeleton.UpdateAbsoluteMatrices();

                vis.VisualizeSkeleton(game, skeleton, new Vector3(4, 0, 4));
            };

            game.Run();
        }
        public void TestSkeletonVisualizer()
        {
            var game = new DX11Game();

            var   skeleton = new Skeleton();
            Joint joint;

            joint                = new Joint();
            joint.Name           = "Root";
            joint.Length         = 2;
            joint.AbsoluteMatrix = Matrix.RotationZ(MathHelper.PiOver2) * // This makes X the forward direction
                                   Matrix.Translation(5, 0, 5);
            skeleton.Joints.Add(joint);

            var parent = joint;

            joint                = new Joint();
            joint.Name           = "Arm1";
            joint.Length         = 2;
            joint.Parent         = parent;
            joint.AbsoluteMatrix = Matrix.RotationZ(MathHelper.PiOver4) * Matrix.Translation(4, 0, 0)
                                   * joint.Parent.AbsoluteMatrix;
            skeleton.Joints.Add(joint);

            joint                = new Joint();
            joint.Name           = "Arm2Upper";
            joint.Length         = 2;
            joint.Parent         = parent;
            joint.AbsoluteMatrix = Matrix.RotationZ(-MathHelper.PiOver4) * Matrix.Translation(4, 0, 0)
                                   * joint.Parent.AbsoluteMatrix;
            skeleton.Joints.Add(joint);

            parent = joint;

            joint                = new Joint();
            joint.Name           = "Arm2Lower";
            joint.Length         = 2;
            joint.Parent         = parent;
            joint.AbsoluteMatrix = Matrix.RotationZ(MathHelper.PiOver4) * Matrix.Translation(2, 0, 0)
                                   * joint.Parent.AbsoluteMatrix;
            skeleton.Joints.Add(joint);


            var vis = new SkeletonVisualizer();



            game.GameLoopEvent += delegate
            {
                vis.VisualizeSkeleton(game, skeleton);
            };

            game.Run();
        }
        public void TestSkeletonUpdateAbsoluteMatrices()
        {
            var game = new DX11Game();

            var   skeleton = new Skeleton();
            Joint joint;

            joint        = new Joint();
            joint.Name   = "Root";
            joint.Length = 4;
            joint.CalculateInitialRelativeMatrix(Matrix.Translation(5, 0, 5));
            skeleton.Joints.Add(joint);

            var parent = joint;

            joint        = new Joint();
            joint.Name   = "Arm1";
            joint.Length = 2;
            joint.Parent = parent;
            joint.CalculateInitialRelativeMatrix(Matrix.RotationZ(MathHelper.PiOver4));
            skeleton.Joints.Add(joint);

            joint        = new Joint();
            joint.Name   = "Arm2Upper";
            joint.Length = 2;
            joint.Parent = parent;
            joint.CalculateInitialRelativeMatrix(Matrix.RotationZ(-MathHelper.PiOver4));
            skeleton.Joints.Add(joint);

            parent = joint;

            joint        = new Joint();
            joint.Name   = "Arm2Lower";
            joint.Length = 2;
            joint.Parent = parent;
            joint.CalculateInitialRelativeMatrix(Matrix.RotationY(MathHelper.PiOver4));
            skeleton.Joints.Add(joint);


            var vis = new SkeletonVisualizer();

            skeleton.UpdateAbsoluteMatrices();

            game.GameLoopEvent += delegate
            {
                vis.VisualizeSkeleton(game, skeleton);
            };

            game.Run();
        }
        public void TestImportSkeletonFromASF()
        {
            var parser = new ASFParser();


            var root = new ASFJoint();

            parser.RootJoint = root;

            var child1 = new ASFJoint();

            child1.length    = 4;
            child1.direction = MathHelper.Up;
            root.children.Add(child1);

            var child2 = new ASFJoint();

            child2.direction = MathHelper.Up;
            child1.children.Add(child2);

            var skeleton1 = parser.ImportSkeleton();

            skeleton1.UpdateAbsoluteMatrices();

            using (var strm = EmbeddedFile.GetStream("MHGameWork.TheWizards.Tests.Features.Simulation.Animation.Files.TestSkeleton01.asf"))
            {
                parser.ImportASF(strm);
            }
            var skeleton2 = parser.ImportSkeleton();

            skeleton2.UpdateAbsoluteMatrices();

            var game = new DX11Game();
            var vis  = new SkeletonVisualizer();

            game.GameLoopEvent += delegate
            {
                vis.VisualizeSkeleton(game, skeleton1, new Vector3(4, 0, 4));
                vis.VisualizeSkeleton(game, skeleton2, new Vector3(11, 0, 11));
            };

            game.Run();
        }