2012-01-16 26 views
0

モデルの起点ではなく、スキンモデルの骨をどのように回転させるのですか?スキンモデルのボーンを正しく回転させるには? XNA

SkinningSampleでは、私は男の前腕を回転させると、モデルの起源と思われるものの周りを回転します。可能であれば、自分の起源の周りで骨を回転させたいと思います。

GetSkinTransforms()ための説明が書かれています:

は、「現在の骨が変換行列を取得し、スキニング バインドの相対ポーズ。」

だから私はそれが問題かもしれないと思う。誰もがこれらの変換をどのように変換する必要があるかを知っていますか?

ここにはSkinningSampleの一部が含まれています。

float rotation = 0; 
    protected override void Update(GameTime gameTime) 
    { 
     HandleInput(); 

     UpdateCamera(gameTime); 

     animationPlayer.UpdateWorldTransforms(Matrix.Identity); 
     animationPlayer.UpdateSkinTransforms(); 

     Matrix RotationTransform = Matrix.CreateFromYawPitchRoll(rotation, 0, 0) ; 
     animationPlayer.GetSkinTransforms().SetValue(RotationTransform, 34); 

     rotation = rotation + .1f; 
     base.Update(gameTime); 
    } 


    /// <summary> 
    /// This is called when the game should draw itself. 
    /// </summary> 
    protected override void Draw(GameTime gameTime) 
    { 
     GraphicsDevice device = graphics.GraphicsDevice; 

     device.Clear(Color.CornflowerBlue); 

     Matrix[] bones = animationPlayer.GetSkinTransforms(); 

     // Compute camera matrices. 
     Matrix view = Matrix.CreateTranslation(0, -40, 0) * 
         Matrix.CreateRotationY(MathHelper.ToRadians(cameraRotation)) * 
         Matrix.CreateRotationX(MathHelper.ToRadians(cameraArc)) * 
         Matrix.CreateLookAt(new Vector3(0, 0, -cameraDistance), 
              new Vector3(0, 0, 0), Vector3.Up); 

     Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, 
                   device.Viewport.AspectRatio, 
                   1, 
                   10000); 

     // Render the skinned mesh. 
     foreach (ModelMesh mesh in currentModel.Meshes) 
     { 
      foreach (SkinnedEffect effect in mesh.Effects) 
      { 
       effect.SetBoneTransforms(bones); 

       effect.View = view; 
       effect.Projection = projection; 

       effect.EnableDefaultLighting(); 

       effect.SpecularColor = new Vector3(0.25f); 
       effect.SpecularPower = 16; 
      } 

      mesh.Draw(); 
     } 

     base.Draw(gameTime); 
    } 

答えて

0

skinTransformではなく、boneTransformを変換する必要があります。私はちょうどこの操作を可能にするためにAnimationPlayerクラスの別のメソッドを作成しました:

public void TransformBone(Matrix BoneAlteration, int BoneID) 
{ 
    boneTransform[BoneID] = BoneAlteration * bindPose[BoneID]; 
    UpdateWorldTransforms(Matrix.Identity); 
    UpdateSkinTransforms(); 
} 

私は骨を回転させたかったのであれば、私は正しいskinTransformationマトリックスを作成するには、このメソッドを呼び出すと思います。これは、他のboneTransformsが正しい位置に設定されていることを前提としています。既に回転した骨について回転させたい場合は、bindPoseをboneTransformに置き換えることもできると思います。

関連する問題