示例#1
0
        public void Draw()
        {
            if ( Text == null )
            {
                return;
            }
            if ( Text.Length == 0 )
            {
                return;
            }
            if ( TextFont == null )
            {
                return;
            }

            var CharCode = 0;
            float CharWidth = 0;
            var TexRatio = new XYDouble();
            float LetterPosA = 0;
            float LetterPosB = 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++ )
            {
                CharCode = Text[A];
                if ( CharCode >= 0 & CharCode <= 255 )
                {
                    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);
                    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 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].MapViewGlTextureNum;
                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();
        }
示例#3
0
        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 X = 0;
            var Y = 0;
            var Num = 0;
            var XY_int = new XYInt();
            var A = 0;
            var Vertex0 = new XYDouble();
            var Vertex1 = new XYDouble();
            var Vertex2 = new XYDouble();
            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);

                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].TextureViewGlTextureNum;
                        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.Tile_TypeNum[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;
                    Vertex0 = TileUtil.GetTileRotatedPos_sng(App.TextureOrientation, UnrotatedPos);
                    UnrotatedPos.X = 0.5F;
                    UnrotatedPos.Y = 0.25F;
                    Vertex1 = TileUtil.GetTileRotatedPos_sng(App.TextureOrientation, UnrotatedPos);
                    UnrotatedPos.X = 0.5F;
                    UnrotatedPos.Y = 0.5F;
                    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
                {
                    var TextLabel = default(clsTextLabel);
                    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;
                            }
                            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;
                    XY_int.X = A - A / TextureCount.X * TextureCount.X;
                    XY_int.Y = A / TextureCount.X;
                    GL.Begin(BeginMode.LineLoop);
                    GL.Color3(1.0F, 1.0F, 0.0F);
                    GL.Vertex2(XY_int.X * 64, XY_int.Y * 64);
                    GL.Vertex2(XY_int.X * 64, XY_int.Y * 64.0D + 64);
                    GL.Vertex2(XY_int.X * 64 + 64, XY_int.Y * 64 + 64);
                    GL.Vertex2(XY_int.X * 64 + 64, XY_int.Y * 64);
                    GL.End();
                }
            }

            GL.Flush();
            OpenGLControl.SwapBuffers();

            Refresh();
        }
示例#4
0
 public XYDouble(double X, double Y)
 {
     this = new XYDouble();
     this.X = X;
     this.Y = Y;
 }
示例#5
0
 public void CalcNodePos(PathfinderNode Node, ref XYDouble Pos, ref int SampleCount)
 {
     if ( Node.GetLayer.GetNetwork_LayerNum == 0 )
     {
         var NodeTag = default(clsNodeTag);
         NodeTag = (clsNodeTag)Node.Tag;
         Pos.X += NodeTag.Pos.X;
         Pos.Y += NodeTag.Pos.Y;
     }
     else
     {
         var A = 0;
         for ( A = 0; A <= Node.GetChildNodeCount - 1; A++ )
         {
             CalcNodePos(Node.get_GetChildNode(A), ref Pos, ref SampleCount);
         }
         SampleCount += Node.GetChildNodeCount;
     }
 }
