public void GenerateWorld() { int seed = System.DateTime.Now.Millisecond; HeightMap h = new HeightMap(GameSettings.GridDimensionsX, GameEngine.GetInstance().Client.ServerSeed); h.AddPerlinNoise(1.0f); h.AddPerlinNoise(3.0f); h.AddPerlinNoise(2); h.MakeIsland(); //h.Perturb(32.0f, 32.0f); for (int i = 0; i < 30; i++) { h.Erode(16.0f); } h.Smoothen(); for (int x = 0; x < GameSettings.GridDimensionsX; x++) { for (int y = 0; y < GameSettings.GridDimensionsY; y++) { for (int z = 0; z < GameSettings.GridDimensionsZ; z++) { float height = h.Heights[x, z]; float bheight = (float)y / 50.0f;//GameSettings.GridDimensionsY; if (bheight < height) { if (height < 0.11f) { voxelManager.Add(new Vector3(x, y, z), TerrainTypes.Water); } else if (height < 0.12f) { voxelManager.Add(new Vector3(x, y, z), TerrainTypes.Sand); } else if (height < 0.25f) { voxelManager.Add(new Vector3(x, y, z), TerrainTypes.Grass); } else if (height < 0.55f) { voxelManager.Add(new Vector3(x, y, z), TerrainTypes.Rock); } else { voxelManager.Add(new Vector3(x, y, z), TerrainTypes.Snow); } } } } } voxelManager.Update(); }
public void GenerateChunks() { _progressText = "1/3 Generating Heightmap"; _heightMap = new HeightMap(Chunk.SIZE * SIZE); _heightMap.AddPerlinNoise(3f); _heightMap.Perturb(64.0f, 64.0f); for (int i = 0; i < 10; i++) { _heightMap.Erode(256.0f); } _heightMap.Smoothen(); _chunks = new List<Chunk>(); _boxels = new BoxelType[(int)(Math.Pow(Chunk.SIZE, 3) * Math.Pow(SIZE, 3))]; int count = 1; for (int z = 0; z < SIZE; z++) { for (int y = 0; y < SIZE; y++) { for (int x = 0; x < SIZE; x++) { _chunks.Add(new Chunk(new Vector3(x, y, z))); count++; _progress = 0.5f * count / (float)(Math.Pow(SIZE, 3)); _progressText = "2/3 Generating Chunk " + count + " of " + (Math.Pow(SIZE, 3)); } } } }
public override void Load() { _rsDefault.CullMode = CullMode.CullCounterClockwiseFace; _rsDefault.FillMode = FillMode.Solid; _rsWire.CullMode = CullMode.CullCounterClockwiseFace; _rsWire.FillMode = FillMode.WireFrame; int size; dynamic map; if (generateHeightMap) { HeightMap heightMap = new HeightMap(513); heightMap.AddPerlinNoise(5.0f); heightMap.Perturb(32.0f, 32.0f); for (int i = 0; i < 10; i++) heightMap.Erode(16.0f); heightMap.Smoothen(); heightMap.Normalize(); size = heightMap.Size; map = heightMap; } else { Texture2D heightMap = Game.Instance.ContentManager.Load<Texture2D>("textures/hmSmall"); size = heightMap.Height; map = heightMap; } this.TopNodeSize = size - 1; this.Vertices = new TreeVertexCollection(this.Position, map, this.Scale); this.Buffers = new BufferManager(this.Vertices.Vertices, this.Device); this.RootNode = new QuadNode(NodeType.FullNode, this.TopNodeSize, 1, null, this, 0); //Construct an array large enough to hold all of the indices we'll need. // SOMETHING IS WRONG HERE this.Indices = new int[((size + 1) * (size + 1)) * 3]; Effect = new BasicEffect(this.Device); Effect.LightingEnabled = true; Effect.AmbientLightColor = new Vector3(0.4f); Effect.DirectionalLight0.Enabled = true; Effect.DirectionalLight0.Direction = new Vector3(-0.5f, -1, -0.5f); Effect.FogEnabled = true; Effect.FogStart = 300f; Effect.FogEnd = 1000f; Effect.FogColor = Color.Black.ToVector3(); Effect.TextureEnabled = true; Effect.Texture = Game.Instance.ContentManager.Load<Texture2D>("textures/grass");//new Texture2D(this.Device, 100, 100); Effect.Projection = this.Projection; Effect.View = this.View; Effect.World = Matrix.Identity; this.RootNode.EnforceMinimumDepth(); }
IEnumerator <float> Generate() { float step = 0; float maxStep = 2; foreach (var genStep in settings.mSteps) { maxStep = maxStep + 1; if (genStep.type == GeneratorStep.StepType.erode) { maxStep += genStep.erodeIterations; } } //rnd.NextBytes(Noise.perm); settings.terraSize = Mathf.NextPowerOfTwo(settings.terraSize); hm = new HeightMap(settings.terraSize, settings.seed, settings.simplex); foreach (var genStep in settings.mSteps) { switch (genStep.type) { case GeneratorStep.StepType.addNoise: hm.AddPerlinNoise(genStep.noiseSize, genStep.noiseHeight); break; case GeneratorStep.StepType.erode: for (int i = 0; i < genStep.erodeIterations; i++) { hm.Erode(genStep.erodeIntensity); yield return(step++ / maxStep); } break; case GeneratorStep.StepType.perturb: hm.Perturb(genStep.perturbVector.x, genStep.perturbVector.y); break; case GeneratorStep.StepType.smooth: hm.Smoothen(); break; } yield return(step++ / maxStep); } float max = 0; float min = float.MaxValue; for (int y = 0; y < settings.terraSize; y++) { for (int x = 0; x < settings.terraSize; x++) { max = Mathf.Max(hm.Heights [x, y], max); min = Mathf.Min(hm.Heights [x, y], min); } } yield return(step++ / maxStep); for (int y = 0; y < settings.terraSize; y++) { for (int x = 0; x < settings.terraSize; x++) { hm.Heights [x, y] = (hm.Heights [x, y] - min) / (max - min); } } yield return(step++ / maxStep); }