2013-04-20 3 views
0

프로젝트가 곧 완료 될 예정이며 3D Studio Max에서 만든 모델을로드하는 데 많은 문제가 있습니다. 내가 만든 모델은 내 XNA 게임에서 내 지형으로 원하는 것입니다. 내가 원하는 다음XNA에서 지형로드가 잘못됨 + 1 인칭 카메라

GraphicsDeviceManager graphics; 
    SpriteBatch spriteBatch; 

    Model terrainModel; 
    Vector3 terrainPosition = Vector3.Zero; 

    Vector3 cameraPosition = new Vector3(0.0f, 60.0f, 160.0f); 
    Vector3 cameraLookAt = new Vector3(0.0f, 60.0f, 160.0f); 
    Matrix cameraProjectionMatrix; 
    Matrix cameraViewMatrix; 

LoadContent()

 spriteBatch = new SpriteBatch(GraphicsDevice); 

     cameraViewMatrix = Matrix.CreateLookAt(
      cameraPosition, 
      Vector3.Zero, 
      Vector3.Up); 

     cameraProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(
      MathHelper.ToRadians(80.0f), 
      graphics.GraphicsDevice.Viewport.AspectRatio, 
      1.0f, 
      1000.0f); 

     terrainModel = Content.Load<Model>("alphastreet"); 

그리기 (GameTime gameTime)

GraphicsDevice.Clear(Color.CornflowerBlue); 

     DrawModel(terrainModel, terrainPosition); 

     // TODO: Add your drawing code here 

     base.Draw(gameTime); 

그리고 :

방법을 : 여기에 지금까지 한 일이다 그리기 :

void DrawModel(Model model, Vector3 modelPosition) 
    { 
     foreach (ModelMesh mesh in model.Meshes) 
     { 
      foreach (BasicEffect effect in mesh.Effects) 
      { 
       effect.EnableDefaultLighting(); 
       effect.PreferPerPixelLighting = true; 

       effect.World = Matrix.CreateTranslation(modelPosition); 
       effect.Projection = cameraProjectionMatrix; 
       effect.View = cameraViewMatrix; 
      } 
      mesh.Draw(); 
     } 
    } 

다른 모든 것은 XNA 파일이 보여야하는 것과 같습니다. 모델 자체는 상당히 직선적 인 거리처럼 보입니다. 그러나 XNA가 모델을로드하면 모델은로드되는 창에서 큰 블록 일뿐입니다.

나는 모델로드를 이렇게 만들고있는 것이 무엇인지 모르지만, 내 머리카락을 내쫓고 있습니다. 어떤 도움을 주시면 감사하겠습니다.

또한 누구나 나를 walk-through/guide 나 First Person Shooter 카메라를 만드는 수업으로 안내 할 수 있습니까? 그게 바로 제가 할 게임이기 때문입니다. 나는 아마 그것을 골라서는 안된다. 그러나 그것은 지금 바뀌는 것이 너무나 늦다. 그래서 만일 당신도 거기에서 도울 수 있으면 당신은 정말로 나의 피부를 절약 할 것이다!

감사합니다. Jake!

답변

0

모델에 하나 이상의 메쉬가 있습니까? 그렇다면 각각 별도로 렌더링 해 보았습니까? 월드와 뷰에 대한 항등 행렬을 사용해 보았지만 문제가 아닌지 확인해 봤습니까? xna/directx를 다른 상태로 변경하지 않았다고 가정합니다.

FPS 카메라의 경우 float 변수에서 x 및 y 회전을 추적하고 마우스가 x 및 y에서 얼마나 멀리 이동했는지에 따라 각 프레임을 업데이트 할 수 있습니다. 이것들로부터 카메라 뷰 매트릭스를 생성 할 수 있습니다. 다음과 같은 : 카메라가 항상 오른쪽에서 왼쪽으로 이동에게 세계를 이동하기 때문에 반전

var mx = Matrix.CreateRotationX(xangle); 
var my = Matrix.CreateRotationY(yangle); 
var pos = Matrix.CreateTranslation(position); 
var view = mx * my * pos; // These might be in the wrong order, not sure off the top of my head 
view.Invert(); 

는 회전 왼쪽, 오른쪽 등 세계를 회전

관련 문제