2012-01-09 2 views
0

부모 뼈와 변환 된 오프셋이있는 모델이 있습니다 (부모 뼈의 꼬리에 위치하지 않음). Blender에서는 모델이 만들어진 곳에서 뼈를 회전시키고 첨부 된 메쉬가 올바르게 회전하는지 확인할 수 있습니다. 그러나 코드에서 뼈대를 회전하려고하면 부모의 꼬리 부분을 회전시킵니다. 나는 매트릭스 수학 (내 최악의 적)에서 뭔가를 망칠거야.XNA 오프셋 변환을 사용하여 뼈 회전

업데이트 :이 중요한 경우

protected override void Update(GameTime gameTime) 
    { 
     bone.Transform = Matrix.CreateFromYawPitchRoll(0f, 0.5f, 0f); 

     base.Update(gameTime); 
    } 

예쁜 표준이 있지만, 그리기 :

private void DrawModel(Model model, GraphicsDevice graphics, Matrix viewMatrix, Matrix projectionMatrix) 
    { 
     Matrix[] boneTransforms = new Matrix[model.Bones.Count]; 
     model.CopyAbsoluteBoneTransformsTo(boneTransforms); 

     Matrix worldMatrix = orientation * Matrix.CreateTranslation(position); 

     foreach (ModelMesh mesh in model.Meshes) 
     { 
      foreach (BasicEffect effect in mesh.Effects) 
      { 
       effect.World = boneTransforms[mesh.ParentBone.Index] * worldMatrix; 
       effect.View = viewMatrix; 
       effect.Projection = projectionMatrix; 

       effect.EnableDefaultLighting(); 
       effect.PreferPerPixelLighting = true; 

       // Set the fog to match the black background color 
       effect.FogEnabled = true; 
       effect.FogColor = Vector3.Zero; 
       effect.FogStart = 1000; 
       effect.FogEnd = 3200; 
      } 
      mesh.Draw(); 
     } 
    } 

여기 스크린 샷을 http://s1231.photobucket.com/albums/ee516/Neovivacity/?action=view&current=boneRotation.png

+0

이 아마도 당신이 worldMatrix이 먼저 있도록 곱셈의 순서를 변경해야합니다

여기 내 솔루션의 코드 단편이다? 확실하지 않지만 시도해 볼 수 있습니다. – annonymously

답변

1

확인 문제를 보여주기 위해,이하지 않을 수 있습니다 이 문제를 해결하는 가장 간단한 방법이지만 비슷한 문제가있는 사람을위한 해결책이 있습니다.

모델을로드 할 때 원본 변형을 저장하십시오. 그런 다음 당신은 내가 한 것처럼 뼈의 변형을 증폭시킵니다. 마지막으로 원래 변환 인 Translation, oringalTranform.Translation을 얻고 뼈의 새로운 변환을 얻습니다. 오프셋을 조정하려면 bone.Transform * = Matrix.CreateTranslation (originalTranslation - newTranslation)을 조정하십시오.

public void LoadContent(ContentManager content) 
    { 
     Model = content.Load<Model>(ModelName); 
     //Set the Bone pointers and transform matrices 
     AileronLBone = Model.Bones["LAileron"]; 
     AileronRBone = Model.Bones["RAileron"]; 
     ElevatorBone = Model.Bones["Elevator"]; 
     RudderBone = Model.Bones["Rudder"]; 
     FlapsBone = Model.Bones["Flaps"]; 
     if (AileronLBone != null) AileronLTransform = AileronLBone.Transform; 
     if (AileronRBone != null) AileronRTransform = AileronRBone.Transform; 
     if (ElevatorBone != null) ElevatorTransform = ElevatorBone.Transform; 
     if (RudderBone != null) RudderTransform = RudderBone.Transform; 
     if (FlapsBone != null) FlapsTransform = FlapsBone.Transform; 
    } 

    public void Update(GameTime gameTime) 
    { 
     SetOffsetRotation(ElevatorBone, ElevatorTransform, ElevatorRotation); 
    } 

    public void SetOffsetRotation(ModelBone bone, Matrix transform, float rotation) 
    { 
     Vector3 oringalTrans = transform.Translation; 
     bone.Transform *= Matrix.CreateRotationX(rotation); 
     Vector3 newTrans = bone.Transform.Translation; 
     bone.Transform *= Matrix.CreateTranslation(oringalTrans - newTrans); 
    } 
관련 문제