2013-04-20 28 views
0

我有一個項目很快就會到期,而且我有很多問題試圖加載我在3D Studio Max中製作的模型。我製作的模型就是我想要的XNA遊戲中的地形。以下是我迄今所做的:錯誤地在XNA中加載地形+第一人稱攝像頭

方法:

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加載模型時,它只是加載窗口中的一個大塊。

我不知道我在做什麼,使模型像這樣加載,但它讓我拉我的頭髮。任何幫助,將不勝感激。

此外,任何人都可以指導我走路/指導或創建第一人稱射擊照相機的課程,因爲那是我要玩的遊戲。我可能不應該選那個,但現在改變已經太遲了,所以如果你能在那裏幫助,你真的會拯救我的皮膚!

謝謝,傑克!

回答

0

模型中是否有多個網格,如果是,是否嘗試過分別渲染每個網格? 你有沒有嘗試過使用身份矩陣的世界和觀點,以確保這些不是問題? 我假設你還沒有做任何其他狀態更改爲XNA/DirectX,如果是這樣嘗試禁用這些。

對於FPS相機,您可以跟蹤浮動變量中的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(); 

相機始終處於倒置,因爲右向左移動的移動世界,左轉轉的世界第一右等