public void Draw() { if (Text == null) { return; } if (Text.Length == 0) { return; } if (TextFont == null) { return; } var texRatio = new XYDouble(); float letterPosA = 0; float posY1 = 0; float posY2 = 0; float charSpacing = 0; var a = 0; GL.Color4(Colour.Red, Colour.Green, Colour.Blue, Colour.Alpha); posY1 = Pos.Y; posY2 = Pos.Y + SizeY; charSpacing = SizeY / 10.0F; letterPosA = Pos.X; for (a = 0; a <= Text.Length - 1; a++) { int charCode = Text[a]; if (charCode >= 0 & charCode <= 255) { float charWidth = SizeY * TextFont.Character[charCode].Width / TextFont.Height; texRatio.X = (float)((double)TextFont.Character[charCode].Width / TextFont.Character[charCode].TexSize); texRatio.Y = (float)((double)TextFont.Height / TextFont.Character[charCode].TexSize); float letterPosB = letterPosA + charWidth; GL.BindTexture(TextureTarget.Texture2D, TextFont.Character[charCode].GLTexture); GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)TextureEnvMode.Modulate); GL.Begin(BeginMode.Quads); GL.TexCoord2(0.0F, 0.0F); GL.Vertex2(letterPosA, posY1); GL.TexCoord2(0.0F, texRatio.Y); GL.Vertex2(letterPosA, posY2); GL.TexCoord2(texRatio.X, texRatio.Y); GL.Vertex2(letterPosB, posY2); GL.TexCoord2(texRatio.X, 0.0F); GL.Vertex2(letterPosB, posY1); GL.End(); letterPosA = letterPosB + charSpacing; } } }
public static XYDouble GetTileRotatedPos_sng(TileOrientation tileOrientation, XYDouble pos) { var returnResult = new XYDouble(); if (tileOrientation.SwitchedAxes) { if (tileOrientation.ResultXFlip) { returnResult.X = 1.0F - pos.Y; } else { returnResult.X = pos.Y; } if (tileOrientation.ResultYFlip) { returnResult.Y = 1.0F - pos.X; } else { returnResult.Y = pos.X; } } else { if (tileOrientation.ResultXFlip) { returnResult.X = 1.0F - pos.X; } else { returnResult.X = pos.X; } if (tileOrientation.ResultYFlip) { returnResult.Y = 1.0F - pos.Y; } else { returnResult.Y = pos.Y; } } return(returnResult); }
public static double GetAngle(XYDouble length) { return(Math.Atan2(length.Y, length.X)); }
public static void GetTileRotatedTexCoords(TileOrientation tileOrientation, ref XYDouble coordA, ref XYDouble coordB, ref XYDouble coordC, ref XYDouble coordD) { var reverseOrientation = new TileOrientation(); reverseOrientation = tileOrientation; reverseOrientation.Reverse(); if (reverseOrientation.SwitchedAxes) { if (reverseOrientation.ResultXFlip) { coordA.X = 1f; coordB.X = 1f; coordC.X = 0f; coordD.X = 0f; } else { coordA.X = 0f; coordB.X = 0f; coordC.X = 1f; coordD.X = 1f; } if (reverseOrientation.ResultYFlip) { coordA.Y = 1f; coordB.Y = 0f; coordC.Y = 1f; coordD.Y = 0f; } else { coordA.Y = 0f; coordB.Y = 1f; coordC.Y = 0f; coordD.Y = 1f; } } else { if (reverseOrientation.ResultXFlip) { coordA.X = 1f; coordB.X = 0f; coordC.X = 1f; coordD.X = 0f; } else { coordA.X = 0f; coordB.X = 1F; coordC.X = 0f; coordD.X = 1f; } if (reverseOrientation.ResultYFlip) { coordA.Y = 1f; coordB.Y = 1f; coordC.Y = 0f; coordD.Y = 0f; } else { coordA.Y = 0f; coordB.Y = 0f; coordC.Y = 1f; coordD.Y = 1f; } } }
private void DrawView() { if (!(DrawView_Enabled && IsGLInitialized)) { return; } if (GraphicsContext.CurrentContext != OpenGLControl.Context) { OpenGLControl.MakeCurrent(); } GL.Clear(ClearBufferMask.ColorBufferBit); var map = MainMap; if (map == null) { GL.Flush(); OpenGLControl.SwapBuffers(); Refresh(); return; } var xyInt = new XYInt(); var unrotatedPos = new XYDouble(); var texCoord0 = new XYDouble(); var texCoord1 = new XYDouble(); var texCoord2 = new XYDouble(); var texCoord3 = new XYDouble(); GL.MatrixMode(MatrixMode.Projection); var temp_mat = Matrix4.CreateOrthographicOffCenter(0.0F, GLSize.X, GLSize.Y, 0.0F, -1.0F, 1.0F); GL.LoadMatrix(ref temp_mat); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); if (map.Tileset != null) { TileUtil.GetTileRotatedTexCoords(App.TextureOrientation, ref texCoord0, ref texCoord1, ref texCoord2, ref texCoord3); GL.Enable(EnableCap.Texture2D); GL.Color4(0.0F, 0.0F, 0.0F, 1.0F); var x = 0; var y = 0; var num = 0; var a = 0; for (y = 0; y <= TextureCount.Y - 1; y++) { for (x = 0; x <= TextureCount.X - 1; x++) { num = (TextureYOffset + y) * TextureCount.X + x; if (num >= map.Tileset.TileCount) { goto EndOfTextures1; } a = map.Tileset.Tiles[num].GlTextureNum; GL.BindTexture(TextureTarget.Texture2D, a); GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)TextureEnvMode.Decal); GL.Begin(BeginMode.Quads); GL.TexCoord2(texCoord0.X, texCoord0.Y); GL.Vertex2(x * 64, y * 64); // Top Left GL.TexCoord2(texCoord1.X, texCoord1.Y); GL.Vertex2(x * 64 + 64, y * 64); // Bottom Left GL.TexCoord2(texCoord3.X, texCoord3.Y); GL.Vertex2(x * 64 + 64, y * 64 + 64); // Bottom right GL.TexCoord2(texCoord2.X, texCoord2.Y); GL.Vertex2(x * 64, y * 64 + 64); // Top right GL.End(); } } EndOfTextures1: GL.Disable(EnableCap.Texture2D); if (DisplayTileTypes) { GL.Begin(BeginMode.Quads); for (y = 0; y <= TextureCount.Y - 1; y++) { for (x = 0; x <= TextureCount.X - 1; x++) { num = (TextureYOffset + y) * TextureCount.X + x; if (num >= map.Tileset.TileCount) { goto EndOfTextures2; } a = map.TileTypeNum[num]; GL.Color3(App.TileTypes[a].DisplayColour.Red, App.TileTypes[a].DisplayColour.Green, App.TileTypes[a].DisplayColour.Blue); GL.Vertex2(x * 64 + 24, y * 64 + 24); GL.Vertex2(x * 64 + 24, y * 64 + 40); GL.Vertex2(x * 64 + 40, y * 64 + 40); GL.Vertex2(x * 64 + 40, y * 64 + 24); } } EndOfTextures2: GL.End(); } if (App.DisplayTileOrientation) { GL.Disable(EnableCap.CullFace); unrotatedPos.X = 0.25F; unrotatedPos.Y = 0.25F; var vertex0 = TileUtil.GetTileRotatedPos_sng(App.TextureOrientation, unrotatedPos); unrotatedPos.X = 0.5F; unrotatedPos.Y = 0.25F; var vertex1 = TileUtil.GetTileRotatedPos_sng(App.TextureOrientation, unrotatedPos); unrotatedPos.X = 0.5F; unrotatedPos.Y = 0.5F; var vertex2 = TileUtil.GetTileRotatedPos_sng(App.TextureOrientation, unrotatedPos); GL.Begin(BeginMode.Triangles); GL.Color3(1.0F, 1.0F, 0.0F); for (y = 0; y <= TextureCount.Y - 1; y++) { for (x = 0; x <= TextureCount.X - 1; x++) { num = (TextureYOffset + y) * TextureCount.X + x; if (num >= map.Tileset.TileCount) { goto EndOfTextures3; } GL.Vertex2(x * 64 + vertex0.X * 64, y * 64 + vertex0.Y * 64); GL.Vertex2(x * 64 + vertex2.X * 64, y * 64 + vertex2.Y * 64); GL.Vertex2(x * 64 + vertex1.X * 64, y * 64 + vertex1.Y * 64); } } EndOfTextures3: GL.End(); GL.Enable(EnableCap.CullFace); } if (DisplayTileNumbers && App.UnitLabelFont != null) //TextureViewFont IsNot Nothing Then { GL.Enable(EnableCap.Texture2D); for (y = 0; y <= TextureCount.Y - 1; y++) { for (x = 0; x <= TextureCount.X - 1; x++) { num = (TextureYOffset + y) * TextureCount.X + x; if (num >= map.Tileset.TileCount) { goto EndOfTextures4; } clsTextLabel textLabel = new clsTextLabel(); textLabel.Text = num.ToStringInvariant(); textLabel.SizeY = 24.0F; textLabel.Colour.Red = 1.0F; textLabel.Colour.Green = 1.0F; textLabel.Colour.Blue = 0.0F; textLabel.Colour.Alpha = 1.0F; textLabel.Pos.X = x * 64; textLabel.Pos.Y = y * 64; textLabel.TextFont = App.UnitLabelFont; //TextureViewFont textLabel.Draw(); } } EndOfTextures4: GL.Disable(EnableCap.Texture2D); } if (App.SelectedTextureNum >= 0 & TextureCount.X > 0) { a = App.SelectedTextureNum - TextureYOffset * TextureCount.X; xyInt.X = a - a / TextureCount.X * TextureCount.X; xyInt.Y = a / TextureCount.X; GL.Begin(BeginMode.LineLoop); GL.Color3(1.0F, 1.0F, 0.0F); GL.Vertex2(xyInt.X * 64, xyInt.Y * 64); GL.Vertex2(xyInt.X * 64, xyInt.Y * 64.0D + 64); GL.Vertex2(xyInt.X * 64 + 64, xyInt.Y * 64 + 64); GL.Vertex2(xyInt.X * 64 + 64, xyInt.Y * 64); GL.End(); } } GL.Flush(); OpenGLControl.SwapBuffers(); Refresh(); }
public void btnGenerateLayout_Click(Object sender, EventArgs e) { lstResult.Items.Clear(); btnGenerateLayout.Enabled = false; lstResult_AddText("Generating layout."); Application.DoEvents(); StopTrying = false; var LoopCount = 0; Generator.ClearLayout(); Generator.GenerateTileset = null; Generator.Map = null; Generator.TopLeftPlayerCount = PlayerCount; switch (cboSymmetry.SelectedIndex) { case 0: //none Generator.SymmetryBlockCountXY.X = 1; Generator.SymmetryBlockCountXY.Y = 1; Generator.SymmetryBlockCount = 1; Generator.SymmetryBlocks = new clsGenerateMap.sSymmetryBlock[Generator.SymmetryBlockCount - 1]; Generator.SymmetryBlocks[0].XYNum = new XYInt(0, 0); Generator.SymmetryBlocks[0].Orientation = new TileOrientation(false, false, false); Generator.SymmetryIsRotational = false; break; case 1: //h rotation Generator.SymmetryBlockCountXY.X = 2; Generator.SymmetryBlockCountXY.Y = 1; Generator.SymmetryBlockCount = 2; Generator.SymmetryBlocks = new clsGenerateMap.sSymmetryBlock[Generator.SymmetryBlockCount - 1]; Generator.SymmetryBlocks[0].XYNum = new XYInt(0, 0); Generator.SymmetryBlocks[0].Orientation = new TileOrientation(false, false, false); Generator.SymmetryBlocks[0].ReflectToNum = new int[((double)Generator.SymmetryBlockCount / 2).ToInt() - 1]; Generator.SymmetryBlocks[0].ReflectToNum[0] = 1; Generator.SymmetryBlocks[1].XYNum = new XYInt(1, 0); Generator.SymmetryBlocks[1].Orientation = new TileOrientation(true, true, false); Generator.SymmetryBlocks[1].ReflectToNum = new int[((double)Generator.SymmetryBlockCount / 2).ToInt() - 1]; Generator.SymmetryBlocks[1].ReflectToNum[0] = 0; Generator.SymmetryIsRotational = true; break; case 2: //v rotation Generator.SymmetryBlockCountXY.X = 1; Generator.SymmetryBlockCountXY.Y = 2; Generator.SymmetryBlockCount = 2; Generator.SymmetryBlocks = new clsGenerateMap.sSymmetryBlock[Generator.SymmetryBlockCount - 1]; Generator.SymmetryBlocks[0].XYNum = new XYInt(0, 0); Generator.SymmetryBlocks[0].Orientation = new TileOrientation(false, false, false); Generator.SymmetryBlocks[0].ReflectToNum = new int[((double)Generator.SymmetryBlockCount / 2).ToInt() - 1]; Generator.SymmetryBlocks[0].ReflectToNum[0] = 1; Generator.SymmetryBlocks[1].XYNum = new XYInt(0, 1); Generator.SymmetryBlocks[1].Orientation = new TileOrientation(true, true, false); Generator.SymmetryBlocks[1].ReflectToNum = new int[((double)Generator.SymmetryBlockCount / 2).ToInt() - 1]; Generator.SymmetryBlocks[1].ReflectToNum[0] = 0; Generator.SymmetryIsRotational = true; break; case 3: //h flip Generator.SymmetryBlockCountXY.X = 2; Generator.SymmetryBlockCountXY.Y = 1; Generator.SymmetryBlockCount = 2; Generator.SymmetryBlocks = new clsGenerateMap.sSymmetryBlock[Generator.SymmetryBlockCount - 1]; Generator.SymmetryBlocks[0].XYNum = new XYInt(0, 0); Generator.SymmetryBlocks[0].Orientation = new TileOrientation(false, false, false); Generator.SymmetryBlocks[0].ReflectToNum = new int[((double)Generator.SymmetryBlockCount / 2).ToInt() - 1]; Generator.SymmetryBlocks[0].ReflectToNum[0] = 1; Generator.SymmetryBlocks[1].XYNum = new XYInt(1, 0); Generator.SymmetryBlocks[1].Orientation = new TileOrientation(true, false, false); Generator.SymmetryBlocks[1].ReflectToNum = new int[((double)Generator.SymmetryBlockCount / 2).ToInt() - 1]; Generator.SymmetryBlocks[1].ReflectToNum[0] = 0; Generator.SymmetryIsRotational = false; break; case 4: //v flip Generator.SymmetryBlockCountXY.X = 1; Generator.SymmetryBlockCountXY.Y = 2; Generator.SymmetryBlockCount = 2; Generator.SymmetryBlocks = new clsGenerateMap.sSymmetryBlock[(Generator.SymmetryBlockCount - 1) + 1]; Generator.SymmetryBlocks[0].XYNum = new XYInt(0, 0); Generator.SymmetryBlocks[0].Orientation = new TileOrientation(false, false, false); Generator.SymmetryBlocks[0].ReflectToNum = new int[((double)Generator.SymmetryBlockCount / 2).ToInt() - 1]; Generator.SymmetryBlocks[0].ReflectToNum[0] = 1; Generator.SymmetryBlocks[1].XYNum = new XYInt(0, 1); Generator.SymmetryBlocks[1].Orientation = new TileOrientation(false, true, false); Generator.SymmetryBlocks[1].ReflectToNum = new int[((double)Generator.SymmetryBlockCount / 2).ToInt() - 1]; Generator.SymmetryBlocks[1].ReflectToNum[0] = 0; Generator.SymmetryIsRotational = false; Generator.SymmetryIsRotational = false; break; case 5: //4x rotation Generator.SymmetryBlockCountXY.X = 2; Generator.SymmetryBlockCountXY.Y = 2; Generator.SymmetryBlockCount = 4; Generator.SymmetryBlocks = new clsGenerateMap.sSymmetryBlock[Generator.SymmetryBlockCount - 1]; Generator.SymmetryBlocks[0].XYNum = new XYInt(0, 0); Generator.SymmetryBlocks[0].Orientation = new TileOrientation(false, false, false); Generator.SymmetryBlocks[0].ReflectToNum = new int[((double)Generator.SymmetryBlockCount / 2).ToInt() - 1]; Generator.SymmetryBlocks[0].ReflectToNum[0] = 1; Generator.SymmetryBlocks[0].ReflectToNum[1] = 2; Generator.SymmetryBlocks[1].XYNum = new XYInt(1, 0); Generator.SymmetryBlocks[1].Orientation = new TileOrientation(true, false, true); Generator.SymmetryBlocks[1].ReflectToNum = new int[((double)Generator.SymmetryBlockCount / 2).ToInt() - 1]; Generator.SymmetryBlocks[1].ReflectToNum[0] = 3; Generator.SymmetryBlocks[1].ReflectToNum[1] = 0; Generator.SymmetryBlocks[2].XYNum = new XYInt(0, 1); Generator.SymmetryBlocks[2].Orientation = new TileOrientation(false, true, true); Generator.SymmetryBlocks[2].ReflectToNum = new int[((double)Generator.SymmetryBlockCount / 2).ToInt() - 1]; Generator.SymmetryBlocks[2].ReflectToNum[0] = 0; Generator.SymmetryBlocks[2].ReflectToNum[1] = 3; Generator.SymmetryBlocks[3].XYNum = new XYInt(1, 1); Generator.SymmetryBlocks[3].Orientation = new TileOrientation(true, true, false); Generator.SymmetryBlocks[3].ReflectToNum = new int[((double)Generator.SymmetryBlockCount / 2).ToInt() - 1]; Generator.SymmetryBlocks[3].ReflectToNum[0] = 2; Generator.SymmetryBlocks[3].ReflectToNum[1] = 1; Generator.SymmetryIsRotational = true; break; case 6: //hv flip Generator.SymmetryBlockCountXY.X = 2; Generator.SymmetryBlockCountXY.Y = 2; Generator.SymmetryBlockCount = 4; Generator.SymmetryBlocks = new clsGenerateMap.sSymmetryBlock[Generator.SymmetryBlockCount - 1]; Generator.SymmetryBlocks[0].XYNum = new XYInt(0, 0); Generator.SymmetryBlocks[0].Orientation = new TileOrientation(false, false, false); Generator.SymmetryBlocks[0].ReflectToNum = new int[((double)Generator.SymmetryBlockCount / 2).ToInt() - 1]; Generator.SymmetryBlocks[0].ReflectToNum[0] = 1; Generator.SymmetryBlocks[0].ReflectToNum[1] = 2; Generator.SymmetryBlocks[1].XYNum = new XYInt(1, 0); Generator.SymmetryBlocks[1].Orientation = new TileOrientation(true, false, false); Generator.SymmetryBlocks[1].ReflectToNum = new int[((double)Generator.SymmetryBlockCount / 2).ToInt() - 1]; Generator.SymmetryBlocks[1].ReflectToNum[0] = 0; Generator.SymmetryBlocks[1].ReflectToNum[1] = 3; Generator.SymmetryBlocks[2].XYNum = new XYInt(0, 1); Generator.SymmetryBlocks[2].Orientation = new TileOrientation(false, true, false); Generator.SymmetryBlocks[2].ReflectToNum = new int[((double)Generator.SymmetryBlockCount / 2).ToInt() - 1]; Generator.SymmetryBlocks[2].ReflectToNum[0] = 3; Generator.SymmetryBlocks[2].ReflectToNum[1] = 0; Generator.SymmetryBlocks[3].XYNum = new XYInt(1, 1); Generator.SymmetryBlocks[3].Orientation = new TileOrientation(true, true, false); Generator.SymmetryBlocks[3].ReflectToNum = new int[((double)Generator.SymmetryBlockCount / 2).ToInt() - 1]; Generator.SymmetryBlocks[3].ReflectToNum[0] = 2; Generator.SymmetryBlocks[3].ReflectToNum[1] = 1; Generator.SymmetryIsRotational = false; break; default: MessageBox.Show("Select symmetry"); btnGenerateLayout.Enabled = true; return; } if (Generator.TopLeftPlayerCount * Generator.SymmetryBlockCount < 2) { MessageBox.Show("That configuration only produces 1 player."); btnGenerateLayout.Enabled = true; return; } if (Generator.TopLeftPlayerCount * Generator.SymmetryBlockCount > 10) { MessageBox.Show("That configuration produces more than 10 players."); btnGenerateLayout.Enabled = true; return; } Generator.TileSize.X = ValidateTextbox(txtWidth, 48.0D, 250.0D, 1.0D); Generator.TileSize.Y = ValidateTextbox(txtHeight, 48.0D, 250.0D, 1.0D); if (Generator.SymmetryBlockCount == 4) { if (Generator.TileSize.X != Generator.TileSize.Y && Generator.SymmetryIsRotational) { MessageBox.Show("Width and height must be equal if map is rotated on two axes."); btnGenerateLayout.Enabled = true; return; } } Generator.PlayerBasePos = new XYInt[Generator.TopLeftPlayerCount]; var BaseMin = 12.0D; var BaseMax = new XYDouble(Math.Min((double)Generator.TileSize.X / Generator.SymmetryBlockCountXY.X, Generator.TileSize.X - 12.0D), Math.Min((double)Generator.TileSize.Y / Generator.SymmetryBlockCountXY.Y, Generator.TileSize.Y - 12.0D)); Generator.PlayerBasePos[0] = new XYInt(ValidateTextbox(txt1x, BaseMin, BaseMax.X, Constants.TerrainGridSpacing), ValidateTextbox(txt1y, BaseMin, BaseMax.X, Constants.TerrainGridSpacing)); if (Generator.TopLeftPlayerCount >= 2) { Generator.PlayerBasePos[1] = new XYInt(ValidateTextbox(txt2x, BaseMin, BaseMax.X, Constants.TerrainGridSpacing), ValidateTextbox(txt2y, BaseMin, BaseMax.Y, Constants.TerrainGridSpacing)); if (Generator.TopLeftPlayerCount >= 3) { Generator.PlayerBasePos[2] = new XYInt(ValidateTextbox(txt3x, BaseMin, BaseMax.X, Constants.TerrainGridSpacing), ValidateTextbox(txt3y, BaseMin, BaseMax.Y, Constants.TerrainGridSpacing)); if (Generator.TopLeftPlayerCount >= 4) { Generator.PlayerBasePos[3] = new XYInt(ValidateTextbox(txt4x, BaseMin, BaseMax.X, Constants.TerrainGridSpacing), ValidateTextbox(txt4y, BaseMin, BaseMax.Y, Constants.TerrainGridSpacing)); if (Generator.TopLeftPlayerCount >= 5) { Generator.PlayerBasePos[4] = new XYInt(ValidateTextbox(txt5x, BaseMin, BaseMax.X, Constants.TerrainGridSpacing), ValidateTextbox(txt5y, BaseMin, BaseMax.Y, Constants.TerrainGridSpacing)); if (Generator.TopLeftPlayerCount >= 6) { Generator.PlayerBasePos[5] = new XYInt(ValidateTextbox(txt6x, BaseMin, BaseMax.X, Constants.TerrainGridSpacing), ValidateTextbox(txt6y, BaseMin, BaseMax.Y, Constants.TerrainGridSpacing)); if (Generator.TopLeftPlayerCount >= 7) { Generator.PlayerBasePos[6] = new XYInt(ValidateTextbox(txt7x, BaseMin, BaseMax.X, Constants.TerrainGridSpacing), ValidateTextbox(txt7y, BaseMin, BaseMax.Y, Constants.TerrainGridSpacing)); if (Generator.TopLeftPlayerCount >= 8) { Generator.PlayerBasePos[7] = new XYInt(ValidateTextbox(txt8x, BaseMin, BaseMax.X, Constants.TerrainGridSpacing), ValidateTextbox(txt8y, BaseMin, BaseMax.Y, Constants.TerrainGridSpacing)); if (Generator.TopLeftPlayerCount >= 9) { Generator.PlayerBasePos[8] = new XYInt( ValidateTextbox(txt9x, BaseMin, BaseMax.X, Constants.TerrainGridSpacing), ValidateTextbox(txt9y, BaseMin, BaseMax.Y, Constants.TerrainGridSpacing)); if (Generator.TopLeftPlayerCount >= 10) { Generator.PlayerBasePos[9] = new XYInt(ValidateTextbox(txt10x, BaseMin, BaseMax.X, Constants.TerrainGridSpacing), ValidateTextbox(txt10y, BaseMin, BaseMax.Y, Constants.TerrainGridSpacing)); } } } } } } } } } Generator.LevelCount = ValidateTextbox(txtLevels, 3.0D, 5.0D, 1.0D); Generator.BaseLevel = ValidateTextbox(txtBaseLevel, -1.0D, Generator.LevelCount - 1, 1.0D); Generator.JitterScale = 1; Generator.MaxLevelTransition = 2; Generator.PassagesChance = ValidateTextbox(txtLevelFrequency, 0.0D, 100.0D, 1.0D); Generator.VariationChance = ValidateTextbox(txtVariation, 0.0D, 100.0D, 1.0D); Generator.FlatsChance = ValidateTextbox(txtFlatness, 0.0D, 100.0D, 1.0D); Generator.BaseFlatArea = ValidateTextbox(txtBaseArea, 1.0D, 16.0D, 1.0D); Generator.NodeScale = 4.0F; Generator.WaterSpawnQuantity = ValidateTextbox(txtWaterQuantity, 0.0D, 9999.0D, 1.0D); Generator.TotalWaterQuantity = ValidateTextbox(txtConnectedWater, 0.0D, 9999.0D, 1.0D); Application.DoEvents(); LoopCount = 0; var Result = default(Result); do { Result = new Result("", false); Result = Generator.GenerateLayout(); if (!Result.HasProblems) { var HeightsResult = FinishHeights(); Result.Add(HeightsResult); if (!HeightsResult.HasProblems) { lstResult_AddResult(Result); lstResult_AddText("Done."); btnGenerateLayout.Enabled = true; break; } } LoopCount++; lstResult_AddText("Attempt " + Convert.ToString(LoopCount) + " failed."); Application.DoEvents(); if (StopTrying) { Generator.Map = null; lstResult_AddResult(Result); lstResult_AddText("Stopped."); btnGenerateLayout.Enabled = true; return; } lstResult_AddResult(Result); lstResult_AddText("Retrying..."); Application.DoEvents(); Generator.ClearLayout(); } while (true); lstResult_AddResult(Result); }
public override void Perform() { var terrain = Map.Terrain; var tileset = Map.Tileset; var tileTerrainHeight = new double[5]; var vertices = new XYZDouble[5]; //4 corners + center var normals = new XYZDouble[5]; var texCoords = new XYDouble[5]; //Texture binding code copied from clsDrawTileOld if (terrain.Tiles[TileX, TileY].Texture.TextureNum < 0) { GL.BindTexture(TextureTarget.Texture2D, App.GLTexture_NoTile); } else if (tileset == null) { GL.BindTexture(TextureTarget.Texture2D, App.GLTexture_OverflowTile); } else if (terrain.Tiles[TileX, TileY].Texture.TextureNum < tileset.TileCount) { var viewGlTextureNum = tileset.Tiles[terrain.Tiles[TileX, TileY].Texture.TextureNum].GlTextureNum; if (viewGlTextureNum == 0) { GL.BindTexture(TextureTarget.Texture2D, App.GLTexture_OverflowTile); } else { GL.BindTexture(TextureTarget.Texture2D, viewGlTextureNum); } } else { GL.BindTexture(TextureTarget.Texture2D, App.GLTexture_OverflowTile); } GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)TextureEnvMode.Modulate); //Vertex order: //0 1 // 4 //2 3 tileTerrainHeight[0] = terrain.Vertices[TileX, TileY].Height; tileTerrainHeight[1] = terrain.Vertices[TileX + 1, TileY].Height; tileTerrainHeight[2] = terrain.Vertices[TileX, TileY + 1].Height; tileTerrainHeight[3] = terrain.Vertices[TileX + 1, TileY + 1].Height; tileTerrainHeight[4] = (tileTerrainHeight[0] + tileTerrainHeight[1] + tileTerrainHeight[2] + tileTerrainHeight[3]) / 4; //middle height is average of the corners TileUtil.GetTileRotatedTexCoords(terrain.Tiles[TileX, TileY].Texture.Orientation, ref texCoords[0], ref texCoords[1], ref texCoords[2], ref texCoords[3]); //cowboy: don't forget the middle texture coordinate regardless of rotation. texCoords[4].X = 0.5f; texCoords[4].Y = 0.5f; vertices[0].X = TileX * Constants.TerrainGridSpacing; vertices[0].Y = (float)(tileTerrainHeight[0] * Map.HeightMultiplier); vertices[0].Z = -TileY * Constants.TerrainGridSpacing; vertices[1].X = (TileX + 1) * Constants.TerrainGridSpacing; vertices[1].Y = (float)(tileTerrainHeight[1] * Map.HeightMultiplier); vertices[1].Z = -TileY * Constants.TerrainGridSpacing; vertices[2].X = TileX * Constants.TerrainGridSpacing; vertices[2].Y = (float)(tileTerrainHeight[2] * Map.HeightMultiplier); vertices[2].Z = -(TileY + 1) * Constants.TerrainGridSpacing; vertices[3].X = (TileX + 1) * Constants.TerrainGridSpacing; vertices[3].Y = (float)(tileTerrainHeight[3] * Map.HeightMultiplier); vertices[3].Z = -(TileY + 1) * Constants.TerrainGridSpacing; vertices[4].X = (TileX + 0.5f) * Constants.TerrainGridSpacing; vertices[4].Y = (float)(tileTerrainHeight[4] * Map.HeightMultiplier); vertices[4].Z = -(TileY + 0.5f) * Constants.TerrainGridSpacing; normals[0] = Map.TerrainVertexNormalCalc(TileX, TileY); normals[1] = Map.TerrainVertexNormalCalc(TileX + 1, TileY); normals[2] = Map.TerrainVertexNormalCalc(TileX, TileY + 1); normals[3] = Map.TerrainVertexNormalCalc(TileX + 1, TileY + 1); normals[4] = (normals[0] + normals[1] + normals[2] + normals[3]) / 4; //Linearly interpolate from corner vertices normals[4] /= normals[4].GetMagnitude(); //normalize vector length GL.Begin(BeginMode.Triangles); int[] indices = { 1, 0, 4, 3, 1, 4, 2, 3, 4, 0, 2, 4 }; foreach (var i in indices) { GL.Normal3(normals[i].X, normals[i].Y, -normals[i].Z); GL.TexCoord2(texCoords[i].X, texCoords[i].Y); GL.Vertex3(vertices[i].X, vertices[i].Y, -vertices[i].Z); } GL.End(); }