Beispiel #1
0
 public static Vector3d ChunkToWorldSpace(Vector2i v)
 {
     return new Vector3d(
         v.X * ChunkScale,
         0,
         v.Y * ChunkScale
         );
 }
Beispiel #2
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            SingletonConfigManager.LoadAll();

            Title = WindowConfig.WindowTitle;

            ClientSize = new Size(WindowConfig.ScreenSize.X, WindowConfig.ScreenSize.Y);
            var resolution = new Vector2i(DisplayDevice.Default.Width, DisplayDevice.Default.Height);
            Location = new Point((resolution.X - ClientSize.Width) / 2, (resolution.Y - ClientSize.Height) / 2);

            Renderer.OnLoad();
            World.OnLoad();
        }
Beispiel #3
0
 public bool Equals(Vector2i other)
 {
     return X == other.X && Y == other.Y;
 }
Beispiel #4
0
        public static Voxel[,,] GenerateChunk(Vector2i i)
        {
            var data = new float[ChunkSize.X + 1, ChunkHeight, ChunkSize.Y + 1];
            var voxels = new Voxel[ChunkSize.X + 1, ChunkHeight, ChunkSize.Y + 1];
            var ns = new Vector3d(
                NoiseStep * ChunkSize.X * i.X,
                0,
                NoiseStep * ChunkSize.Y * i.Y
                );

            // gen data
            for (int x = 0; x < data.GetLength(0); x++)
            {
                for (int y = 0; y < data.GetLength(1); y++)
                {
                    for (int z = 0; z < data.GetLength(2); z++)
                    {
                        float density = -y / (float) ChunkHeight / 2f + 0.1f;

                        density += Noise.Generate(
                            (float) (NoiseLocation.X + ns.X + NoiseStep * x * 1),
                            (float) (NoiseLocation.X + ns.Y + NoiseStep * y * 1),
                            (float) (NoiseLocation.X + ns.Z + NoiseStep * z * 1)) / 4f;

                        //density += Noise.Generate(
                        //    (float)(NoiseLocation.X + ns.X * 2 + NoiseStep * x * 2),
                        //    (float)(NoiseLocation.X + ns.Y * 2 + NoiseStep * y * 2),
                        //    (float)(NoiseLocation.X + ns.Z * 2 + NoiseStep * z * 2)) / 8f;

                        //density += Noise.Generate(
                        //    (float)(NoiseLocation.X + ns.X * 4 + NoiseStep * x * 4),
                        //    (float)(NoiseLocation.X + ns.Y * 4 + NoiseStep * y * 4),
                        //    (float)(NoiseLocation.X + ns.Z * 4 + NoiseStep * z * 4)) / 16f;

                        //density += Noise.Generate(
                        //    (float)(NoiseLocation.X + ns.X * 8 + NoiseStep * x * 8),
                        //    (float)(NoiseLocation.X + ns.Y * 8 + NoiseStep * y * 8),
                        //    (float)(NoiseLocation.X + ns.Z * 8 + NoiseStep * z * 8)) / 32f;

                        data[x, y, z] = density;
                    }
                }
            }
            // make voxels
            for (int x = 0; x < data.GetLength(0); x++)
            {
                for (int y = 0; y < data.GetLength(1); y++)
                {
                    for (int z = 0; z < data.GetLength(2); z++)
                    {
                        float density = data[x, y, z];
                        Vector3 normal = new Vector3(
                            ((x < data.GetLength(0) - 1 ? data[x + 1, y, z] : data[x, y, z])
                             + (x > 0 ? data[x - 1, y, z] : data[x, y, z])) / 2f,
                            ((y < data.GetLength(0) - 1 ? data[x, y + 1, z] : data[x, y, z])
                             + (y > 0 ? data[x, y - 1, z] : data[x, y, z])) / 2f,
                            ((z < data.GetLength(0) - 1 ? data[x, y, z + 1] : data[x, y, z])
                             + (z > 0 ? data[x, y, z - 1] : data[x, y, z])) / 2f
                            ).Normalized();

                        if (y / (float) ChunkHeight < 0.2f)
                            voxels[x, y, z] = new Voxel(1d, VoxelType.Blue, normal);
                        else if (density < 0f)
                            voxels[x, y, z] = new Voxel(density, VoxelType.None, normal);
                        else
                            voxels[x, y, z] = new Voxel(density, VoxelType.DarkGray, normal);
                    }
                }
            }

            return voxels;
        }