protected override void GenerateTerrainData(CubicTerrainData terrainDataObject, Vector3 worldspace)
    {
        for (int x = 0; x < terrainDataObject.width; x++)
        {
            for (int z = 0; z < terrainDataObject.depth; z++)
            {
                // Get absolute positions for noise generation
                float absX = (float) x + worldspace.x;
                float absZ = (float) z + worldspace.z;

                float perlin = Mathf.PerlinNoise(absX * frequency, absZ * frequency);
                int toY = (int)(perlin * ((float)terrainDataObject.height-1));

                for (int y = 0; y < toY-3; y++)
                {
                    terrainDataObject.SetVoxel(x,y,z,stoneId);
                }

                for (int y = toY-3; y < toY-1; y++)
                {
                    terrainDataObject.SetVoxel(x,y,z,dirtId);
                }
                terrainDataObject.SetVoxel(x,toY-1,z,grassId);
            }
        }
    }
Beispiel #2
0
    /// <summary>
    /// Sets the block id at position x|y|z.
    /// </summary>
    /// <param name="x">The x coordinate.</param>
    /// <param name="y">The y coordinate.</param>
    /// <param name="z">The z coordinate.</param>
    public void SetBlock(int x, int y, int z, short blockId)
    {
        // Calculate chunk position for calculating relative position
        Vector3 chunk = this.GetChunkPosition(new Vector3(x, y, z));

        if (!this.chunkData.ContainsKey((int)chunk.x, (int)chunk.y, (int)chunk.z))
        {
            return;
        }

        CubicTerrainData cData = this.chunkData [new ListIndex <int> ((int)chunk.x, (int)chunk.y, (int)chunk.z)];

        // Calculate relative position
        x = x - (int)(chunk.x * this.chunkWidth);
        y = y - (int)(chunk.y * this.chunkHeight);
        z = z - (int)(chunk.z * this.chunkDepth);

        if (x < 0)
        {
            x *= -1;
        }
        if (z < 0)
        {
            z *= -1;
        }

        if (this.chunkData.ContainsKey((int)chunk.x, (int)chunk.y, (int)chunk.z))
        {
            cData.SetVoxel(x, y, z, blockId);
        }
        else
        {
            Debug.LogError("Tried to set block to non existing chunk: " + chunk + " at position " + x + "|" + y + "|" + z);
        }
    }
    protected override void GenerateTerrainData(CubicTerrainData terrainDataObject, Vector3 worldspace)
    {
        for (int x = 0; x < terrainDataObject.width; x++)
        {
            for (int z = 0; z < terrainDataObject.depth; z++)
            {
                // Get absolute positions for noise generation
                float absX = (float) x + worldspace.x;
                float absZ = (float) z + worldspace.z;

                float perlin = Mathf.PerlinNoise(absX * frequency, absZ * frequency);
                int toY = (int)(perlin * ((float)(terrainDataObject.owner.chunkHeight * terrainDataObject.owner.chunksOnYAxis)-1));
                toY -= (int)terrainDataObject.owner.GetChunkPosition(worldspace).y * terrainDataObject.owner.chunkHeight;
                toY = Mathf.Min(toY, terrainDataObject.height);

                for (int y = 0; y < terrainDataObject.height; y++)
                {
                    if (y > toY)
                    {
                        continue;
                    }
                    if (y < toY - 3)
                    {
                        terrainDataObject.SetVoxel(x,y,z,stoneId);
                    }
                    else if (y == toY)
                    {
                        terrainDataObject.SetVoxel(x,y,z,grassId);
                    }
                    else if (y > toY - 1)
                    {
                        terrainDataObject.SetVoxel(x,y,z,dirtId);
                    }
                    else if (y > toY - 3)
                    {
                        terrainDataObject.SetVoxel(x,y,z,dirtId);
                    }
                }
            }
        }
    }
    protected override void GenerateTerrainData(CubicTerrainData terrainDataObject, Vector3 worldspace)
    {
        for (int x = 0; x < terrainDataObject.width; x++)
        {
            for (int z = 0; z < terrainDataObject.depth; z++)
            {
                // Get absolute positions for noise generation
                float absX = (float)x + worldspace.x;
                float absZ = (float)z + worldspace.z;

                float perlin = Mathf.PerlinNoise(absX * frequency, absZ * frequency);
                int   toY    = (int)(perlin * ((float)(terrainDataObject.owner.chunkHeight * terrainDataObject.owner.chunksOnYAxis) - 1));
                toY -= (int)terrainDataObject.owner.GetChunkPosition(worldspace).y *terrainDataObject.owner.chunkHeight;
                toY  = Mathf.Min(toY, terrainDataObject.height);

                for (int y = 0; y < terrainDataObject.height; y++)
                {
                    if (y > toY)
                    {
                        continue;
                    }
                    if (y < toY - 3)
                    {
                        terrainDataObject.SetVoxel(x, y, z, stoneId);
                    }
                    else if (y == toY)
                    {
                        terrainDataObject.SetVoxel(x, y, z, grassId);
                    }
                    else if (y > toY - 1)
                    {
                        terrainDataObject.SetVoxel(x, y, z, dirtId);
                    }
                    else if (y > toY - 3)
                    {
                        terrainDataObject.SetVoxel(x, y, z, dirtId);
                    }
                }
            }
        }
    }
