public TerrainBlock(Terrain terrain, int depth, GraphicsDevice GraphicsDevice, Effect effect, PlanetBlock planetBlock, Planet.GetNeighbourDelegate method, Point location,TerrainBlock parent, Vector3 blockOffset = new Vector3()) { this.GraphicsDevice = GraphicsDevice; this.effect = effect; this.depth = depth; this.planet = true; this.waterSphere = new BoundingSphere(Vector3.Zero, Terrain.PlanetRadius + Planet.HeightMag); this.GetNeighbour = method; this.location = location; this.parent = parent; if (blockOffset == Vector3.Zero) this.blockOffset = new Vector3(0, 0, Planet.PlanetRes); else this.blockOffset = new Vector3(blockOffset.X, blockOffset.Y, blockOffset.Z); this.planet = planet; this.pWidth = terrain.Size; this.busy = false; this.baseTexture = terrain.baseTexture; this.children = new TerrainBlock[BlockRes, BlockRes]; this.terrain = new Terrain[BlockRes, BlockRes]; if (planet) this.SplitMainTerrainPlanet(terrain); this.visible = true; //this.SplitChildren(Vector3.Zero); }
public Planet(GraphicsDevice GraphicsDevice, ContentManager Content) { this.isWater = false; Effect effect = Content.Load<Effect>(@"effects/PPModel"); Texture2D texture = Content.Load<Texture2D>(@"textures/base"); Vector3 pos = Vector3.Zero; top = new Terrain(4096, HeightMag, 1f, PlanetRes, pos, effect, texture, Terrain.Type.CubeFace); top.GenerateFractual(); float[][] borders = new float[4][]; borders[2] = top.MyHeightBorders[0].ToArray(); left = new Terrain(4096, HeightMag, 1f, PlanetRes, pos, effect, texture, Terrain.Type.CubeFace); left.GenerateFractualSlice(new Vector3(0, 0, 90), borders, Fractal.BorderType.Right); borders = new float[4][]; borders[0] = top.MyHeightBorders[2].ToArray(); right = new Terrain(4096, HeightMag, 1f, PlanetRes, pos, effect, texture, Terrain.Type.CubeFace); right.GenerateFractualSlice(new Vector3(0, 0, -90), borders, Fractal.BorderType.Left); borders = new float[4][]; borders[0] = left.MyHeightBorders[3].ToArray(); borders[1] = top.MyHeightBorders[3].ToArray(); borders[2] = right.MyHeightBorders[3].ToArray(); Array.Reverse(borders[0]); front = new Terrain(4096, HeightMag, 1f, PlanetRes, pos, effect, texture, Terrain.Type.CubeFace); front.GenerateFractualSlice(new Vector3(90, 0, 0), borders, Fractal.BorderType.Left | Fractal.BorderType.Top | Fractal.BorderType.Right); borders = new float[4][]; borders[0] = left.MyHeightBorders[1].ToArray(); borders[2] = right.MyHeightBorders[1].ToArray(); borders[3] = top.MyHeightBorders[1].ToArray(); Array.Reverse(borders[2]); back = new Terrain(4096, HeightMag, 1f, PlanetRes, pos, effect, texture, Terrain.Type.CubeFace); back.GenerateFractualSlice(new Vector3(-90, 0, 0), borders, Fractal.BorderType.Left | Fractal.BorderType.Bottom | Fractal.BorderType.Right); borders = new float[4][]; borders[0] = left.MyHeightBorders[0].ToArray(); borders[1] = front.MyHeightBorders[3].ToArray(); borders[2] = right.MyHeightBorders[2].ToArray(); borders[3] = back.MyHeightBorders[1].ToArray(); Array.Reverse(borders[0]); Array.Reverse(borders[2]); bottom = new Terrain(4096, HeightMag, 1f, PlanetRes, pos, effect, texture, Terrain.Type.CubeFace); bottom.GenerateFractualSlice(new Vector3(180, 0, 0), borders, Fractal.BorderType.All); /////////////////// top.loadPosBorders(left.MyRawHeightBorders[2], Fractal.BorderType.Left, false); top.loadPosBorders(right.MyRawHeightBorders[0], Fractal.BorderType.Right, false); top.loadPosBorders(front.MyRawHeightBorders[1], Fractal.BorderType.Bottom, false); top.loadPosBorders(back.MyRawHeightBorders[3], Fractal.BorderType.Top, false); top.PostNormalize(); left.loadPosBorders(top.MyRawHeightBorders[0], Fractal.BorderType.Right, false); left.loadPosBorders(front.MyRawHeightBorders[0], Fractal.BorderType.Bottom, true); left.loadPosBorders(back.MyRawHeightBorders[0], Fractal.BorderType.Top, false); left.loadPosBorders(bottom.MyRawHeightBorders[0], Fractal.BorderType.Left, true); left.PostNormalize(); right.loadPosBorders(top.MyRawHeightBorders[2], Fractal.BorderType.Left, false); right.loadPosBorders(front.MyRawHeightBorders[2], Fractal.BorderType.Bottom, false); right.loadPosBorders(back.MyRawHeightBorders[2], Fractal.BorderType.Top, true); right.loadPosBorders(bottom.MyRawHeightBorders[2], Fractal.BorderType.Right, true); right.PostNormalize(); front.loadPosBorders(top.MyRawHeightBorders[3], Fractal.BorderType.Top, false); front.loadPosBorders(left.MyRawHeightBorders[3], Fractal.BorderType.Left, true); front.loadPosBorders(right.MyRawHeightBorders[3], Fractal.BorderType.Right, false); front.loadPosBorders(bottom.MyRawHeightBorders[1], Fractal.BorderType.Bottom, false); front.PostNormalize(); back.loadPosBorders(top.MyRawHeightBorders[1], Fractal.BorderType.Bottom, false); back.loadPosBorders(right.MyRawHeightBorders[1], Fractal.BorderType.Right, true); back.loadPosBorders(left.MyRawHeightBorders[1], Fractal.BorderType.Left, false); back.loadPosBorders(bottom.MyRawHeightBorders[3], Fractal.BorderType.Top, false); back.PostNormalize(); bottom.loadPosBorders(left.MyRawHeightBorders[0], Fractal.BorderType.Left, true); bottom.loadPosBorders(front.MyRawHeightBorders[3], Fractal.BorderType.Top, false); bottom.loadPosBorders(right.MyRawHeightBorders[2], Fractal.BorderType.Right, true); bottom.loadPosBorders(back.MyRawHeightBorders[1], Fractal.BorderType.Bottom, false); bottom.PostNormalize(); topBlock = new TerrainBlock(top, 0, GraphicsDevice, effect, TerrainBlock.PlanetBlock.Top, this.GetNeighbourTerrain, new Point(), null); leftBlock = new TerrainBlock(left, 0, GraphicsDevice, effect, TerrainBlock.PlanetBlock.Left, this.GetNeighbourTerrain, new Point(), null); rightBlock = new TerrainBlock(right, 0, GraphicsDevice, effect, TerrainBlock.PlanetBlock.Right, this.GetNeighbourTerrain, new Point(), null); frontBlock = new TerrainBlock(front, 0, GraphicsDevice, effect, TerrainBlock.PlanetBlock.Front, this.GetNeighbourTerrain, new Point(), null); backBlock = new TerrainBlock(back, 0, GraphicsDevice, effect, TerrainBlock.PlanetBlock.Back, this.GetNeighbourTerrain, new Point(), null); bottomBlock = new TerrainBlock(bottom, 0, GraphicsDevice, effect, TerrainBlock.PlanetBlock.Bottom, this.GetNeighbourTerrain, new Point(), null); topBlock.GetNeighbour = this.GetNeighbourTerrain; leftBlock.GetNeighbour = this.GetNeighbourTerrain; rightBlock.GetNeighbour = this.GetNeighbourTerrain; frontBlock.GetNeighbour = this.GetNeighbourTerrain; backBlock.GetNeighbour = this.GetNeighbourTerrain; bottomBlock.GetNeighbour = this.GetNeighbourTerrain; water = new Planet(GraphicsDevice, Content, true); }
public Planet(GraphicsDevice GraphicsDevice, ContentManager Content, Vector3 sunPosition) { this.isWater = false; Vector3 pos = Vector3.Zero; top = new Terrain(4096, HeightMag, 1f, PlanetRes, pos, new Vector3(1, -1, 0), GraphicsDevice, Content.Load<Effect>(@"effects/Terrain"), Content.Load<Texture2D>(@"textures/base"), Terrain.Type.CubeFace); top.GenerateFractual(); top.LightPosition = sunPosition; topBlock = new TerrainBlock(top, 0, true, GraphicsDevice, Content.Load<Effect>(@"effects/Terrain")); //l,t,r,b float[,] borders = new float[4, PlanetRes]; for (int i = 0; i < 4; i++) for (int c = 0; c < PlanetRes; c++) if (i == 2) borders[i, c] = top.heightMaps[0, c]; left = new Terrain(4096, HeightMag, 1f, PlanetRes, pos, new Vector3(1, -1, 0), GraphicsDevice, Content.Load<Effect>(@"effects/Terrain"), Content.Load<Texture2D>(@"textures/base"), Terrain.Type.CubeFace); left.GenerateFractualSlice(new Vector3(0, 0, 90), borders, Fractal.BorderType.Right); left.LightPosition = sunPosition; leftBlock = new TerrainBlock(left, 0, true, GraphicsDevice, Content.Load<Effect>(@"effects/Terrain")); //l,t,r,b borders = new float[4, PlanetRes]; for (int i = 0; i < 4; i++) for (int c = 0; c < PlanetRes; c++) if (i == 0) borders[i, c] = top.heightMaps[(PlanetRes - 1), c]; right = new Terrain(4096, HeightMag, 1f, PlanetRes, pos, new Vector3(1, -1, 0), GraphicsDevice, Content.Load<Effect>(@"effects/Terrain"), Content.Load<Texture2D>(@"textures/base"), Terrain.Type.CubeFace); right.GenerateFractualSlice(new Vector3(0, 0, -90), borders, Fractal.BorderType.Left); right.LightPosition = sunPosition; rightBlock = new TerrainBlock(right, 0, true, GraphicsDevice, Content.Load<Effect>(@"effects/Terrain")); //l,t,r,b borders = new float[4, PlanetRes]; for (int i = 0; i < 4; i++) for (int c = 0; c < PlanetRes; c++) if (i == 0) borders[i, c] = left.heightMaps[(PlanetRes - 1) - c, (PlanetRes - 1)]; else if (i == 1) borders[i, c] = top.heightMaps[c, (PlanetRes - 1)]; else if (i == 2) borders[i, c] = right.heightMaps[c, (PlanetRes - 1)]; front = new Terrain(4096, HeightMag, 1f, PlanetRes, pos, new Vector3(1, -1, 0), GraphicsDevice, Content.Load<Effect>(@"effects/Terrain"), Content.Load<Texture2D>(@"textures/base"), Terrain.Type.CubeFace); front.GenerateFractualSlice(new Vector3(90, 0, 0), borders, Fractal.BorderType.Left | Fractal.BorderType.Top | Fractal.BorderType.Right); front.LightPosition = sunPosition; frontBlock = new TerrainBlock(front, 0, true, GraphicsDevice, Content.Load<Effect>(@"effects/Terrain")); //l,t,r,b borders = new float[4, PlanetRes]; for (int i = 0; i < 4; i++) for (int c = 0; c < PlanetRes; c++) if (i == 0) borders[i, c] = left.heightMaps[c, 0]; else if (i == 2) borders[i, c] = right.heightMaps[(PlanetRes - 1) - c, 0]; else if (i == 3) borders[i, c] = top.heightMaps[c, 0]; back = new Terrain(4096, HeightMag, 1f, PlanetRes, pos, new Vector3(1, -1, 0), GraphicsDevice, Content.Load<Effect>(@"effects/Terrain"), Content.Load<Texture2D>(@"textures/base"), Terrain.Type.CubeFace); back.GenerateFractualSlice(new Vector3(-90, 0, 0), borders, Fractal.BorderType.Left | Fractal.BorderType.Bottom | Fractal.BorderType.Right); back.LightPosition = sunPosition; backBlock = new TerrainBlock(back, 0, true, GraphicsDevice, Content.Load<Effect>(@"effects/Terrain")); //l,t,r,b borders = new float[4, PlanetRes]; for (int i = 0; i < 4; i++) for (int c = 0; c < PlanetRes; c++) if (i == 0) borders[i, c] = left.heightMaps[0, (PlanetRes - 1) - c]; else if (i == 1) borders[i, c] = front.heightMaps[c, (PlanetRes - 1)]; else if (i == 2) borders[i, c] = right.heightMaps[(PlanetRes - 1), (PlanetRes - 1) - c]; else if (i == 3) borders[i, c] = back.heightMaps[c, 0]; bottom = new Terrain(4096, HeightMag, 1f, PlanetRes, pos, new Vector3(1, -1, 0), GraphicsDevice, Content.Load<Effect>(@"effects/Terrain"), Content.Load<Texture2D>(@"textures/base"), Terrain.Type.CubeFace); bottom.GenerateFractualSlice(new Vector3(180, 0, 0), borders, Fractal.BorderType.All); bottom.LightPosition = sunPosition; bottomBlock = new TerrainBlock(bottom, 0, true, GraphicsDevice, Content.Load<Effect>(@"effects/Terrain")); water = new Planet(GraphicsDevice, Content, true, sunPosition); }