//void FillSecondLayer(List<Vector2> potentialPositions, int width, int height) //{ // // Second Texture Variables: // // Make sure this Mesh object shares the same mesh as Base mesh // Mesh islandMesh = base_renderer.gameObject.GetComponent<MeshFilter>().mesh; // second_renderer.gameObject.GetComponent<MeshFilter>().mesh = islandMesh; // int textureWidth = width * tileResolution; // int textureHeight = height * tileResolution; // Texture2D texture2 = new Texture2D(textureWidth, textureHeight); // texture2.name = "Secondary Land Texture"; // // Turn land regions into an array for faster searching // //LandRegion[] Regions = landRegions.ToArray(); // GraphicTile.TileLandTypes currLandType = baseLandType; // Color[][] tiles = SplitTileSheet(currLandType); // // Use this array to Set Pixels // Color[] thisTilePixels; // // Create land regions, limit them to a total of regions, using the otherTiles positions // landRegions = new List<LandRegion>(); // for (int x = 0; x < width; x++) // { // for (int y = 0; y < height; y++) // { // Vector2 thisPosition = new Vector2(x, y); // //This is a "hacky" way of doing it, if posIndex does not come back with a hit it'll return as 99999 // int posIndex = GetIndexOfExistingTile(potentialPositions.ToArray(), thisPosition); // int skipOrNo = Random.Range(0, 2); // if (posIndex < potentialPositions.Count && skipOrNo > 0) // { // // We hit a potential tile position. // // This is the starting position // Vector2 startingPosition = thisPosition; // Debug.Log("New Starting Position: " + startingPosition); // //Decide how many tiles this region will have (MINIMUM = 9, MAX can be the number that looks best // //int maxtiles = Random.Range(9, 28); // int maxtiles = 10; // //Construct a new Land Region // LandRegion newRegion = new LandRegion(startingPosition, maxtiles); // // Loop through the region's max tiles assigning a position // for (int m = 0; m < maxtiles; m++) // { // // Fill the new Region's positions, including starting pos // // To make sure this region will be a nice grid we need to force the positions // // First one is potentialPositions[posIndex] // if (m == 0) // { // newRegion.tilePosList.Add(potentialPositions[posIndex]); // } // else if (m >= 1 && m <= 2) // { // // Second potentialPositions[posIndex].x, potentialPositions[posIndex].y + 1 // // Third potentialPositions[posIndex].x, potentialPositions[posIndex].y + 2 // Vector2 newPosition = new Vector2(potentialPositions[posIndex].x, potentialPositions[posIndex].y + m); // newRegion.tilePosList.Add(newPosition); // } // // Now second column // else if (m == 3) // { // // Fourth potentialPositions[posIndex].x + 1, potentialPositions[posIndex].y // Vector2 newPosition = new Vector2(potentialPositions[posIndex].x + 1, potentialPositions[posIndex].y); // newRegion.tilePosList.Add(newPosition); // } // else if (m == 4) // { // // Fifth potentialPositions[posIndex].x + 1, potentialPositions[posIndex].y + 1 // Vector2 newPosition = new Vector2(potentialPositions[posIndex].x + 1, potentialPositions[posIndex].y + 1); // newRegion.tilePosList.Add(newPosition); // } // else if (m == 5) // { // // Sixth potentialPositions[posIndex].x + 1, potentialPositions[posIndex].y + 2 // Vector2 newPosition = new Vector2(potentialPositions[posIndex].x + 1, potentialPositions[posIndex].y + 2); // newRegion.tilePosList.Add(newPosition); // } // // Third column // else if (m == 6) // { // // Seventh potentialPositions[posIndex].x + 2, potentialPositions[posIndex].y // Vector2 newPosition = new Vector2(potentialPositions[posIndex].x + 2, potentialPositions[posIndex].y); // newRegion.tilePosList.Add(newPosition); // }else if (m == 7) // { // // Eigth potentialPositions[posIndex].x + 2, potentialPositions[posIndex].y + 1 // Vector2 newPosition = new Vector2(potentialPositions[posIndex].x + 2, potentialPositions[posIndex].y + 1); // newRegion.tilePosList.Add(newPosition); // } // else // { // // Ninth potentialPositions[posIndex].x + 2, potentialPositions[posIndex].y + 2 // Vector2 newPosition = new Vector2(potentialPositions[posIndex].x + 2, potentialPositions[posIndex].y + 2); // newRegion.tilePosList.Add(newPosition); // } // //// Add this position to the region's Tile Positions List but make sure PosIndex + M is < total of potential Positions // //if (posIndex + m < potentialPositions.Count) // //{ // // newRegion.tilePosList.Add(potentialPositions[posIndex + m]); // // Debug.Log("New Region Position: " + potentialPositions[posIndex + m]); // // // Instead of removing I can make it a null vector 2 // // potentialPositions[posIndex + m] = Vector2.zero; // //} // } // // After assigning the positions to the region, we need to clean up the list inside the region and make it an array of V2 // newRegion.CleanUpListAndCreateArray(); // // Now that this region's positions are defined, add it to the list of regions // landRegions.Add(newRegion); // // remove as a potential position to avoid overlap between regions, this will be a clear tile once the tex is generated // //for (int i = 0; i < maxtiles; i++) // //{ // // potentialPositions.RemoveAt(posIndex + i); // **** This is probably f*****g up the index later on since it reduces the list // //} // } // else // { // // Not a potential position, set this to clear tile // // Set clear pixels // thisTilePixels = clearPixels; // texture2.SetPixels(x * tileResolution, y * tileResolution, tileResolution, tileResolution, thisTilePixels); // } // } // } // // Now we define each region's graphic tiles // if (landRegions.Count > 0) // DefineLandRegionTiles(width, height, landRegions.ToArray(), texture2); // //Debug.Log("Region #" + (landRegions.Count - 1) + ", Max Tiles = " + newRegion.MaxTiles + ", TilePosArray = " + newRegion.TilePositions.Length + ", Tiles = " + newRegion.RegionTiles.Length); //} /* // For each region's region tile, decide wether it's a land or clear tile int random = Random.Range(0, 100); if (random<randomFillPercent) { // This is a land tile // Choose new land type GraphicTile.TileLandTypes newLandType = GetNewLandType(baseLandType); // Loop through the region's set Tile Positions and define the Tiles for (int i = 0; i<newRegion.TilePositions.Length; i++) { // Define this new region's tile newRegion.RegionTiles[i] = DefineRegionTile(newLandType, newRegion.TilePositions, newRegion.TilePositions[i], newRegion.RegionTiles); Debug.Log("Tile defined. " + newRegion.RegionTiles[i].MyTilePosType + " " + newRegion.RegionTiles[i].MyTileEdgeType); // Set Pixels tiles = SplitTileSheet(newLandType); thisTilePixels = tiles[FindIndex(newRegion.RegionTiles[i].MyTilePosType, newRegion.RegionTiles[i].MyTileEdgeType, newRegion.RegionTiles[i].MyTileLandType)]; texture2.SetPixels(x* tileResolution, y * tileResolution, tileResolution, tileResolution, thisTilePixels); } } else { //clear tile // remove this as a potential position potentialPositions.RemoveAt(posIndex); Debug.Log("Potential positions = " + potentialPositions.Count); // Set clear pixels thisTilePixels = clearPixels; texture2.SetPixels(x* tileResolution, y * tileResolution, tileResolution, tileResolution, thisTilePixels); } // Define the Graphic Tiles in this region as Clear and Undefined first for (int t = 0; t<r.RegionTiles.Length; t++) { r.RegionTiles[t] = new GraphicTile(GraphicTile.TilePositionTypes.CLEAR, GraphicTile.TileEdgeTypes.UNDEFINED, baseLandType, r.TilePositions[t]); } // Loop through the tilePositions array in this region // for (int x = 0; x < r.TilePositions.Length; x++) // { r.RegionTiles[x] = DefineRegionTile(GetNewLandType(baseLandType), r.TilePositions, r.TilePositions[x], r.RegionTiles); // } */ void DefineLandRegionTiles(int width, int height, LandRegion[] regions, Texture2D secondTexture) { GraphicTile.TileLandTypes currLandType = baseLandType; Color[][] tiles = SplitTileSheet(currLandType); // Use this array to Set Pixels Color[] thisTilePixels; foreach (LandRegion r in regions) { // Choose new land type for this region GraphicTile.TileLandTypes newLandType = GetNewLandType(baseLandType); // Loop through the Region's tiles for (int t = 0; t < r.RegionTiles.Length; t++) { // Decide wether it's land or clear //int decision = Random.Range(0, 101); // if (1 < 2) // { // This is land r.RegionTiles[t] = DefineRegionTile(newLandType, r.TilePositions, r.TilePositions[t], r.RegionTiles); if (newLandType != currLandType) { currLandType = newLandType; tiles = SplitTileSheet(currLandType); } // Set Pixels thisTilePixels = tiles[FindIndex(r.RegionTiles[t].MyTilePosType, r.RegionTiles[t].MyTileEdgeType, r.RegionTiles[t].MyTileLandType)]; // Get tile pos as int int x = (int)r.RegionTiles[t].MyPos.x; int y = (int)r.RegionTiles[t].MyPos.y; secondTexture.SetPixels(x * tileResolution, y * tileResolution, tileResolution, tileResolution, thisTilePixels); // } //else //{ // // This is a clear tile // r.RegionTiles[t] = new GraphicTile(GraphicTile.TilePositionTypes.CLEAR, r.TilePositions[t]); // // Set clear pixels // thisTilePixels = clearPixels; // // Get tile pos as int // int x = (int)r.RegionTiles[t].MyPos.x; // int y = (int)r.RegionTiles[t].MyPos.y; // secondTexture.SetPixels(x * tileResolution, y * tileResolution, tileResolution, tileResolution, thisTilePixels); //} } } // int random = Random.Range(0, regions.Length); // int randomTile = Random.Range(0, regions[random].RegionTiles.Length); // Debug.Log("Land Region " + random + "'s " + random + "th Tile is defined as " + regions[random].RegionTiles[randomTile].MyTilePosType + // " of Edge type " + regions[random].RegionTiles[randomTile].MyTileEdgeType); // Once ALL regions are created: // Give all their data and respective tile types to a texture. //BuildSecondaryTexture(width, height, regions); secondTexture.filterMode = FilterMode.Bilinear; Texture2 = secondTexture; ApplyTextures(); }
private void Draw(Simulation simulation) { if (_surfaceImage.Source != null) { return; } var group = new DrawingGroup(); using (DrawingContext context = group.Open()) { var surfaceRect = new Rect(0, 0, ActualWidth, ActualHeight); context.PushClip(new RectangleGeometry(surfaceRect)); context.DrawRectangle( Brushes.White, null, surfaceRect); double xRatio = ActualWidth / simulation.Width; double yRatio = ActualHeight / simulation.Height; Pen pen = new Pen { Brush = Brushes.Blue, //Thickness = 2 }; foreach (Drop drop in simulation.Drops) { double x = xRatio * drop.PositionX; double y = ActualHeight - yRatio * drop.PositionY; context.DrawLine(pen, new Point(x, y), new Point(x - ActualWidth * drop.VelocityX * drop.Volume, y - 5 * ActualHeight / 300 * drop.Volume)); } for (int i = 0; i < simulation.Land.Regions.Count; ++i) { LandRegion landRegion = simulation.Land.Regions[i]; double landRegionWidth = xRatio; double landRegionHeight = yRatio * landRegion.Height; if (landRegionHeight > 0) { var landRegionRect = new Rect( x: i * landRegionWidth, y: ActualHeight - landRegionHeight, width: landRegionWidth, height: landRegionHeight); context.DrawRectangle(Brushes.Black, null, landRegionRect); } double landRegionWaterHeight = yRatio * landRegion.Water; var landRegionWaterRect = new Rect( x: i * landRegionWidth, y: ActualHeight - landRegionHeight - landRegionWaterHeight, width: landRegionWidth, height: landRegionWaterHeight); context.DrawRectangle(Brushes.DarkBlue, null, landRegionWaterRect); } } group.Freeze(); _surfaceImage.Source = new DrawingImage(group); }