Beispiel #5
0
 protected override void GenerateTerrainData(CubicTerrainData terrainDataObject, Vector3 worldspace)
 {
     for (int x = 0; x < terrainDataObject.width; x++)
     {
         for (int z = 0; z < terrainDataObject.depth; z++)
         {
             for (int y = 0; y < 3; y++)
             {
                 terrainDataObject.SetVoxel(x,y,z,1);
             }
         }
     }
 }
Beispiel #6
0
    protected override void GenerateTerrainData(CubicTerrainData terrainDataObject, Vector3 worldspace)
    {
        for (int x = 0; x < terrainDataObject.width; x++)
        {
            for (int y = 0; y < terrainDataObject.height; y++)
            {
                for (int z = 0; z < terrainDataObject.depth; z++)
                {
                    // Get absolute positions for noise generation
                    float absX = (float) x + worldspace.x;
                    float absZ = (float) z + worldspace.z;
                    float absY = (float) y + worldspace.y;

                    if (absY < 4)
                        terrainDataObject.SetVoxel(x,y,z,2);
                }
            }
        }
    }
Beispiel #7
0
    protected override void GenerateTerrainData(CubicTerrainData terrainDataObject, Vector3 worldspace)
    {
        for (int x = 0; x < terrainDataObject.width; x++)
        {
            for (int y = 0; y < terrainDataObject.height; y++)
            {
                for (int z = 0; z < terrainDataObject.depth; z++)
                {
                    // Get absolute positions for noise generation
                    float absX = (float)x + worldspace.x;
                    float absZ = (float)z + worldspace.z;
                    float absY = (float)y + worldspace.y;

                    if (absY < 4)
                    {
                        terrainDataObject.SetVoxel(x, y, z, 2);
                    }
                }
            }
        }
    }
Beispiel #8
0
    protected override void GenerateTerrainData(CubicTerrainData terrainDataObject, Vector3 worldspace)
    {
        for (int x = 0; x < terrainDataObject.width; x++)
        {
            for (int y = 0; y < terrainDataObject.height; y++)
            {
                for (int z = 0; z < terrainDataObject.depth; z++)
                {
                    // Get absolute positions for noise generation
                    float absX = (float)x + worldspace.x;
                    float absZ = (float)z + worldspace.z;
                    float absY = (float)y + worldspace.y;

                    //float perlin = Mathf.PerlinNoise(absX * frequency, absZ * frequency);
                    //int toY = (int)(perlin * ((float)terrainDataObject.height-1));
                    float noise = Simplex.Generate(absX * this.frequency, absY * this.frequency, absZ * this.frequency);

                    /*for (int y = 0; y < toY-3; y++)
                     * {
                     *      terrainDataObject.SetVoxel(x,y,z,stoneId);
                     * }
                     *
                     * for (int y = toY-3; y < toY-1; y++)
                     * {
                     *      terrainDataObject.SetVoxel(x,y,z,dirtId);
                     * }
                     * terrainDataObject.SetVoxel(x,toY-1,z,grassId);*/

                    if (noise < 0.5f && noise > 0.25f)
                    {
                        terrainDataObject.SetVoxel(x, y, z, 2);
                    }
                }
            }
        }
    }
