Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static RasterizerState MyRasterizerStateCullNoneSolid = new RasterizerState() { FillMode = FillMode.Solid, CullMode = CullMode.None };
- public Chunk(int chunkX, int chunkY, int width, int height, int mapWidth, int mapHeight, float[] noiseMap, GraphicsDeviceManager graphics, PlanetTypes planetType) {
- Width = width;
- Height = height;
- ChunkY = chunkY;
- List < Vector3 > positions = new List < Vector3 > ();
- List < Color > colors = new List < Color > ();
- VertexPositionColor[] vertices;
- float pX = chunkX * width * innerRadius * 2;
- float pY = chunkY * height * outerRadius * 3 / 2;
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- float tx = pX + (x + y * 0.5 f - y / 2) * (innerRadius * 2 f);
- float ty = pY + y * (outerRadius * 1.5 f);
- float value = noiseMap[(y + chunkY * height) * width * mapWidth + x + chunkX * width];
- int color = (int)(MathHelper.Clamp(value, 0.1 f, 0.9 f) * 255);
- Vector3 pos = new Vector3(tx, ty, value * 100);
- for (int i = 0; i < 6; i++) {
- Vector3 c1 = pos + corners[i];
- Vector3 c2 = pos + corners[i + 1];
- if (i == 0 || i == 4 || i == 5) {
- int ax = y % 2 == 0 ? AdjentsEven[i].Item1 : AdjentsOdd[i].Item1;
- int ay = y % 2 == 0 ? AdjentsEven[i].Item2 : AdjentsOdd[i].Item2;
- int nx = x + ax;
- int ny = y + ay;
- float tx2 = pX + (nx + ny * 0.5 f - ny / 2) * (innerRadius * 2 f);
- float ty2 = pY + ny * (outerRadius * 1.5 f);
- int noiseMapIndex = (ny + chunkY * height) * width * mapWidth + nx + chunkX * width;
- if (noiseMapIndex >= 0 && noiseMapIndex < noiseMap.Length) {
- float value2 = noiseMap[noiseMapIndex];
- int color2 = (int)(MathHelper.Clamp(value2, 0.1 f, 0.9 f) * 255);
- Vector3 pos2 = new Vector3(tx2, ty2, value2 * 100);
- Vector3 c3 = pos2 + corners[(i + 4) % 6];
- Vector3 c4 = pos2 + corners[(i + 3) % 6];
- positions.Add(c1);
- positions.Add(c2);
- positions.Add(c3);
- colors.Add(new Color(color, 125, 125));
- colors.Add(new Color(color, 125, 125));
- colors.Add(new Color(color2, 125, 125));
- positions.Add(c4);
- positions.Add(c3);
- positions.Add(c2);
- colors.Add(new Color(color2, 125, 125));
- colors.Add(new Color(color2, 125, 125));
- colors.Add(new Color(color, 125, 125));
- }
- }
- //if(y >= CHUNK_WIDTH/ 2)
- //{
- // positions.Add(pos);
- // positions.Add(c2);
- // positions.Add(c1);
- // colors.Add(new Color(color, 125, 125));
- // colors.Add(new Color(color, 125, 125));
- // colors.Add(new Color(color, 125, 125));
- //}
- //else
- //{
- positions.Add(c2);
- positions.Add(pos);
- positions.Add(c1);
- colors.Add(new Color(color, 225, 225));
- colors.Add(new Color(color, 225, 225));
- colors.Add(new Color(color, 225, 225));
- //}
- }
- }
- }
- //Vertices = new VertexBuffer(graphics.GraphicsDevice, typeof(VertexPositionColor), positions.Count, BufferUsage.None);
- //positions.Reverse();
- //colors.Reverse();
- Vertices = new VertexPositionColor[positions.Count];
- for (int i = 0; i < positions.Count; i++)
- Vertices[i] = new VertexPositionColor(positions[i], colors[i]);
- BoundingBox = BoundingBox.CreateFromPoints(positions);
- testEffect = new BasicEffect(graphics.GraphicsDevice);
- }
- public static void LoadContent(ContentManager content) {
- effect = content.Load < Effect > ("Shaders/FogOfWar");
- }
- public void Draw(SpriteBatch spriteBatch, GraphicsDeviceManager graphics, Camera camera) {
- //if (camera.Frustum.Contains(BoundingBox) == ContainmentType.Disjoint)
- // return;
- Space.ChunksDrawn++;
- effect.Parameters["WorldViewProjection"].SetValue(camera.ViewMatrix * camera.ProjectionMatrix * Matrix.Identity);
- graphics.GraphicsDevice.RasterizerState = MyRasterizerStateCullNoneSolid;
- graphics.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
- foreach(var pass in effect.CurrentTechnique.Passes) {
- pass.Apply();
- graphics.GraphicsDevice.DrawUserPrimitives < VertexPositionColor > (
- PrimitiveType.TriangleList,
- Vertices,
- 0,
- Width * Height * 6, VertexPositionColor.VertexDeclaration);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement