예제 #1
0
    public JacobianTransposeIKSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      var modelNode = ContentManager.Load<ModelNode>("Dude/Dude");
      _meshNode = modelNode.GetSubtree().OfType<MeshNode>().First().Clone();
      _meshNode.PoseLocal = new Pose(new Vector3F(0, 0, 0));
      SampleHelper.EnablePerPixelLighting(_meshNode);
      GraphicsScreen.Scene.Children.Add(_meshNode);

      // Create the IK solver. The JacobianTranspose method can solve long bone chains with 
      // limits. It allocates heap memory as is not recommended for performance critical 
      // console or phone games.
      _ikSolver = new JacobianTransposeIKSolver
      {
        SkeletonPose = _meshNode.SkeletonPose,

        // The chain starts at the upper arm.
        RootBoneIndex = 13,

        // The chain ends at the hand bone.
        TipBoneIndex = 15,

        // The offset from the hand center to the hand origin.
        TipOffset = new Vector3F(0.1f, 0, 0),

        // This solver uses an iterative method and will make up to 100 iterations if necessary.
        NumberOfIterations = 100,

        // This parameter must be hand-tuned. Make it too large and the solver is unstable.
        // Make it too low and the solver needs a crazy amount of iterations.
        StepSize = 1,

        // A method that applies bone limits.
        LimitBoneTransforms = LimitBoneTransform,
      };
    }
        protected override void LoadContent()
        {
            _model = Game.Content.Load<Model>("Dude");
              var additionalData = (Dictionary<string, object>)_model.Tag;
              var skeleton = (Skeleton)additionalData["Skeleton"];
              _skeletonPose = SkeletonPose.Create(skeleton);

              // Create the IK solver. The JacobianTranspose method can solve long bone chains with
              // limits. It allocates heap memory as is not recommended for performance critical
              // console or phone games.
              _ikSolver = new JacobianTransposeIKSolver
              {
            SkeletonPose = _skeletonPose,

            // The chain starts at the upper arm.
            RootBoneIndex = 13,

            // The chain ends at the hand bone.
            TipBoneIndex = 15,

            // The offset from the hand center to the hand origin.
            TipOffset = new Vector3F(0.1f, 0, 0),

            // This solver uses an iterative method and will make up to 100 iterations if necessary.
            NumberOfIterations = 100,

            // This parameter must be hand-tuned. Make it too large and the solver is unstable.
            // Make it too low and the solver needs a crazy amount of iterations.
            StepSize = 1,

            // A method that applies bone limits.
            LimitBoneTransforms = LimitBoneTransform,
              };

              base.LoadContent();
        }