示例#6
0
        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) + 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) + 1];
                    Generator.SymmetryBlocks[0].XYNum = new XYInt(0, 0);
                    Generator.SymmetryBlocks[0].Orientation = new TileOrientation(false, false, false);
                    Generator.SymmetryBlocks[0].ReflectToNum = new int[(((int)Math.Round(Generator.SymmetryBlockCount / 2.0)) - 1) + 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[(((int)Math.Round(Generator.SymmetryBlockCount / 2.0)) - 1) + 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) + 1];
                    Generator.SymmetryBlocks[0].XYNum = new XYInt(0, 0);
                    Generator.SymmetryBlocks[0].Orientation = new TileOrientation(false, false, false);
                    Generator.SymmetryBlocks[0].ReflectToNum = new int[(((int)Math.Round(Generator.SymmetryBlockCount / 2.0)) - 1) + 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[(((int)Math.Round(Generator.SymmetryBlockCount / 2.0)) - 1) + 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) + 1];
                    Generator.SymmetryBlocks[0].XYNum = new XYInt(0, 0);
                    Generator.SymmetryBlocks[0].Orientation = new TileOrientation(false, false, false);
                    Generator.SymmetryBlocks[0].ReflectToNum = new int[(((int)Math.Round(Generator.SymmetryBlockCount / 2.0)) - 1) + 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[(((int)Math.Round(Generator.SymmetryBlockCount / 2.0)) - 1) + 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[(((int)Math.Round(Generator.SymmetryBlockCount / 2.0)) - 1) + 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[(((int)Math.Round(Generator.SymmetryBlockCount / 2.0)) - 1) + 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) + 1];
                    Generator.SymmetryBlocks[0].XYNum = new XYInt(0, 0);
                    Generator.SymmetryBlocks[0].Orientation = new TileOrientation(false, false, false);
                    Generator.SymmetryBlocks[0].ReflectToNum = new int[(((int)Math.Round(Generator.SymmetryBlockCount / 2.0)) - 1) + 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[(((int)Math.Round(Generator.SymmetryBlockCount / 2.0)) - 1) + 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[(((int)Math.Round(Generator.SymmetryBlockCount / 2.0)) - 1) + 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[(((int)Math.Round(Generator.SymmetryBlockCount / 2.0)) - 1) + 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) + 1];
                    Generator.SymmetryBlocks[0].XYNum = new XYInt(0, 0);
                    Generator.SymmetryBlocks[0].Orientation = new TileOrientation(false, false, false);
                    Generator.SymmetryBlocks[0].ReflectToNum = new int[(((int)Math.Round(Generator.SymmetryBlockCount / 2.0)) - 1) + 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[(((int)Math.Round(Generator.SymmetryBlockCount / 2.0)) - 1) + 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[(((int)Math.Round(Generator.SymmetryBlockCount / 2.0)) - 1) + 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[(((int)Math.Round(Generator.SymmetryBlockCount / 2.0)) - 1) + 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(clsResult);
            do
            {
                Result = new clsResult("", 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);
        }
示例#7
0
        public bool ScreenXY_Get_ViewPlanePos_ForwardDownOnly(int screenX, int screenY, double planeHeight, ref XYDouble resultPos)
        {
            double dblTemp = 0;
            var xYZ_dbl = default(XYZDouble);
            var xYZ_dbl2 = default(XYZDouble);
            double dblTemp2 = 0;

            if ( ViewPos.Y < planeHeight )
            {
                return false;
            }

            try
            {
                //convert screen pos to vector of one pos unit
                dblTemp2 = FOVMultiplier;
                xYZ_dbl.X = (screenX - MapViewControl.GLSize.X / 2.0D) * dblTemp2;
                xYZ_dbl.Y = (MapViewControl.GLSize.Y / 2.0D - screenY) * dblTemp2;
                xYZ_dbl.Z = 1.0D;
                //factor in the view angle
                Matrix3DMath.VectorRotationByMatrix(ViewAngleMatrix, xYZ_dbl, ref xYZ_dbl2);
                //get distance to cover the height
                if ( xYZ_dbl2.Y > 0.0D )
                {
                    return false;
                }
                dblTemp = (planeHeight - ViewPos.Y) / xYZ_dbl2.Y;
                resultPos.X = ViewPos.X + xYZ_dbl2.X * dblTemp;
                resultPos.Y = ViewPos.Z + xYZ_dbl2.Z * dblTemp;
            }
            catch
            {
                return false;
            }
            return true;
        }
示例#8
0
        public bool ScreenXY_Get_ViewPlanePos(XYInt ScreenPos, double PlaneHeight, ref XYDouble ResultPos)
        {
            double dblTemp = 0;
            var XYZ_dbl = default(XYZDouble);
            var XYZ_dbl2 = default(XYZDouble);

            try
            {
                //convert screen pos to vector of one pos unit
                XYZ_dbl.X = (ScreenPos.X - MapViewControl.GLSize.X / 2.0D) * FOVMultiplier;
                XYZ_dbl.Y = (MapViewControl.GLSize.Y / 2.0D - ScreenPos.Y) * FOVMultiplier;
                XYZ_dbl.Z = 1.0D;
                //factor in the view angle
                Matrix3DMath.VectorRotationByMatrix(ViewAngleMatrix, XYZ_dbl, ref XYZ_dbl2);
                //get distance to cover the height
                dblTemp = (PlaneHeight - ViewPos.Y) / XYZ_dbl2.Y;
                ResultPos.X = ViewPos.X + XYZ_dbl2.X * dblTemp;
                ResultPos.Y = ViewPos.Z + XYZ_dbl2.Z * dblTemp;
            }
            catch
            {
                return false;
            }
            return true;
        }
示例#9
0
 public static double GetAngle(XYDouble Length)
 {
     return Math.Atan2(Length.Y, Length.X);
 }
示例#10
0
        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;
                }
            }
        }
示例#11
0
        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;
        }