Beispiel #9
0
    protected override void GenerateTerrainData(CubicTerrainData terrainDataObject, Vector3 worldspace)
    {
        /*Simplex.remixPermutation (System.DateTime.Now.Millisecond * System.DateTime.Now.Second);
        for (int x = 0; x < terrainDataObject.width; x++)
        {
            for (int z = 0; z < terrainDataObject.depth; z++)
            {
                // Get absolute positions for noise generation
                float absX = (float) x + worldspace.x;
                float absZ = (float) z + worldspace.z;

                float perlin = Mathf.PerlinNoise(absX * frequency2D, absZ * frequency2D);
                float absoluteWorldHeight = CubicTerrain.GetInstance().chunksOnYAxis * CubicTerrain.GetInstance().chunkHeight;
                int toY = Mathf.Min((int)(perlin * absoluteWorldHeight), terrainDataObject.height);

                bool tree = false; // this.rand.NextDouble() > 0.99;
                for (int y = worldspace.y; y < (int)worldspace.y + toY; y++)
                {
                    if (y < toY-4)
                    {
                        terrainDataObject.SetVoxel(x,y,z,stoneId);
                    }
                    else if (y < toY - 1)
                    {
                        terrainDataObject.SetVoxel(x,y,z,dirtId);
                    }
                    else
                    {
                        terrainDataObject.SetVoxel(x,toY-1,z,grassId);
                    }

                    if (y < 24)
                    {
                        // 3D-Noise
                        float noise = Simplex.Generate(absX * this.frequency3D, y * this.frequency3D, absZ * this.frequency3D);

                        if (noise < 0.5f && noise > 0.3f)
                            terrainDataObject.SetVoxel(x,y,z,-1);
                    }
                }

                // Tree generation possible
                bool treeGenerationPossible = terrainDataObject.GetVoxel (x,toY-1,z).blockId == grassId &&
                    x > 2 && x < terrainDataObject.width - 2 &&
                    z > 2 && z < terrainDataObject.depth - 2;

                if (treeGenerationPossible && tree)
                {
                    // Generate tree
                    int treeHeight = this.rand.Next (5,6);

                    if (toY + treeHeight < terrainDataObject.height)
                    {
                        for (int i = toY; i<toY+treeHeight; i++)
                        {
                            terrainDataObject.SetVoxel(x,i,z,treeId);
                        }

                        for (int lY = toY +treeHeight-1; lY < toY +treeHeight+3; lY++)
                        {
                            // Generate leaves
                            for (int lX = x - 2; lX < x + 2; lX++)
                            {
                                for (int lZ = z - 2; lZ < z + 2; lZ++)
                                {
                                    terrainDataObject.SetVoxel (lZ, lY, lZ, leavesId);
                                }
                            }
                        }
                    }
                }

                // Set bedrock
                terrainDataObject.SetVoxel(x,0,z,bedrockId);
            }
        }*/

        for (int x = 0; x < terrainDataObject.width; x++)
        {
            for (int y = 0; y < terrainDataObject.height; y++)
            {
                for (int z = 0; z < terrainDataObject.depth; z++)
                {
                    // Get absolute positions for noise generation
                    float absX = (float) x + worldspace.x;
                    float absZ = (float) z + worldspace.z;
                    float absY = (float) y + worldspace.y;

                    //float perlin = Mathf.PerlinNoise(absX * frequency, absZ * frequency);
                    //int toY = (int)(perlin * ((float)terrainDataObject.height-1));
                    float noise = Simplex.Generate(absX * this.frequency, absY * this.frequency, absZ * this.frequency);

                    /*for (int y = 0; y < toY-3; y++)
                    {
                        terrainDataObject.SetVoxel(x,y,z,stoneId);
                    }

                    for (int y = toY-3; y < toY-1; y++)
                    {
                        terrainDataObject.SetVoxel(x,y,z,dirtId);
                    }
                    terrainDataObject.SetVoxel(x,toY-1,z,grassId);*/

                    /*if (noise < 0.5f && noise > 0.25f)
                        terrainDataObject.SetVoxel(x,y,z,2);*/
                    if (absY < 4)
                        terrainDataObject.SetVoxel(x,y,z,2);
                }
            }
        }
    }