private void confirmButton_Click(object sender, EventArgs e) { //Set the image to the project's main input if (!forMask) { Form1.currentOpenProject.SetFirstHeightmap(image); } else { Form1.currentOpenProject.CreateMask(image.width, image.height); int[,] mask = Form1.currentOpenProject.GetMask(); Bitmap bit = image.ToBitmap(); for (int i = 0; i < bit.Width; i++) { for (int j = 0; j < bit.Height; j++) { Color pixel = bit.GetPixel(i, j); if (pixel == Heightmap.ValueToColor(0)) { mask[i, j] = 0; } else { mask[i, j] = 1; } } } } this.Close(); }
public override void Apply(Heightmap targetHeightmap, Bitmap targetBitmap, int x, int y, double size, double speed, double deltaTime) { double radius = size; //Make a bounding box around the circle int startX = (int)((double)x - size); int endX = (int)((double)x + size); int startY = (int)((double)y - size); int endY = (int)((double)y + size); //Make sure the corners are in bounds startX = Utils.CapBounds(startX, 0, targetHeightmap.width); endX = Utils.CapBounds(endX, 0, targetHeightmap.width); startY = Utils.CapBounds(startY, 0, targetHeightmap.height); endY = Utils.CapBounds(endY, 0, targetHeightmap.height); //Loop through the bounding box, skipping any pixels that fall outside the circle int centerX = x; int centerY = y; //Save x and y, since we're using those variable names in the loop for (x = startX; x < endX; x++) { for (y = startY; y < endY; y++) { //Skip this pixel if it's not within the radius double squaredDist = (x - centerX) * (x - centerX) + (y - centerY) * (y - centerY); if (squaredDist > radius * radius) { continue; } //Make it so the speed decreases as it gets further from the center double distPercent = squaredDist / (radius * radius); double scaledSpeed = Utils.Lerp(speed, 0, distPercent); //Change the height at this position double val = targetHeightmap.GetValue(x, y); val += scaledSpeed * deltaTime; //Ensure the value stays within the limits if (Math.Abs(val) > Heightmap.MAX_HEIGHT) { val = Math.Sign(val) * Heightmap.MAX_HEIGHT; } //Apply the height change targetHeightmap.SetValue(x, y, val); targetBitmap.SetPixel(x, y, Heightmap.ValueToColor(val)); } } //End of double for loop } //End of function
public override void Apply(Heightmap targetHeightmap, Bitmap targetBitmap, int x, int y, double size, double speed, double deltaTime) { //Make a square around the coordinates int startX = (int)((double)x - size / 2); int endX = (int)((double)x + size / 2); int startY = (int)((double)y - size / 2); int endY = (int)((double)y + size / 2); //Make sure the corners of the square are in bounds startX = Utils.CapBounds(startX, 0, targetHeightmap.width); endX = Utils.CapBounds(endX, 0, targetHeightmap.width); startY = Utils.CapBounds(startY, 0, targetHeightmap.height); endY = Utils.CapBounds(endY, 0, targetHeightmap.height); //Iterate through the square, applying the logic to it. for (x = startX; x < endX; x++) { for (y = startY; y < endY; y++) { //Change the height at this position double val = targetHeightmap.GetValue(x, y); val += speed * deltaTime; //Ensure the value stays within the limits if (Math.Abs(val) > Heightmap.MAX_HEIGHT) { val = Math.Sign(val) * Heightmap.MAX_HEIGHT; } //Apply the height change targetHeightmap.SetValue(x, y, val); targetBitmap.SetPixel(x, y, Heightmap.ValueToColor(val)); } } }