Esempio n. 1
0
 private void RenderTerrain(float[,] h, float[,] w, Vector3 player)
 {
     for (int i = (int)(player.x - renderDistance / 2); i < (int)(player.x + renderDistance / 2); i++)
     {
         for (int j = (int)(player.z - renderDistance / 2); j < (int)(player.z + renderDistance / 2); j++)
         {
             try
             {
                 for (int k = 0; k < h[i, j] * MaxHeight + 1; k++)
                 {
                     if (k >= (int)(h[i, j] * MaxHeight) - 2)
                     {
                         if (w[i, j] < waterLevel && !Physics.CheckSphere(new Vector3(i, k, j), .25f))
                         {
                             Instantiate(Land, new Vector3(i, k, j), Quaternion.identity);
                         }
                         else if (!Physics.CheckSphere(new Vector3(i, k, j), (float)(0.25)))
                         {
                             Instantiate(Water, new Vector3(i, k, j), Quaternion.identity);
                         }
                     }
                     if (texture.GetPixel(i, j).r >= .1f &&
                         !Physics.CheckSphere(new Vector3(i, h[i, j] * MaxHeight + 2, j), .25f) &&
                         w[i, j] < waterLevel)
                     {
                         if (!treeMap.ContainsKey(new point(i, j, (int)(h[i, j] * MaxHeight + 1))))
                         {
                             tree Tree = new tree(TreeTrunk);
                             Tree.genTree(new Vector3(i, h[i, j] * MaxHeight + 1, j), 5, 5, 10, Mathf.PI / 2);
                             treeMap.Add(new point(i, j, (int)(h[i, j] * MaxHeight + 1)), Tree);
                         }
                         tree Tree1;
                         treeMap.TryGetValue(new point(i, j, (int)(h[i, j] * MaxHeight + 1)), out Tree1);
                         Tree1.generate();
                     }
                 }
             }
             catch { }
         }
     }
 }