Ejemplo n.º 1
0
    void Update()
    {
        //Begin draw.
        voxelRender.BeginDraw();

        //Inc counters.
        count  += 0.02f;
        count2 += 0.1f;

        //Calculate some voxels.
        int  x     = (int)(96 + 80 * Mathf.Sin(count * 0.6f - count2 * 0.3f));
        int  z     = (int)(80 + 80 * Mathf.Sin(-0.4f * count + count2 * 0.2f));
        int  y     = (int)(8 + 8 * Mathf.Sin(0.4f * count + count2 * 0.4f + z * 0.1f));
        byte color = (byte)Random.Range(1, 255);

        //Put it to level.
        for (int i = 4; i < 16; i++)
        {
            voxelRender.SetVoxel(x, y + i, z, color, Layer.Static);
        }


        //End draw, it starts a multithreading geometry building.
        voxelRender.EndDraw();

        //Wait geometry.
        voxelRender.WaitGeometry();
    }
Ejemplo n.º 2
0
    void Update()
    {
        //Swap frames, so we update everything at 30 FPS, for descrete voxel space it still nice.
        //And we have a massive perfomance boost.
        frame = !frame;

        if (frame)
        {
            //Begin draw.
            voxelRender.BeginDraw();


            //Draw some dynamic voxels.
            //Update count.
            count += 0.02f;

            for (int x = 0; x < voxelRender.Width; x++)
            {
                for (int z = 0; z < voxelRender.Depth; z++)
                {
                    float height = 16 + 8 * Mathf.PerlinNoise((float)x * 0.025f, (float)z * 0.025f) + 8 * Mathf.Sin(count + x * 0.01f + z * 0.01f);
                    voxelRender.SetVoxel(x, (int)height, z, (byte)(height + 1), Layer.Dynamic);
                }
            }


            //End draw, it starts a multithreading geometry building.
            voxelRender.EndDraw();
        }
        else
        {
            //Wait geometry.
            voxelRender.WaitGeometry();
        }
    }