2011-03-05 37 views

回答

0

簡單的答案是否定的。如果您嘗試繪製無限數量的多邊形,您的內存不僅會用完,而且程序也會崩潰,但硬件會花費無限的時間渲染場景。

爲了解決這個問題,遊戲開發者使用天空盒和無法觸及的地形等技巧來讓玩家認爲世界是無限的。所以如果你想要一個具有重複地面紋理的有限世界,只需在網格中多次繪製地面紋理,並放置一個覆蓋地面外部邊緣的天空盒。

如果你真的想要一個無限的外觀世界,你可以做一個把戲,天空盒和地面隨你移動。因此,只需將地面和天空盒的速度設置爲正在移動的精靈的速度即可。

0

就這樣!這是我的自定義樣本。您可以從具有不同紋理的矩陣索引重複模型

//Draw a ground land 
    private void draw_groundLand1(int[,,] MatriceWorldCube,Vector3 position_model_origin) 
    { 

     int hauteur = MatriceWorldCube.GetLength(0); 
     int largeur = MatriceWorldCube.GetLength(1); 
     int longueur = MatriceWorldCube.GetLength(2); 

     Vector3 pos_reference = position_model_origin; 

     for (int epaisseur = 0; epaisseur < hauteur; epaisseur++) 
     { 

      for (int collone = 0; collone < largeur; collone++) 
      { 

       for (int ligne = 0; ligne < longueur ; ligne++) 
       { 

        //Vérifie si l'index de la matrice comporte bien un matériaux a placer 
        if (MatriceWorldCube[epaisseur, collone, ligne] != 0) 
        { 
         // Copy any parent transforms. 
         Matrix[] transforms = new Matrix[model_ground_land1.Bones.Count]; 
         model_ground_land1.CopyAbsoluteBoneTransformsTo(transforms); 

         // Draw the model. A model can have multiple meshes, so loop. 
         foreach (ModelMesh mesh in model_ground_land1.Meshes) 
         { 
          // This is where the mesh orientation is set, as well 
          // as our camera and projection. 
          foreach (BasicEffect effect in mesh.Effects) 
          { 
           effect.EnableDefaultLighting(); 
           effect.World = transforms[mesh.ParentBone.Index] * 
          Matrix.CreateRotationY(cubeGroundLand1_modelRotation) * Matrix.CreateTranslation(position_model_origin); 
           effect.View = View; 
           effect.Projection = Projection; 

           //Applique la texture en fonction du type de matière définit dans l'indice de la matrice 
           switch (MatriceWorldCube[epaisseur, collone, ligne]) 
           { 
            case 1: 
             effect.Texture = text_ground_land1; 
             break; 

            case 2: 
             effect.Texture = text_ground_land2; 
             break; 

            default: 
             break; 
           } 
          } 

          // Draw the mesh, using the effects set above. 
          mesh.Draw(); 
         } 

        } 

        position_model_origin.X = (float)(ligne+1); 
       } 
       position_model_origin.X = pos_reference.X; 
       position_model_origin.Z = (float)(collone+1); 

      } 
      position_model_origin.Z = pos_reference.Z; 
      position_model_origin.Y = (float)(epaisseur+1); 

     } 
     position_model_origin.Y = pos_reference.Y; 
     position_model_origin = pos_reference; 
    }