2012-04-05 2 views
1

블렌더에서 개별 메쉬가있는 모델을 만들었습니다. Xna 프로젝트에 넣을 때 Matrix 변환을 통해 모델을 이동하려고하면 모든 개별 메쉬가 개별 방향으로 이동합니다. 내 코드는 기본적으로 각 메쉬를 개별적으로 업데이트합니다. 모델의 메쉬가 함께 움직이는데 사용하는 것이 더 나은 코드가 있습니까?전체적으로 Xna에서 모델을 이동하는 방법은 무엇입니까?

답변

0

이 호출하는 경우 :

private void DrawModel(Model model, Matrix worldMatrix) 
    { 
     //Matrix array for number of bones 
     Matrix[] modelTransformations = new Matrix[model.Bones.Count]; 

     //Put bones into matrix array 
     model.CopyAbsoluteBoneTransformsTo(modelTransformations); 

     //for every model 
     foreach (ModelMesh mesh in model.Meshes) 
     { 
      foreach (BasicEffect effect in mesh.Effects) 
      { 
       //Add default lighting 
       effect.EnableDefaultLighting(); 

       //Set default postion 
       effect.World = modelTransformations[mesh.ParentBone.Index] * worldMatrix; 

       //Set view 
       effect.View = camera.viewMatrix; 

       //Set projection 
       effect.Projection = camera.projectionMatrix; 
      } 

      //Draw Model 
      mesh.Draw(); 
     } 
    } 

그리고 당신이 이런 식으로 넣어 세계 매트릭스를 번역 :

modelWorld *= Matrix.CreateTranslation(XDir, YDir, ZDir); 

당신은 아무런 문제가 없습니다. 적어도, 그렇게하는 방법입니다.

관련 문제