Esempio n. 1
0
        public void GLDraw()
        {
            var angleRpy = default(Angles.AngleRPY);
            var matrixA  = new Matrix3DMath.Matrix3D();

            foreach (var model in Models)
            {
                model.GLDraw();
            }

            foreach (var attachment in Attachments)
            {
                GL.PushMatrix();
                Matrix3DMath.MatrixInvert(attachment.AngleOffsetMatrix, matrixA);
                Matrix3DMath.MatrixToRPY(matrixA, ref angleRpy);
                GL.Translate(attachment.PosOffset.X, attachment.PosOffset.Y, Convert.ToDouble(-attachment.PosOffset.Z));
                GL.Rotate((float)(angleRpy.Roll / MathUtil.RadOf1Deg), 0.0F, 0.0F, -1.0F);
                GL.Rotate((float)(angleRpy.Pitch / MathUtil.RadOf1Deg), 1.0F, 0.0F, 0.0F);
                GL.Rotate((float)(angleRpy.Yaw / MathUtil.RadOf1Deg), 0.0F, 1.0F, 0.0F);
                attachment.GLDraw();
                GL.PopMatrix();
            }
        }
Esempio n. 2
0
        private void OpenGL_KeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            clsMap Map = MainMap;

            if ( Map == null )
            {
                return;
            }

            Matrix3DMath.Matrix3D matrixA = new Matrix3DMath.Matrix3D();
            clsViewInfo.clsMouseOver.clsOverTerrain MouseOverTerrain = Map.ViewInfo.GetMouseOverTerrain();

            App.IsViewKeyDown.Keys[(int)e.KeyCode] = true;

            foreach ( Option<KeyboardControl> control in KeyboardManager.OptionsKeyboardControls.Options )
            {
                ((KeyboardControl)(KeyboardManager.KeyboardProfile.get_Value(control))).KeysChanged(App.IsViewKeyDown);
            }

            if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.Undo) )
            {
                string Message = "";
                if ( Map.UndoPosition > 0 )
                {
                    Message = "Undid: " + Map.Undos[Map.UndoPosition - 1].Name;
                    clsMap.clsMessage MapMessage = new clsMap.clsMessage();
                    MapMessage.Text = Message;
                    Map.Messages.Add(MapMessage);
                    Map.UndoPerform();
                    DrawViewLater();
                }
                else
                {
                    Message = "Nothing to undo";
                }
                DisplayUndoMessage(Message);
            }
            if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.Redo) )
            {
                string Message = "";
                if ( Map.UndoPosition < Map.Undos.Count )
                {
                    Message = "Redid: " + Map.Undos[Map.UndoPosition].Name;
                    clsMap.clsMessage MapMessage = new clsMap.clsMessage();
                    MapMessage.Text = Message;
                    Map.Messages.Add(MapMessage);
                    Map.RedoPerform();
                    DrawViewLater();
                }
                else
                {
                    Message = "Nothing to redo";
                }
                DisplayUndoMessage(Message);
            }
            if ( App.IsViewKeyDown.Keys[(int)Keys.ControlKey] )
            {
                if ( e.KeyCode == Keys.D1 )
                {
                    App.VisionRadius_2E = 6;
                }
                else if ( e.KeyCode == Keys.D2 )
                {
                    App.VisionRadius_2E = 7;
                }
                else if ( e.KeyCode == Keys.D3 )
                {
                    App.VisionRadius_2E = 8;
                }
                else if ( e.KeyCode == Keys.D4 )
                {
                    App.VisionRadius_2E = 9;
                }
                else if ( e.KeyCode == Keys.D5 )
                {
                    App.VisionRadius_2E = 10;
                }
                else if ( e.KeyCode == Keys.D6 )
                {
                    App.VisionRadius_2E = 11;
                }
                else if ( e.KeyCode == Keys.D7 )
                {
                    App.VisionRadius_2E = 12;
                }
                else if ( e.KeyCode == Keys.D8 )
                {
                    App.VisionRadius_2E = 13;
                }
                else if ( e.KeyCode == Keys.D9 )
                {
                    App.VisionRadius_2E = 14;
                }
                else if ( e.KeyCode == Keys.D0 )
                {
                    App.VisionRadius_2E = 15;
                }
                App.VisionRadius_2E_Changed();
            }

            if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewMoveType) )
            {
                if ( App.ViewMoveType == App.enumView_Move_Type.Free )
                {
                    App.ViewMoveType = App.enumView_Move_Type.RTS;
                }
                else if ( App.ViewMoveType == App.enumView_Move_Type.RTS )
                {
                    App.ViewMoveType = App.enumView_Move_Type.Free;
                }
            }
            if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewRotateType) )
            {
                App.RTSOrbit = !App.RTSOrbit;
            }
            if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewReset) )
            {
                Map.ViewInfo.FOV_Multiplier_Set(SettingsManager.Settings.FOVDefault);
                if ( App.ViewMoveType == App.enumView_Move_Type.Free )
                {
                    Matrix3DMath.MatrixSetToXAngle(matrixA, Math.Atan(2.0D));
                    Map.ViewInfo.ViewAngleSet_Rotate(matrixA);
                }
                else if ( App.ViewMoveType == App.enumView_Move_Type.RTS )
                {
                    Matrix3DMath.MatrixSetToXAngle(matrixA, Math.Atan(2.0D));
                    Map.ViewInfo.ViewAngleSet_Rotate(matrixA);
                }
            }
            if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewTextures) )
            {
                App.Draw_TileTextures = !App.Draw_TileTextures;
                DrawViewLater();
            }
            if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewWireframe) )
            {
                App.Draw_TileWireframe = !App.Draw_TileWireframe;
                DrawViewLater();
            }
            if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewUnits) )
            {
                App.Draw_Units = !App.Draw_Units;
                int X = 0;
                int Y = 0;
                sXY_int SectorNum = new sXY_int();
                clsMap.clsUnit Unit = default(clsMap.clsUnit);
                clsMap.clsUnitSectorConnection Connection = default(clsMap.clsUnitSectorConnection);
                for ( Y = 0; Y <= Map.SectorCount.Y - 1; Y++ )
                {
                    for ( X = 0; X <= Map.SectorCount.X - 1; X++ )
                    {
                        foreach ( clsMap.clsUnitSectorConnection tempLoopVar_Connection in Map.Sectors[X, Y].Units )
                        {
                            Connection = tempLoopVar_Connection;
                            Unit = Connection.Unit;
                            if ( Unit.Type.Type == clsUnitType.enumType.PlayerStructure )
                            {
                                if ( ((clsStructureType)Unit.Type).StructureBasePlate != null )
                                {
                                    SectorNum.X = X;
                                    SectorNum.Y = Y;
                                    Map.SectorGraphicsChanges.Changed(SectorNum);
                                    break;
                                }
                            }
                        }
                    }
                }
                Map.Update();
                DrawViewLater();
            }
            if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewScriptMarkers) )
            {
                App.Draw_ScriptMarkers = !App.Draw_ScriptMarkers;
                DrawViewLater();
            }
            if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewLighting) )
            {
                if ( App.Draw_Lighting == App.enumDrawLighting.Off )
                {
                    App.Draw_Lighting = App.enumDrawLighting.Half;
                }
                else if ( App.Draw_Lighting == App.enumDrawLighting.Half )
                {
                    App.Draw_Lighting = App.enumDrawLighting.Normal;
                }
                else if ( App.Draw_Lighting == App.enumDrawLighting.Normal )
                {
                    App.Draw_Lighting = App.enumDrawLighting.Off;
                }
                DrawViewLater();
            }
            if ( modTools.Tool == modTools.Tools.TextureBrush )
            {
                if ( MouseOverTerrain != null )
                {
                    if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.Clockwise) )
                    {
                        Map.ViewInfo.Apply_Texture_Clockwise();
                    }
                    if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.CounterClockwise) )
                    {
                        Map.ViewInfo.Apply_Texture_CounterClockwise();
                    }
                    if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.TextureFlip) )
                    {
                        Map.ViewInfo.Apply_Texture_FlipX();
                    }
                    if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.TriFlip) )
                    {
                        Map.ViewInfo.Apply_Tri_Flip();
                    }
                }
            }
            if ( modTools.Tool == modTools.Tools.ObjectSelect )
            {
                if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.UnitDelete) )
                {
                    if ( Map.SelectedUnits.Count > 0 )
                    {
                        clsMap.clsUnit Unit = default(clsMap.clsUnit);
                        foreach ( clsMap.clsUnit tempLoopVar_Unit in Map.SelectedUnits.GetItemsAsSimpleList() )
                        {
                            Unit = tempLoopVar_Unit;
                            Map.UnitRemoveStoreChange(Unit.MapLink.ArrayPosition);
                        }
                        Program.frmMainInstance.SelectedObject_Changed();
                        Map.UndoStepCreate("Object Deleted");
                        Map.Update();
                        Map.MinimapMakeLater();
                        DrawViewLater();
                    }
                }
                if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.UnitMove) )
                {
                    if ( MouseOverTerrain != null )
                    {
                        if ( Map.SelectedUnits.Count > 0 )
                        {
                            Position.XY_dbl Centre = App.CalcUnitsCentrePos(Map.SelectedUnits.GetItemsAsSimpleList());
                            sXY_int Offset = new sXY_int();
                            Offset.X = ((int)(Math.Round(Convert.ToDouble((MouseOverTerrain.Pos.Horizontal.X - Centre.X) / App.TerrainGridSpacing)))) *
                                       App.TerrainGridSpacing;
                            Offset.Y = ((int)(Math.Round(Convert.ToDouble((MouseOverTerrain.Pos.Horizontal.Y - Centre.Y) / App.TerrainGridSpacing)))) *
                                       App.TerrainGridSpacing;
                            clsMap.clsObjectPosOffset ObjectPosOffset = new clsMap.clsObjectPosOffset();
                            ObjectPosOffset.Map = Map;
                            ObjectPosOffset.Offset = Offset;
                            Map.SelectedUnitsAction(ObjectPosOffset);

                            Map.UndoStepCreate("Objects Moved");
                            Map.Update();
                            Map.MinimapMakeLater();
                            Program.frmMainInstance.SelectedObject_Changed();
                            DrawViewLater();
                        }
                    }
                }
                if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.Clockwise) )
                {
                    clsMap.clsObjectRotationOffset ObjectRotationOffset = new clsMap.clsObjectRotationOffset();
                    ObjectRotationOffset.Map = Map;
                    ObjectRotationOffset.Offset = -90;
                    Map.SelectedUnitsAction(ObjectRotationOffset);
                    Map.Update();
                    Program.frmMainInstance.SelectedObject_Changed();
                    Map.UndoStepCreate("Object Rotated");
                    DrawViewLater();
                }
                if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.CounterClockwise) )
                {
                    clsMap.clsObjectRotationOffset ObjectRotationOffset = new clsMap.clsObjectRotationOffset();
                    ObjectRotationOffset.Map = Map;
                    ObjectRotationOffset.Offset = 90;
                    Map.SelectedUnitsAction(ObjectRotationOffset);
                    Map.Update();
                    Program.frmMainInstance.SelectedObject_Changed();
                    Map.UndoStepCreate("Object Rotated");
                    DrawViewLater();
                }
            }

            if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.Deselect) )
            {
                modTools.Tool = modTools.Tools.ObjectSelect;
                DrawViewLater();
            }

            if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.PreviousTool) )
            {
                modTools.Tool = modTools.PreviousTool;
                DrawViewLater();
            }
        }
Esempio n. 3
0
 public void LookAtPos(modMath.sXY_int Horizontal)
 {
     Position.XYZ_dbl _dbl;
     modMath.sXYZ_int _int;
     Matrix3DMath.Matrix3D matrix = new Matrix3DMath.Matrix3D();
     Matrix3DMath.VectorForwardsRotationByMatrix(this.ViewAngleMatrix, ref _dbl);
     double terrainHeight = this.Map.GetTerrainHeight(Horizontal);
     int num = ((int) Math.Round(Math.Ceiling(terrainHeight))) + 0x80;
     if (this.ViewPos.Y < num)
     {
         this.ViewPos.Y = num;
     }
     if (_dbl.Y > -0.33333333333333331)
     {
         Angles.AnglePY epy;
         _dbl.Y = -0.33333333333333331;
         Matrix3DMath.VectorToPY(_dbl, ref epy);
         Matrix3DMath.MatrixSetToPY(matrix, epy);
         this.ViewAngleSet(matrix);
     }
     terrainHeight = (this.ViewPos.Y - terrainHeight) / _dbl.Y;
     _int.X = (int) Math.Round((double) (Horizontal.X + (terrainHeight * _dbl.X)));
     _int.Y = this.ViewPos.Y;
     _int.Z = (int) Math.Round((double) ((0 - Horizontal.Y) + (terrainHeight * _dbl.Z)));
     this.ViewPosSet(_int);
 }
Esempio n. 4
0
 public void ViewAngleSetToDefault()
 {
     Matrix3DMath.Matrix3D matrix = new Matrix3DMath.Matrix3D();
     Matrix3DMath.MatrixSetToXAngle(matrix, Math.Atan(2.0));
     this.ViewAngleSet(matrix);
     this.MapView.DrawViewLater();
 }
Esempio n. 5
0
 public void TimedActions(double Zoom, double Move, double Pan, double Roll, double OrbitRate)
 {
     Angles.AnglePY epy;
     modMath.sXYZ_int _int;
     Position.XYZ_dbl _dbl2;
     double scale = Pan * this.FieldOfViewY;
     Matrix3DMath.Matrix3D matrix = new Matrix3DMath.Matrix3D();
     Matrix3DMath.Matrix3D resultMatrix = new Matrix3DMath.Matrix3D();
     Move *= (this.FOVMultiplier * (this.MapView.GLSize.X + this.MapView.GLSize.Y)) * Math.Max((double) Math.Abs(this.ViewPos.Y), 512.0);
     if (modControls.KeyboardProfile.Active(modControls.Control_View_Zoom_In))
     {
         this.FOV_Scale_2E_Change(-Zoom);
     }
     if (modControls.KeyboardProfile.Active(modControls.Control_View_Zoom_Out))
     {
         this.FOV_Scale_2E_Change(Zoom);
     }
     if (modProgram.ViewMoveType == modProgram.enumView_Move_Type.Free)
     {
         Position.XYZ_dbl _dbl;
         _int.X = 0;
         _int.Y = 0;
         _int.Z = 0;
         if (modControls.KeyboardProfile.Active(modControls.Control_View_Move_Forward))
         {
             Matrix3DMath.VectorForwardsRotationByMatrix(this.ViewAngleMatrix, Move, ref _dbl2);
             _int.Add_dbl(_dbl2);
         }
         if (modControls.KeyboardProfile.Active(modControls.Control_View_Move_Backward))
         {
             Matrix3DMath.VectorBackwardsRotationByMatrix(this.ViewAngleMatrix, Move, ref _dbl2);
             _int.Add_dbl(_dbl2);
         }
         if (modControls.KeyboardProfile.Active(modControls.Control_View_Move_Left))
         {
             Matrix3DMath.VectorLeftRotationByMatrix(this.ViewAngleMatrix, Move, ref _dbl2);
             _int.Add_dbl(_dbl2);
         }
         if (modControls.KeyboardProfile.Active(modControls.Control_View_Move_Right))
         {
             Matrix3DMath.VectorRightRotationByMatrix(this.ViewAngleMatrix, Move, ref _dbl2);
             _int.Add_dbl(_dbl2);
         }
         if (modControls.KeyboardProfile.Active(modControls.Control_View_Move_Up))
         {
             Matrix3DMath.VectorUpRotationByMatrix(this.ViewAngleMatrix, Move, ref _dbl2);
             _int.Add_dbl(_dbl2);
         }
         if (modControls.KeyboardProfile.Active(modControls.Control_View_Move_Down))
         {
             Matrix3DMath.VectorDownRotationByMatrix(this.ViewAngleMatrix, Move, ref _dbl2);
             _int.Add_dbl(_dbl2);
         }
         _dbl.X = 0.0;
         _dbl.Y = 0.0;
         _dbl.Z = 0.0;
         if (modControls.KeyboardProfile.Active(modControls.Control_View_Left))
         {
             Matrix3DMath.VectorForwardsRotationByMatrix(this.ViewAngleMatrix, Roll, ref _dbl2);
             _dbl += _dbl2;
         }
         if (modControls.KeyboardProfile.Active(modControls.Control_View_Right))
         {
             Matrix3DMath.VectorBackwardsRotationByMatrix(this.ViewAngleMatrix, Roll, ref _dbl2);
             _dbl += _dbl2;
         }
         if (modControls.KeyboardProfile.Active(modControls.Control_View_Backward))
         {
             Matrix3DMath.VectorLeftRotationByMatrix(this.ViewAngleMatrix, scale, ref _dbl2);
             _dbl += _dbl2;
         }
         if (modControls.KeyboardProfile.Active(modControls.Control_View_Forward))
         {
             Matrix3DMath.VectorRightRotationByMatrix(this.ViewAngleMatrix, scale, ref _dbl2);
             _dbl += _dbl2;
         }
         if (modControls.KeyboardProfile.Active(modControls.Control_View_Roll_Left))
         {
             Matrix3DMath.VectorDownRotationByMatrix(this.ViewAngleMatrix, scale, ref _dbl2);
             _dbl += _dbl2;
         }
         if (modControls.KeyboardProfile.Active(modControls.Control_View_Roll_Right))
         {
             Matrix3DMath.VectorUpRotationByMatrix(this.ViewAngleMatrix, scale, ref _dbl2);
             _dbl += _dbl2;
         }
         if (((_int.X != 0.0) | (_int.Y != 0.0)) | (_int.Z != 0.0))
         {
             this.ViewPosChange(_int);
         }
         if ((!(_dbl.X == 0.0) | !(_dbl.Y == 0.0)) | !(_dbl.Z == 0.0))
         {
             Matrix3DMath.VectorToPY(_dbl, ref epy);
             Matrix3DMath.MatrixSetToPY(matrix, epy);
             Matrix3DMath.MatrixRotationAroundAxis(this.ViewAngleMatrix, matrix, _dbl.GetMagnitude(), resultMatrix);
             this.ViewAngleSet_Rotate(resultMatrix);
         }
     }
     else if (modProgram.ViewMoveType == modProgram.enumView_Move_Type.RTS)
     {
         _int = new modMath.sXYZ_int();
         Matrix3DMath.MatrixToPY(this.ViewAngleMatrix, ref epy);
         Matrix3DMath.MatrixSetToYAngle(matrix, epy.Yaw);
         if (modControls.KeyboardProfile.Active(modControls.Control_View_Move_Forward))
         {
             Matrix3DMath.VectorForwardsRotationByMatrix(matrix, Move, ref _dbl2);
             _int.Add_dbl(_dbl2);
         }
         if (modControls.KeyboardProfile.Active(modControls.Control_View_Move_Backward))
         {
             Matrix3DMath.VectorBackwardsRotationByMatrix(matrix, Move, ref _dbl2);
             _int.Add_dbl(_dbl2);
         }
         if (modControls.KeyboardProfile.Active(modControls.Control_View_Move_Left))
         {
             Matrix3DMath.VectorLeftRotationByMatrix(matrix, Move, ref _dbl2);
             _int.Add_dbl(_dbl2);
         }
         if (modControls.KeyboardProfile.Active(modControls.Control_View_Move_Right))
         {
             Matrix3DMath.VectorRightRotationByMatrix(matrix, Move, ref _dbl2);
             _int.Add_dbl(_dbl2);
         }
         if (modControls.KeyboardProfile.Active(modControls.Control_View_Move_Up))
         {
             _int.Y += (int) Math.Round(Move);
         }
         if (modControls.KeyboardProfile.Active(modControls.Control_View_Move_Down))
         {
             _int.Y -= (int) Math.Round(Move);
         }
         bool flag = false;
         if (modProgram.RTSOrbit)
         {
             if (modControls.KeyboardProfile.Active(modControls.Control_View_Forward))
             {
                 epy.Pitch = modMath.Clamp_dbl(epy.Pitch + OrbitRate, -1.5702509114036483, 1.5702509114036483);
                 flag = true;
             }
             if (modControls.KeyboardProfile.Active(modControls.Control_View_Backward))
             {
                 epy.Pitch = modMath.Clamp_dbl(epy.Pitch - OrbitRate, -1.5702509114036483, 1.5702509114036483);
                 flag = true;
             }
             if (modControls.KeyboardProfile.Active(modControls.Control_View_Left))
             {
                 epy.Yaw = modMath.AngleClamp(epy.Yaw + OrbitRate);
                 flag = true;
             }
             if (modControls.KeyboardProfile.Active(modControls.Control_View_Right))
             {
                 epy.Yaw = modMath.AngleClamp(epy.Yaw - OrbitRate);
                 flag = true;
             }
         }
         else
         {
             if (modControls.KeyboardProfile.Active(modControls.Control_View_Forward))
             {
                 epy.Pitch = modMath.Clamp_dbl(epy.Pitch - OrbitRate, -1.5702509114036483, 1.5702509114036483);
                 flag = true;
             }
             if (modControls.KeyboardProfile.Active(modControls.Control_View_Backward))
             {
                 epy.Pitch = modMath.Clamp_dbl(epy.Pitch + OrbitRate, -1.5702509114036483, 1.5702509114036483);
                 flag = true;
             }
             if (modControls.KeyboardProfile.Active(modControls.Control_View_Left))
             {
                 epy.Yaw = modMath.AngleClamp(epy.Yaw - OrbitRate);
                 flag = true;
             }
             if (modControls.KeyboardProfile.Active(modControls.Control_View_Right))
             {
                 epy.Yaw = modMath.AngleClamp(epy.Yaw + OrbitRate);
                 flag = true;
             }
         }
         if (((_int.X != 0.0) | (_int.Y != 0.0)) | (_int.Z != 0.0))
         {
             this.ViewPosChange(_int);
         }
         if (flag)
         {
             Matrix3DMath.MatrixSetToPY(matrix, epy);
             this.ViewAngleSet_Rotate(matrix);
         }
     }
 }
Esempio n. 6
0
 public void GLDraw()
 {
     IEnumerator enumerator;
     IEnumerator enumerator2;
     Matrix3DMath.Matrix3D matrixOut = new Matrix3DMath.Matrix3D();
     try
     {
         enumerator = this.Models.GetEnumerator();
         while (enumerator.MoveNext())
         {
             ((clsModel) enumerator.Current).GLDraw();
         }
     }
     finally
     {
         if (enumerator is IDisposable)
         {
             (enumerator as IDisposable).Dispose();
         }
     }
     try
     {
         enumerator2 = this.Attachments.GetEnumerator();
         while (enumerator2.MoveNext())
         {
             Angles.AngleRPY erpy;
             clsUnitType.clsAttachment current = (clsUnitType.clsAttachment) enumerator2.Current;
             GL.PushMatrix();
             Matrix3DMath.MatrixInvert(current.AngleOffsetMatrix, matrixOut);
             Matrix3DMath.MatrixToRPY(matrixOut, ref erpy);
             GL.Translate(current.Pos_Offset.X, current.Pos_Offset.Y, -current.Pos_Offset.Z);
             GL.Rotate((double) (erpy.Roll / 0.017453292519943295), (double) 0.0, (double) 0.0, (double) -1.0);
             GL.Rotate((double) (erpy.Pitch / 0.017453292519943295), (double) 1.0, (double) 0.0, (double) 0.0);
             GL.Rotate((double) (erpy.Yaw / 0.017453292519943295), (double) 0.0, (double) 1.0, (double) 0.0);
             current.GLDraw();
             GL.PopMatrix();
         }
     }
     finally
     {
         if (enumerator2 is IDisposable)
         {
             (enumerator2 as IDisposable).Dispose();
         }
     }
 }
Esempio n. 7
0
        public void GLDraw()
        {
            Position.XYZ_dbl XYZ_dbl = default(Position.XYZ_dbl);
            sXY_int Footprint;
            int X = 0;
            int Y = 0;
            int X2 = 0;
            int Y2 = 0;
            int A = 0;
            int B = 0;
            int C = 0;
            int D = 0;
            sRGBA_sng ColourA = new sRGBA_sng();
            sRGBA_sng ColourB = new sRGBA_sng();
            bool ShowMinimapViewPosBox = default(bool);
            Position.XY_dbl ViewCorner0 = default(Position.XY_dbl);
            Position.XY_dbl ViewCorner1 = default(Position.XY_dbl);
            Position.XY_dbl ViewCorner2 = default(Position.XY_dbl);
            Position.XY_dbl ViewCorner3 = default(Position.XY_dbl);
            double dblTemp = 0;
            Position.XYZ_dbl Vertex0 = default(Position.XYZ_dbl);
            Position.XYZ_dbl Vertex1 = default(Position.XYZ_dbl);
            Position.XYZ_dbl Vertex2 = default(Position.XYZ_dbl);
            Position.XYZ_dbl Vertex3 = default(Position.XYZ_dbl);
            sXY_int ScreenPos = new sXY_int();
            Position.XYZ_dbl XYZ_dbl2 = default(Position.XYZ_dbl);
            App.sWorldPos WorldPos = new App.sWorldPos();
            Position.XY_dbl PosA = default(Position.XY_dbl);
            Position.XY_dbl PosB = default(Position.XY_dbl);
            Position.XY_dbl PosC = default(Position.XY_dbl);
            Position.XY_dbl PosD = default(Position.XY_dbl);
            sXY_int MinimapSizeXY = new sXY_int();
            clsUnit Unit = default(clsUnit);
            sXY_int StartXY = new sXY_int();
            sXY_int FinishXY = new sXY_int();
            bool DrawIt = default(bool);
            clsBrush.sPosNum DrawCentreSector = new clsBrush.sPosNum();
            clsTextLabel SelectionLabel = new clsTextLabel();
            float[] light_position = new float[4];
            Matrix3DMath.Matrix3D matrixA = new Matrix3DMath.Matrix3D();
            Matrix3DMath.Matrix3D matrixB = new Matrix3DMath.Matrix3D();
            clsAction MapAction = default(clsAction);
            float ZNearFar = 0;
            MapViewControl MapViewControl = ViewInfo.MapViewControl;
            sXY_int GLSize = ViewInfo.MapViewControl.GLSize;
            Position.XY_dbl DrawCentre = default(Position.XY_dbl);
            double dblTemp2 = 0;

            dblTemp = SettingsManager.Settings.MinimapSize;
            ViewInfo.Tiles_Per_Minimap_Pixel = Math.Sqrt(Terrain.TileSize.X * Terrain.TileSize.X + Terrain.TileSize.Y * Terrain.TileSize.Y) /
                                               (MathUtil.RootTwo * dblTemp);
            if ( Minimap_Texture_Size > 0 & ViewInfo.Tiles_Per_Minimap_Pixel > 0.0D )
            {
                MinimapSizeXY.X = (int)(Terrain.TileSize.X / ViewInfo.Tiles_Per_Minimap_Pixel);
                MinimapSizeXY.Y = (int)(Terrain.TileSize.Y / ViewInfo.Tiles_Per_Minimap_Pixel);
            }

            if ( !ViewInfo.ScreenXY_Get_ViewPlanePos(new sXY_int((int)(GLSize.X / 2.0D), (int)(GLSize.Y / 2.0D)), dblTemp, DrawCentre) )
            {
                Matrix3DMath.VectorForwardsRotationByMatrix(ViewInfo.ViewAngleMatrix, ref XYZ_dbl);
                dblTemp2 = App.VisionRadius * 2.0D / Math.Sqrt(XYZ_dbl.X * XYZ_dbl.X + XYZ_dbl.Z * XYZ_dbl.Z);
                DrawCentre.X = ViewInfo.ViewPos.X + XYZ_dbl.X * dblTemp2;
                DrawCentre.Y = ViewInfo.ViewPos.Z + XYZ_dbl.Z * dblTemp2;
            }
            DrawCentre.X = MathUtil.Clamp_dbl(DrawCentre.X, 0.0D, Terrain.TileSize.X * App.TerrainGridSpacing - 1.0D);
            DrawCentre.Y = MathUtil.Clamp_dbl(Convert.ToDouble(- DrawCentre.Y), 0.0D, Terrain.TileSize.Y * App.TerrainGridSpacing - 1.0D);
            DrawCentreSector.Normal = GetPosSectorNum(new sXY_int((int)DrawCentre.X, (int)DrawCentre.Y));
            DrawCentreSector.Alignment =
                GetPosSectorNum(new sXY_int((int)(DrawCentre.X - Constants.SectorTileSize * App.TerrainGridSpacing / 2.0D),
                    (int)(DrawCentre.Y - Constants.SectorTileSize * App.TerrainGridSpacing / 2.0D)));

            clsDrawSectorObjects DrawObjects = new clsDrawSectorObjects();
            DrawObjects.Map = this;
            DrawObjects.UnitTextLabels = new clsTextLabels(64);
            DrawObjects.Start();

            XYZ_dbl.X = DrawCentre.X - ViewInfo.ViewPos.X;
            XYZ_dbl.Y = 128 - ViewInfo.ViewPos.Y;
            XYZ_dbl.Z = - DrawCentre.Y - ViewInfo.ViewPos.Z;
            ZNearFar = (float)(XYZ_dbl.GetMagnitude());

            GL.Enable(EnableCap.DepthTest);
            GL.MatrixMode(MatrixMode.Projection);
            Matrix4 temp_mat = Matrix4.CreatePerspectiveFieldOfView(ViewInfo.FieldOfViewY, MapViewControl.GLSize_XPerY, ZNearFar / 128.0F, ZNearFar * 128.0F);
            GL.LoadMatrix(ref temp_mat);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();

            Matrix3DMath.MatrixRotationByMatrix(ViewInfo.ViewAngleMatrix_Inverted, App.SunAngleMatrix, matrixB);
            Matrix3DMath.VectorForwardsRotationByMatrix(matrixB, ref XYZ_dbl);
            light_position[0] = (float)XYZ_dbl.X;
            light_position[1] = (float)XYZ_dbl.Y;
            light_position[2] = Convert.ToSingle(- XYZ_dbl.Z);
            light_position[3] = 0.0F;
            GL.Light(LightName.Light0, LightParameter.Position, light_position);
            GL.Light(LightName.Light1, LightParameter.Position, light_position);

            GL.Disable(EnableCap.Light0);
            GL.Disable(EnableCap.Light1);
            if ( App.Draw_Lighting != App.enumDrawLighting.Off )
            {
                if ( App.Draw_Lighting == App.enumDrawLighting.Half )
                {
                    GL.Enable(EnableCap.Light0);
                }
                else if ( App.Draw_Lighting == App.enumDrawLighting.Normal )
                {
                    GL.Enable(EnableCap.Light1);
                }
                GL.Enable(EnableCap.Lighting);
            }
            else
            {
                GL.Disable(EnableCap.Lighting);
            }

            dblTemp = 127.5D * HeightMultiplier;
            if ( ViewInfo.ScreenXY_Get_ViewPlanePos_ForwardDownOnly(0, 0, dblTemp, ViewCorner0)
                 && ViewInfo.ScreenXY_Get_ViewPlanePos_ForwardDownOnly(GLSize.X, 0, dblTemp, ViewCorner1)
                 && ViewInfo.ScreenXY_Get_ViewPlanePos_ForwardDownOnly(GLSize.X, GLSize.Y, dblTemp, ViewCorner2)
                 && ViewInfo.ScreenXY_Get_ViewPlanePos_ForwardDownOnly(0, GLSize.Y, dblTemp, ViewCorner3) )
            {
                ShowMinimapViewPosBox = true;
            }
            else
            {
                ShowMinimapViewPosBox = false;
            }

            GL.Rotate((float)(ViewInfo.ViewAngleRPY.Roll / MathUtil.RadOf1Deg), 0.0F, 0.0F, -1.0F);
            GL.Rotate((float)(ViewInfo.ViewAngleRPY.Pitch / MathUtil.RadOf1Deg), 1.0F, 0.0F, 0.0F);
            GL.Rotate((float)(ViewInfo.ViewAngleRPY.Yaw / MathUtil.RadOf1Deg), 0.0F, 1.0F, 0.0F);
            GL.Translate(Convert.ToDouble(- ViewInfo.ViewPos.X), Convert.ToDouble(- ViewInfo.ViewPos.Y), ViewInfo.ViewPos.Z);

            GL.Enable(EnableCap.CullFace);

            DebugGLError("Matrix modes");

            if ( App.Draw_TileTextures )
            {
                GL.Color3(1.0F, 1.0F, 1.0F);
                GL.Enable(EnableCap.Texture2D);
                MapAction = new clsDrawCallTerrain();
                MapAction.Map = this;
                App.VisionSectors.PerformActionMapSectors(MapAction, DrawCentreSector);
                GL.Disable(EnableCap.Texture2D);

                DebugGLError("Tile textures");
            }

            GL.Disable(EnableCap.DepthTest);
            GL.Disable(EnableCap.Lighting);

            if ( App.Draw_TileWireframe )
            {
                GL.Color3(0.0F, 1.0F, 0.0F);
                GL.LineWidth(1.0F);
                clsDrawCallTerrainWireframe DrawCallTerrainWireframe = new clsDrawCallTerrainWireframe();
                DrawCallTerrainWireframe.Map = this;
                App.VisionSectors.PerformActionMapSectors(DrawCallTerrainWireframe, DrawCentreSector);

                DebugGLError("Wireframe");
            }

            //draw tile orientation markers

            if ( App.DisplayTileOrientation )
            {
                GL.Disable(EnableCap.CullFace);

                GL.Begin(BeginMode.Triangles);
                GL.Color3(1.0F, 1.0F, 0.0F);
                MapAction = new clsDrawTileOrientation();
                MapAction.Map = this;
                App.VisionSectors.PerformActionMapSectors(MapAction, DrawCentreSector);
                GL.End();

                GL.Enable(EnableCap.CullFace);

                DebugGLError("Tile orientation");
            }

            //draw painted texture terrain type markers

            sRGB_sng RGB_sng = new sRGB_sng();

            clsViewInfo.clsMouseOver.clsOverTerrain MouseOverTerrain = ViewInfo.GetMouseOverTerrain();

            if ( App.Draw_VertexTerrain )
            {
                GL.LineWidth(1.0F);
                clsDrawVertexTerrain DrawVertexTerran = new clsDrawVertexTerrain();
                DrawVertexTerran.Map = this;
                DrawVertexTerran.ViewAngleMatrix = ViewInfo.ViewAngleMatrix;
                App.VisionSectors.PerformActionMapSectors(DrawVertexTerran, DrawCentreSector);
                DebugGLError("Terrain type markers");
            }

            SelectionLabel.Text = "";

            if ( Selected_Area_VertexA != null )
            {
                DrawIt = false;
                if ( Selected_Area_VertexB != null )
                {
                    //area is selected
                    MathUtil.ReorderXY(Selected_Area_VertexA.XY, Selected_Area_VertexB.XY, StartXY, FinishXY);
                    XYZ_dbl.X = Selected_Area_VertexB.X * App.TerrainGridSpacing - ViewInfo.ViewPos.X;
                    XYZ_dbl.Z = - Selected_Area_VertexB.Y * App.TerrainGridSpacing - ViewInfo.ViewPos.Z;
                    XYZ_dbl.Y = GetVertexAltitude(Selected_Area_VertexB.XY) - ViewInfo.ViewPos.Y;
                    DrawIt = true;
                }
                else if ( modTools.Tool == modTools.Tools.TerrainSelect )
                {
                    if ( MouseOverTerrain != null )
                    {
                        //selection is changing under pointer
                        MathUtil.ReorderXY(Selected_Area_VertexA.XY, MouseOverTerrain.Vertex.Normal, StartXY, FinishXY);
                        XYZ_dbl.X = MouseOverTerrain.Vertex.Normal.X * App.TerrainGridSpacing - ViewInfo.ViewPos.X;
                        XYZ_dbl.Z = - MouseOverTerrain.Vertex.Normal.Y * App.TerrainGridSpacing - ViewInfo.ViewPos.Z;
                        XYZ_dbl.Y = GetVertexAltitude(MouseOverTerrain.Vertex.Normal) - ViewInfo.ViewPos.Y;
                        DrawIt = true;
                    }
                }
                if ( DrawIt )
                {
                    Matrix3DMath.VectorRotationByMatrix(ViewInfo.ViewAngleMatrix_Inverted, XYZ_dbl, ref XYZ_dbl2);
                    if ( ViewInfo.Pos_Get_Screen_XY(XYZ_dbl2, ScreenPos) )
                    {
                        if ( ScreenPos.X >= 0 & ScreenPos.X <= GLSize.X & ScreenPos.Y >= 0 & ScreenPos.Y <= GLSize.Y )
                        {
                            SelectionLabel.Colour.Red = 1.0F;
                            SelectionLabel.Colour.Green = 1.0F;
                            SelectionLabel.Colour.Blue = 1.0F;
                            SelectionLabel.Colour.Alpha = 1.0F;
                            SelectionLabel.TextFont = App.UnitLabelFont;
                            SelectionLabel.SizeY = SettingsManager.Settings.FontSize;
                            SelectionLabel.Pos = ScreenPos;
                            SelectionLabel.Text = FinishXY.X - StartXY.X + "x" + Convert.ToString(FinishXY.Y - StartXY.Y);
                        }
                    }
                    GL.LineWidth(3.0F);
                    clsDrawTileAreaOutline DrawSelection = new clsDrawTileAreaOutline();
                    DrawSelection.Map = this;
                    DrawSelection.StartXY = StartXY;
                    DrawSelection.FinishXY = FinishXY;
                    DrawSelection.Colour = new sRGBA_sng(1.0F, 1.0F, 1.0F, 1.0F);
                    DrawSelection.ActionPerform();
                }

                DebugGLError("Terrain selection box");
            }

            if ( modTools.Tool == modTools.Tools.TerrainSelect )
            {
                if ( MouseOverTerrain != null )
                {
                    //draw mouseover vertex
                    GL.LineWidth(3.0F);

                    Vertex0.X = MouseOverTerrain.Vertex.Normal.X * App.TerrainGridSpacing;
                    Vertex0.Y = Convert.ToDouble(Terrain.Vertices[MouseOverTerrain.Vertex.Normal.X, MouseOverTerrain.Vertex.Normal.Y].Height * HeightMultiplier);
                    Vertex0.Z = - MouseOverTerrain.Vertex.Normal.Y * App.TerrainGridSpacing;
                    GL.Begin(BeginMode.Lines);
                    GL.Color3(1.0F, 1.0F, 1.0F);
                    GL.Vertex3(Vertex0.X - 8.0D, Vertex0.Y, Convert.ToDouble(- Vertex0.Z));
                    GL.Vertex3(Vertex0.X + 8.0D, Vertex0.Y, Convert.ToDouble(- Vertex0.Z));
                    GL.Vertex3(Vertex0.X, Vertex0.Y, - Vertex0.Z - 8.0D);
                    GL.Vertex3(Vertex0.X, Vertex0.Y, - Vertex0.Z + 8.0D);
                    GL.End();
                }
                DebugGLError("Terrain selection vertex");
            }

            clsGateway Gateway = default(clsGateway);

            if ( App.Draw_Gateways )
            {
                GL.LineWidth(2.0F);
                foreach ( clsGateway tempLoopVar_Gateway in Gateways )
                {
                    Gateway = tempLoopVar_Gateway;
                    if ( Gateway.PosA.X == Gateway.PosB.X )
                    {
                        if ( Gateway.PosA.Y <= Gateway.PosB.Y )
                        {
                            C = Gateway.PosA.Y;
                            D = Gateway.PosB.Y;
                        }
                        else
                        {
                            C = Gateway.PosB.Y;
                            D = Gateway.PosA.Y;
                        }
                        X2 = Gateway.PosA.X;
                        for ( Y2 = C; Y2 <= D; Y2++ )
                        {
                            Vertex0.X = X2 * App.TerrainGridSpacing;
                            Vertex0.Y = Convert.ToDouble(Terrain.Vertices[X2, Y2].Height * HeightMultiplier);
                            Vertex0.Z = - Y2 * App.TerrainGridSpacing;
                            Vertex1.X = (X2 + 1) * App.TerrainGridSpacing;
                            Vertex1.Y = Convert.ToDouble(Terrain.Vertices[X2 + 1, Y2].Height * HeightMultiplier);
                            Vertex1.Z = - Y2 * App.TerrainGridSpacing;
                            Vertex2.X = X2 * App.TerrainGridSpacing;
                            Vertex2.Y = Convert.ToDouble(Terrain.Vertices[X2, Y2 + 1].Height * HeightMultiplier);
                            Vertex2.Z = - (Y2 + 1) * App.TerrainGridSpacing;
                            Vertex3.X = (X2 + 1) * App.TerrainGridSpacing;
                            Vertex3.Y = Convert.ToDouble(Terrain.Vertices[X2 + 1, Y2 + 1].Height * HeightMultiplier);
                            Vertex3.Z = - (Y2 + 1) * App.TerrainGridSpacing;
                            GL.Begin(BeginMode.LineLoop);
                            GL.Color3(0.75F, 1.0F, 0.0F);
                            GL.Vertex3(Vertex0.X, Vertex0.Y, Convert.ToDouble(- Vertex0.Z));
                            GL.Vertex3(Vertex1.X, Vertex1.Y, Convert.ToDouble(- Vertex1.Z));
                            GL.Vertex3(Vertex3.X, Vertex3.Y, Convert.ToDouble(- Vertex3.Z));
                            GL.Vertex3(Vertex2.X, Vertex2.Y, Convert.ToDouble(- Vertex2.Z));
                            GL.End();
                        }
                    }
                    else if ( Gateway.PosA.Y == Gateway.PosB.Y )
                    {
                        if ( Gateway.PosA.X <= Gateway.PosB.X )
                        {
                            C = Gateway.PosA.X;
                            D = Gateway.PosB.X;
                        }
                        else
                        {
                            C = Gateway.PosB.X;
                            D = Gateway.PosA.X;
                        }
                        Y2 = Gateway.PosA.Y;
                        for ( X2 = C; X2 <= D; X2++ )
                        {
                            Vertex0.X = X2 * App.TerrainGridSpacing;
                            Vertex0.Y = Convert.ToDouble(Terrain.Vertices[X2, Y2].Height * HeightMultiplier);
                            Vertex0.Z = - Y2 * App.TerrainGridSpacing;
                            Vertex1.X = (X2 + 1) * App.TerrainGridSpacing;
                            Vertex1.Y = Convert.ToDouble(Terrain.Vertices[X2 + 1, Y2].Height * HeightMultiplier);
                            Vertex1.Z = - Y2 * App.TerrainGridSpacing;
                            Vertex2.X = X2 * App.TerrainGridSpacing;
                            Vertex2.Y = Convert.ToDouble(Terrain.Vertices[X2, Y2 + 1].Height * HeightMultiplier);
                            Vertex2.Z = - (Y2 + 1) * App.TerrainGridSpacing;
                            Vertex3.X = (X2 + 1) * App.TerrainGridSpacing;
                            Vertex3.Y = Convert.ToDouble(Terrain.Vertices[X2 + 1, Y2 + 1].Height * HeightMultiplier);
                            Vertex3.Z = - (Y2 + 1) * App.TerrainGridSpacing;
                            GL.Begin(BeginMode.LineLoop);
                            GL.Color3(0.75F, 1.0F, 0.0F);
                            GL.Vertex3(Vertex0.X, Vertex0.Y, Convert.ToDouble(- Vertex0.Z));
                            GL.Vertex3(Vertex1.X, Vertex1.Y, Convert.ToDouble(- Vertex1.Z));
                            GL.Vertex3(Vertex3.X, Vertex3.Y, Convert.ToDouble(- Vertex3.Z));
                            GL.Vertex3(Vertex2.X, Vertex2.Y, Convert.ToDouble(- Vertex2.Z));
                            GL.End();
                        }
                    }
                    else
                    {
                        //draw invalid gateways as red tile borders
                        X2 = Gateway.PosA.X;
                        Y2 = Gateway.PosA.Y;

                        Vertex0.X = X2 * App.TerrainGridSpacing;
                        Vertex0.Y = Convert.ToDouble(Terrain.Vertices[X2, Y2].Height * HeightMultiplier);
                        Vertex0.Z = - Y2 * App.TerrainGridSpacing;
                        Vertex1.X = (X2 + 1) * App.TerrainGridSpacing;
                        Vertex1.Y = Convert.ToDouble(Terrain.Vertices[X2 + 1, Y2].Height * HeightMultiplier);
                        Vertex1.Z = - Y2 * App.TerrainGridSpacing;
                        Vertex2.X = X2 * App.TerrainGridSpacing;
                        Vertex2.Y = Convert.ToDouble(Terrain.Vertices[X2, Y2 + 1].Height * HeightMultiplier);
                        Vertex2.Z = - (Y2 + 1) * App.TerrainGridSpacing;
                        Vertex3.X = (X2 + 1) * App.TerrainGridSpacing;
                        Vertex3.Y = Convert.ToDouble(Terrain.Vertices[X2 + 1, Y2 + 1].Height * HeightMultiplier);
                        Vertex3.Z = - (Y2 + 1) * App.TerrainGridSpacing;
                        GL.Begin(BeginMode.LineLoop);
                        GL.Color3(1.0F, 0.0F, 0.0F);
                        GL.Vertex3(Vertex0.X, Vertex0.Y, Convert.ToDouble(- Vertex0.Z));
                        GL.Vertex3(Vertex1.X, Vertex1.Y, Convert.ToDouble(- Vertex1.Z));
                        GL.Vertex3(Vertex3.X, Vertex3.Y, Convert.ToDouble(- Vertex3.Z));
                        GL.Vertex3(Vertex2.X, Vertex2.Y, Convert.ToDouble(- Vertex2.Z));
                        GL.End();

                        X2 = Gateway.PosB.X;
                        Y2 = Gateway.PosB.Y;

                        Vertex0.X = X2 * App.TerrainGridSpacing;
                        Vertex0.Y = Convert.ToDouble(Terrain.Vertices[X2, Y2].Height * HeightMultiplier);
                        Vertex0.Z = - Y2 * App.TerrainGridSpacing;
                        Vertex1.X = (X2 + 1) * App.TerrainGridSpacing;
                        Vertex1.Y = Convert.ToDouble(Terrain.Vertices[X2 + 1, Y2].Height * HeightMultiplier);
                        Vertex1.Z = - Y2 * App.TerrainGridSpacing;
                        Vertex2.X = X2 * App.TerrainGridSpacing;
                        Vertex2.Y = Convert.ToDouble(Terrain.Vertices[X2, Y2 + 1].Height * HeightMultiplier);
                        Vertex2.Z = - (Y2 + 1) * App.TerrainGridSpacing;
                        Vertex3.X = (X2 + 1) * App.TerrainGridSpacing;
                        Vertex3.Y = Convert.ToDouble(Terrain.Vertices[X2 + 1, Y2 + 1].Height * HeightMultiplier);
                        Vertex3.Z = - (Y2 + 1) * App.TerrainGridSpacing;
                        GL.Begin(BeginMode.LineLoop);
                        GL.Color3(1.0F, 0.0F, 0.0F);
                        GL.Vertex3(Vertex0.X, Vertex0.Y, Convert.ToDouble(- Vertex0.Z));
                        GL.Vertex3(Vertex1.X, Vertex1.Y, Convert.ToDouble(- Vertex1.Z));
                        GL.Vertex3(Vertex3.X, Vertex3.Y, Convert.ToDouble(- Vertex3.Z));
                        GL.Vertex3(Vertex2.X, Vertex2.Y, Convert.ToDouble(- Vertex2.Z));
                        GL.End();
                    }
                }
                DebugGLError("Gateways");
            }

            if ( MouseOverTerrain != null )
            {
                if ( modTools.Tool == modTools.Tools.ObjectSelect )
                {
                    if ( Unit_Selected_Area_VertexA != null )
                    {
                        //selection is changing under pointer
                        MathUtil.ReorderXY(Unit_Selected_Area_VertexA.XY, MouseOverTerrain.Vertex.Normal, StartXY, FinishXY);
                        GL.LineWidth(2.0F);
                        GL.Color3(0.0F, 1.0F, 1.0F);
                        for ( X = StartXY.X; X <= FinishXY.X - 1; X++ )
                        {
                            Vertex0.X = X * App.TerrainGridSpacing;
                            Vertex0.Y = Convert.ToDouble(Terrain.Vertices[X, StartXY.Y].Height * HeightMultiplier);
                            Vertex0.Z = - StartXY.Y * App.TerrainGridSpacing;
                            Vertex1.X = (X + 1) * App.TerrainGridSpacing;
                            Vertex1.Y = Convert.ToDouble(Terrain.Vertices[X + 1, StartXY.Y].Height * HeightMultiplier);
                            Vertex1.Z = - StartXY.Y * App.TerrainGridSpacing;
                            GL.Begin(BeginMode.Lines);
                            GL.Vertex3(Vertex0.X, Vertex0.Y, Convert.ToDouble(- Vertex0.Z));
                            GL.Vertex3(Vertex1.X, Vertex1.Y, Convert.ToDouble(- Vertex1.Z));
                            GL.End();
                        }
                        for ( X = StartXY.X; X <= FinishXY.X - 1; X++ )
                        {
                            Vertex0.X = X * App.TerrainGridSpacing;
                            Vertex0.Y = Convert.ToDouble(Terrain.Vertices[X, FinishXY.Y].Height * HeightMultiplier);
                            Vertex0.Z = - FinishXY.Y * App.TerrainGridSpacing;
                            Vertex1.X = (X + 1) * App.TerrainGridSpacing;
                            Vertex1.Y = Convert.ToDouble(Terrain.Vertices[X + 1, FinishXY.Y].Height * HeightMultiplier);
                            Vertex1.Z = - FinishXY.Y * App.TerrainGridSpacing;
                            GL.Begin(BeginMode.Lines);
                            GL.Vertex3(Vertex0.X, Vertex0.Y, Convert.ToDouble(- Vertex0.Z));
                            GL.Vertex3(Vertex1.X, Vertex1.Y, Convert.ToDouble(- Vertex1.Z));
                            GL.End();
                        }
                        for ( Y = StartXY.Y; Y <= FinishXY.Y - 1; Y++ )
                        {
                            Vertex0.X = StartXY.X * App.TerrainGridSpacing;
                            Vertex0.Y = Convert.ToDouble(Terrain.Vertices[StartXY.X, Y].Height * HeightMultiplier);
                            Vertex0.Z = - Y * App.TerrainGridSpacing;
                            Vertex1.X = StartXY.X * App.TerrainGridSpacing;
                            Vertex1.Y = Convert.ToDouble(Terrain.Vertices[StartXY.X, Y + 1].Height * HeightMultiplier);
                            Vertex1.Z = - (Y + 1) * App.TerrainGridSpacing;
                            GL.Begin(BeginMode.Lines);
                            GL.Vertex3(Vertex0.X, Vertex0.Y, Convert.ToDouble(- Vertex0.Z));
                            GL.Vertex3(Vertex1.X, Vertex1.Y, Convert.ToDouble(- Vertex1.Z));
                            GL.End();
                        }
                        for ( Y = StartXY.Y; Y <= FinishXY.Y - 1; Y++ )
                        {
                            Vertex0.X = FinishXY.X * App.TerrainGridSpacing;
                            Vertex0.Y = Convert.ToDouble(Terrain.Vertices[FinishXY.X, Y].Height * HeightMultiplier);
                            Vertex0.Z = - Y * App.TerrainGridSpacing;
                            Vertex1.X = FinishXY.X * App.TerrainGridSpacing;
                            Vertex1.Y = Convert.ToDouble(Terrain.Vertices[FinishXY.X, Y + 1].Height * HeightMultiplier);
                            Vertex1.Z = - (Y + 1) * App.TerrainGridSpacing;
                            GL.Begin(BeginMode.Lines);
                            GL.Vertex3(Vertex0.X, Vertex0.Y, Convert.ToDouble(- Vertex0.Z));
                            GL.Vertex3(Vertex1.X, Vertex1.Y, Convert.ToDouble(- Vertex1.Z));
                            GL.End();
                        }

                        DebugGLError("Object selection box");
                    }
                    else
                    {
                        GL.LineWidth(2.0F);
                        GL.Color3(0.0F, 1.0F, 1.0F);
                        GL.Begin(BeginMode.Lines);
                        GL.Vertex3(MouseOverTerrain.Pos.Horizontal.X - 16.0D, MouseOverTerrain.Pos.Altitude, MouseOverTerrain.Pos.Horizontal.Y - 16.0D);
                        GL.Vertex3(MouseOverTerrain.Pos.Horizontal.X + 16.0D, MouseOverTerrain.Pos.Altitude, MouseOverTerrain.Pos.Horizontal.Y + 16.0D);
                        GL.Vertex3(MouseOverTerrain.Pos.Horizontal.X + 16.0D, MouseOverTerrain.Pos.Altitude, MouseOverTerrain.Pos.Horizontal.Y - 16.0D);
                        GL.Vertex3(MouseOverTerrain.Pos.Horizontal.X - 16.0D, MouseOverTerrain.Pos.Altitude, MouseOverTerrain.Pos.Horizontal.Y + 16.0D);
                        GL.End();

                        DebugGLError("Mouse over position");
                    }
                }

                if ( modTools.Tool == modTools.Tools.RoadPlace )
                {
                    GL.LineWidth(2.0F);

                    if ( MouseOverTerrain.Side_IsV )
                    {
                        Vertex0.X = MouseOverTerrain.Side_Num.X * App.TerrainGridSpacing;
                        Vertex0.Y = Convert.ToDouble(Terrain.Vertices[MouseOverTerrain.Side_Num.X, MouseOverTerrain.Side_Num.Y].Height * HeightMultiplier);
                        Vertex0.Z = - MouseOverTerrain.Side_Num.Y * App.TerrainGridSpacing;
                        Vertex1.X = MouseOverTerrain.Side_Num.X * App.TerrainGridSpacing;
                        Vertex1.Y = Convert.ToDouble(Terrain.Vertices[MouseOverTerrain.Side_Num.X, MouseOverTerrain.Side_Num.Y + 1].Height * HeightMultiplier);
                        Vertex1.Z = - (MouseOverTerrain.Side_Num.Y + 1) * App.TerrainGridSpacing;
                    }
                    else
                    {
                        Vertex0.X = MouseOverTerrain.Side_Num.X * App.TerrainGridSpacing;
                        Vertex0.Y = Convert.ToDouble(Terrain.Vertices[MouseOverTerrain.Side_Num.X, MouseOverTerrain.Side_Num.Y].Height * HeightMultiplier);
                        Vertex0.Z = - MouseOverTerrain.Side_Num.Y * App.TerrainGridSpacing;
                        Vertex1.X = (MouseOverTerrain.Side_Num.X + 1) * App.TerrainGridSpacing;
                        Vertex1.Y = Convert.ToDouble(Terrain.Vertices[MouseOverTerrain.Side_Num.X + 1, MouseOverTerrain.Side_Num.Y].Height * HeightMultiplier);
                        Vertex1.Z = - MouseOverTerrain.Side_Num.Y * App.TerrainGridSpacing;
                    }

                    GL.Begin(BeginMode.Lines);
                    GL.Color3(0.0F, 1.0F, 1.0F);
                    GL.Vertex3(Vertex0.X, Vertex0.Y, Convert.ToDouble(- Vertex0.Z));
                    GL.Vertex3(Vertex1.X, Vertex1.Y, Convert.ToDouble(- Vertex1.Z));
                    GL.End();

                    DebugGLError("Road place brush");
                }
                else if ( modTools.Tool == modTools.Tools.RoadLines || modTools.Tool == modTools.Tools.Gateways || modTools.Tool == modTools.Tools.ObjectLines )
                {
                    GL.LineWidth(2.0F);

                    if ( Selected_Tile_A != null )
                    {
                        X2 = Selected_Tile_A.X;
                        Y2 = Selected_Tile_A.Y;

                        Vertex0.X = X2 * App.TerrainGridSpacing;
                        Vertex0.Y = Convert.ToDouble(Terrain.Vertices[X2, Y2].Height * HeightMultiplier);
                        Vertex0.Z = - Y2 * App.TerrainGridSpacing;
                        Vertex1.X = (X2 + 1) * App.TerrainGridSpacing;
                        Vertex1.Y = Convert.ToDouble(Terrain.Vertices[X2 + 1, Y2].Height * HeightMultiplier);
                        Vertex1.Z = - Y2 * App.TerrainGridSpacing;
                        Vertex2.X = X2 * App.TerrainGridSpacing;
                        Vertex2.Y = Convert.ToDouble(Terrain.Vertices[X2, Y2 + 1].Height * HeightMultiplier);
                        Vertex2.Z = - (Y2 + 1) * App.TerrainGridSpacing;
                        Vertex3.X = (X2 + 1) * App.TerrainGridSpacing;
                        Vertex3.Y = Convert.ToDouble(Terrain.Vertices[X2 + 1, Y2 + 1].Height * HeightMultiplier);
                        Vertex3.Z = - (Y2 + 1) * App.TerrainGridSpacing;
                        GL.Begin(BeginMode.LineLoop);
                        GL.Color3(0.0F, 1.0F, 1.0F);
                        GL.Vertex3(Vertex0.X, Vertex0.Y, Convert.ToDouble(- Vertex0.Z));
                        GL.Vertex3(Vertex1.X, Vertex1.Y, Convert.ToDouble(- Vertex1.Z));
                        GL.Vertex3(Vertex3.X, Vertex3.Y, Convert.ToDouble(- Vertex3.Z));
                        GL.Vertex3(Vertex2.X, Vertex2.Y, Convert.ToDouble(- Vertex2.Z));
                        GL.End();

                        if ( MouseOverTerrain.Tile.Normal.X == Selected_Tile_A.X )
                        {
                            if ( MouseOverTerrain.Tile.Normal.Y <= Selected_Tile_A.Y )
                            {
                                A = MouseOverTerrain.Tile.Normal.Y;
                                B = Selected_Tile_A.Y;
                            }
                            else
                            {
                                A = Selected_Tile_A.Y;
                                B = MouseOverTerrain.Tile.Normal.Y;
                            }
                            X2 = Selected_Tile_A.X;
                            for ( Y2 = A; Y2 <= B; Y2++ )
                            {
                                Vertex0.X = X2 * App.TerrainGridSpacing;
                                Vertex0.Y = Convert.ToDouble(Terrain.Vertices[X2, Y2].Height * HeightMultiplier);
                                Vertex0.Z = - Y2 * App.TerrainGridSpacing;
                                Vertex1.X = (X2 + 1) * App.TerrainGridSpacing;
                                Vertex1.Y = Convert.ToDouble(Terrain.Vertices[X2 + 1, Y2].Height * HeightMultiplier);
                                Vertex1.Z = - Y2 * App.TerrainGridSpacing;
                                Vertex2.X = X2 * App.TerrainGridSpacing;
                                Vertex2.Y = Convert.ToDouble(Terrain.Vertices[X2, Y2 + 1].Height * HeightMultiplier);
                                Vertex2.Z = - (Y2 + 1) * App.TerrainGridSpacing;
                                Vertex3.X = (X2 + 1) * App.TerrainGridSpacing;
                                Vertex3.Y = Convert.ToDouble(Terrain.Vertices[X2 + 1, Y2 + 1].Height * HeightMultiplier);
                                Vertex3.Z = - (Y2 + 1) * App.TerrainGridSpacing;
                                GL.Begin(BeginMode.LineLoop);
                                GL.Color3(0.0F, 1.0F, 1.0F);
                                GL.Vertex3(Vertex0.X, Vertex0.Y, Convert.ToDouble(- Vertex0.Z));
                                GL.Vertex3(Vertex1.X, Vertex1.Y, Convert.ToDouble(- Vertex1.Z));
                                GL.Vertex3(Vertex3.X, Vertex3.Y, Convert.ToDouble(- Vertex3.Z));
                                GL.Vertex3(Vertex2.X, Vertex2.Y, Convert.ToDouble(- Vertex2.Z));
                                GL.End();
                            }
                        }
                        else if ( MouseOverTerrain.Tile.Normal.Y == Selected_Tile_A.Y )
                        {
                            if ( MouseOverTerrain.Tile.Normal.X <= Selected_Tile_A.X )
                            {
                                A = MouseOverTerrain.Tile.Normal.X;
                                B = Selected_Tile_A.X;
                            }
                            else
                            {
                                A = Selected_Tile_A.X;
                                B = MouseOverTerrain.Tile.Normal.X;
                            }
                            Y2 = Selected_Tile_A.Y;
                            for ( X2 = A; X2 <= B; X2++ )
                            {
                                Vertex0.X = X2 * App.TerrainGridSpacing;
                                Vertex0.Y = Convert.ToDouble(Terrain.Vertices[X2, Y2].Height * HeightMultiplier);
                                Vertex0.Z = - Y2 * App.TerrainGridSpacing;
                                Vertex1.X = (X2 + 1) * App.TerrainGridSpacing;
                                Vertex1.Y = Convert.ToDouble(Terrain.Vertices[X2 + 1, Y2].Height * HeightMultiplier);
                                Vertex1.Z = - Y2 * App.TerrainGridSpacing;
                                Vertex2.X = X2 * App.TerrainGridSpacing;
                                Vertex2.Y = Convert.ToDouble(Terrain.Vertices[X2, Y2 + 1].Height * HeightMultiplier);
                                Vertex2.Z = - (Y2 + 1) * App.TerrainGridSpacing;
                                Vertex3.X = (X2 + 1) * App.TerrainGridSpacing;
                                Vertex3.Y = Convert.ToDouble(Terrain.Vertices[X2 + 1, Y2 + 1].Height * HeightMultiplier);
                                Vertex3.Z = - (Y2 + 1) * App.TerrainGridSpacing;
                                GL.Begin(BeginMode.LineLoop);
                                GL.Color3(0.0F, 1.0F, 1.0F);
                                GL.Vertex3(Vertex0.X, Vertex0.Y, Convert.ToDouble(- Vertex0.Z));
                                GL.Vertex3(Vertex1.X, Vertex1.Y, Convert.ToDouble(- Vertex1.Z));
                                GL.Vertex3(Vertex3.X, Vertex3.Y, Convert.ToDouble(- Vertex3.Z));
                                GL.Vertex3(Vertex2.X, Vertex2.Y, Convert.ToDouble(- Vertex2.Z));
                                GL.End();
                            }
                        }
                    }
                    else
                    {
                        X2 = MouseOverTerrain.Tile.Normal.X;
                        Y2 = MouseOverTerrain.Tile.Normal.Y;

                        Vertex0.X = X2 * App.TerrainGridSpacing;
                        Vertex0.Y = Convert.ToDouble(Terrain.Vertices[X2, Y2].Height * HeightMultiplier);
                        Vertex0.Z = - Y2 * App.TerrainGridSpacing;
                        Vertex1.X = (X2 + 1) * App.TerrainGridSpacing;
                        Vertex1.Y = Convert.ToDouble(Terrain.Vertices[X2 + 1, Y2].Height * HeightMultiplier);
                        Vertex1.Z = - Y2 * App.TerrainGridSpacing;
                        Vertex2.X = X2 * App.TerrainGridSpacing;
                        Vertex2.Y = Convert.ToDouble(Terrain.Vertices[X2, Y2 + 1].Height * HeightMultiplier);
                        Vertex2.Z = - (Y2 + 1) * App.TerrainGridSpacing;
                        Vertex3.X = (X2 + 1) * App.TerrainGridSpacing;
                        Vertex3.Y = Convert.ToDouble(Terrain.Vertices[X2 + 1, Y2 + 1].Height * HeightMultiplier);
                        Vertex3.Z = - (Y2 + 1) * App.TerrainGridSpacing;
                        GL.Begin(BeginMode.LineLoop);
                        GL.Color3(0.0F, 1.0F, 1.0F);
                        GL.Vertex3(Vertex0.X, Vertex0.Y, Convert.ToDouble(- Vertex0.Z));
                        GL.Vertex3(Vertex1.X, Vertex1.Y, Convert.ToDouble(- Vertex1.Z));
                        GL.Vertex3(Vertex3.X, Vertex3.Y, Convert.ToDouble(- Vertex3.Z));
                        GL.Vertex3(Vertex2.X, Vertex2.Y, Convert.ToDouble(- Vertex2.Z));
                        GL.End();
                    }
                    DebugGLError("Line brush");
                }

                //draw mouseover tiles

                clsBrush ToolBrush = default(clsBrush);

                if ( modTools.Tool == modTools.Tools.TextureBrush )
                {
                    ToolBrush = App.TextureBrush;
                }
                else if ( modTools.Tool == modTools.Tools.CliffBrush )
                {
                    ToolBrush = App.CliffBrush;
                }
                else if ( modTools.Tool == modTools.Tools.CliffRemove )
                {
                    ToolBrush = App.CliffBrush;
                }
                else if ( modTools.Tool == modTools.Tools.RoadRemove )
                {
                    ToolBrush = App.CliffBrush;
                }
                else
                {
                    ToolBrush = null;
                }

                if ( ToolBrush != null )
                {
                    GL.LineWidth(2.0F);
                    clsDrawTileOutline DrawTileOutline = new clsDrawTileOutline();
                    DrawTileOutline.Map = this;
                    DrawTileOutline.Colour.Red = 0.0F;
                    DrawTileOutline.Colour.Green = 1.0F;
                    DrawTileOutline.Colour.Blue = 1.0F;
                    DrawTileOutline.Colour.Alpha = 1.0F;
                    ToolBrush.PerformActionMapTiles(DrawTileOutline, MouseOverTerrain.Tile);

                    DebugGLError("Brush tiles");
                }

                //draw mouseover vertex
                if ( modTools.Tool == modTools.Tools.TerrainFill )
                {
                    GL.LineWidth(2.0F);

                    Vertex0.X = MouseOverTerrain.Vertex.Normal.X * App.TerrainGridSpacing;
                    Vertex0.Y = Convert.ToDouble(Terrain.Vertices[MouseOverTerrain.Vertex.Normal.X, MouseOverTerrain.Vertex.Normal.Y].Height * HeightMultiplier);
                    Vertex0.Z = - MouseOverTerrain.Vertex.Normal.Y * App.TerrainGridSpacing;
                    GL.Begin(BeginMode.Lines);
                    GL.Color3(0.0F, 1.0F, 1.0F);
                    GL.Vertex3(Vertex0.X - 8.0D, Vertex0.Y, Convert.ToDouble(- Vertex0.Z));
                    GL.Vertex3(Vertex0.X + 8.0D, Vertex0.Y, Convert.ToDouble(- Vertex0.Z));
                    GL.Vertex3(Vertex0.X, Vertex0.Y, Convert.ToDouble(- Vertex0.Z - 8.0D));
                    GL.Vertex3(Vertex0.X, Vertex0.Y, - Vertex0.Z + 8.0D);
                    GL.End();

                    DebugGLError("Mouse over vertex");
                }

                if ( modTools.Tool == modTools.Tools.TerrainBrush )
                {
                    ToolBrush = App.TerrainBrush;
                }
                else if ( modTools.Tool == modTools.Tools.HeightSetBrush )
                {
                    ToolBrush = App.HeightBrush;
                }
                else if ( modTools.Tool == modTools.Tools.HeightChangeBrush )
                {
                    ToolBrush = App.HeightBrush;
                }
                else if ( modTools.Tool == modTools.Tools.HeightSmoothBrush )
                {
                    ToolBrush = App.HeightBrush;
                }
                else
                {
                    ToolBrush = null;
                }

                if ( ToolBrush != null )
                {
                    GL.LineWidth(2.0F);
                    clsDrawVertexMarker DrawVertexMarker = new clsDrawVertexMarker();
                    DrawVertexMarker.Map = this;
                    DrawVertexMarker.Colour.Red = 0.0F;
                    DrawVertexMarker.Colour.Green = 1.0F;
                    DrawVertexMarker.Colour.Blue = 1.0F;
                    DrawVertexMarker.Colour.Alpha = 1.0F;
                    ToolBrush.PerformActionMapVertices(DrawVertexMarker, MouseOverTerrain.Vertex);

                    DebugGLError("Brush vertices");
                }
            }

            GL.Enable(EnableCap.DepthTest);

            GL.Disable(EnableCap.CullFace);

            GL.LoadIdentity();
            GL.Rotate((float)(ViewInfo.ViewAngleRPY.Roll / MathUtil.RadOf1Deg), 0.0F, 0.0F, -1.0F);
            GL.Rotate((float)(ViewInfo.ViewAngleRPY.Pitch / MathUtil.RadOf1Deg), 1.0F, 0.0F, 0.0F);
            GL.Rotate((float)(ViewInfo.ViewAngleRPY.Yaw / MathUtil.RadOf1Deg), 0.0F, 1.0F, 0.0F);

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            DebugGLError("Object matrix modes");

            if ( App.Draw_Units )
            {
                GL.Color3(1.0F, 1.0F, 1.0F);
                GL.Enable(EnableCap.Texture2D);
                App.VisionSectors.PerformActionMapSectors(DrawObjects, DrawCentreSector);
                GL.Disable(EnableCap.Texture2D);
                DebugGLError("Objects");
            }

            if ( MouseOverTerrain != null )
            {
                GL.Enable(EnableCap.Texture2D);
                if ( modTools.Tool == modTools.Tools.ObjectPlace )
                {
                    clsUnitType placeObject = Program.frmMainInstance.SingleSelectedObjectType;
                    if ( placeObject != null )
                    {
                        int Rotation = 0;
                        try
                        {
                            IOUtil.InvariantParse(Program.frmMainInstance.txtNewObjectRotation.Text, ref Rotation);
                            if ( Rotation < 0 | Rotation > 359 )
                            {
                                Rotation = 0;
                            }
                        }
                        catch
                        {
                            Rotation = 0;
                        }
                        WorldPos = TileAlignedPosFromMapPos(MouseOverTerrain.Pos.Horizontal, placeObject.get_GetFootprintSelected(Rotation));
                        GL.PushMatrix();
                        GL.Translate(WorldPos.Horizontal.X - ViewInfo.ViewPos.X, WorldPos.Altitude - ViewInfo.ViewPos.Y + 2.0D,
                            ViewInfo.ViewPos.Z + WorldPos.Horizontal.Y);
                        placeObject.GLDraw(Rotation);
                        GL.PopMatrix();
                    }
                }
                GL.Disable(EnableCap.Texture2D);
                DebugGLError("Mouse over object");
            }

            GL.Disable(EnableCap.DepthTest);

            clsTextLabels ScriptMarkerTextLabels = new clsTextLabels(256);
            clsTextLabel TextLabel = default(clsTextLabel);
            if ( App.Draw_ScriptMarkers )
            {
                clsScriptPosition ScriptPosition = default(clsScriptPosition);
                clsScriptArea ScriptArea = default(clsScriptArea);
                GL.PushMatrix();
                GL.Translate(Convert.ToDouble(- ViewInfo.ViewPos.X), Convert.ToDouble(- ViewInfo.ViewPos.Y), ViewInfo.ViewPos.Z);
                foreach ( clsScriptPosition tempLoopVar_ScriptPosition in ScriptPositions )
                {
                    ScriptPosition = tempLoopVar_ScriptPosition;
                    ScriptPosition.GLDraw();
                }
                foreach ( clsScriptArea tempLoopVar_ScriptArea in ScriptAreas )
                {
                    ScriptArea = tempLoopVar_ScriptArea;
                    ScriptArea.GLDraw();
                }
                foreach ( clsScriptPosition tempLoopVar_ScriptPosition in ScriptPositions )
                {
                    ScriptPosition = tempLoopVar_ScriptPosition;
                    if ( ScriptMarkerTextLabels.AtMaxCount() )
                    {
                        break;
                    }
                    XYZ_dbl.X = ScriptPosition.PosX - ViewInfo.ViewPos.X;
                    XYZ_dbl.Z = - ScriptPosition.PosY - ViewInfo.ViewPos.Z;
                    XYZ_dbl.Y = GetTerrainHeight(new sXY_int(ScriptPosition.PosX, ScriptPosition.PosY)) - ViewInfo.ViewPos.Y;
                    Matrix3DMath.VectorRotationByMatrix(ViewInfo.ViewAngleMatrix_Inverted, XYZ_dbl, ref XYZ_dbl2);
                    if ( ViewInfo.Pos_Get_Screen_XY(XYZ_dbl2, ScreenPos) )
                    {
                        if ( ScreenPos.X >= 0 & ScreenPos.X <= GLSize.X & ScreenPos.Y >= 0 & ScreenPos.Y <= GLSize.Y )
                        {
                            TextLabel = new clsTextLabel();
                            TextLabel.Colour.Red = 1.0F;
                            TextLabel.Colour.Green = 1.0F;
                            TextLabel.Colour.Blue = 0.5F;
                            TextLabel.Colour.Alpha = 0.75F;
                            TextLabel.TextFont = App.UnitLabelFont;
                            TextLabel.SizeY = SettingsManager.Settings.FontSize;
                            TextLabel.Pos = ScreenPos;
                            TextLabel.Text = ScriptPosition.Label;
                            ScriptMarkerTextLabels.Add(TextLabel);
                        }
                    }
                }
                DebugGLError("Script positions");
                foreach ( clsScriptArea tempLoopVar_ScriptArea in ScriptAreas )
                {
                    ScriptArea = tempLoopVar_ScriptArea;
                    if ( ScriptMarkerTextLabels.AtMaxCount() )
                    {
                        break;
                    }
                    XYZ_dbl.X = ScriptArea.PosAX - ViewInfo.ViewPos.X;
                    XYZ_dbl.Z = - ScriptArea.PosAY - ViewInfo.ViewPos.Z;
                    XYZ_dbl.Y = GetTerrainHeight(new sXY_int(ScriptArea.PosAX, ScriptArea.PosAY)) - ViewInfo.ViewPos.Y;
                    Matrix3DMath.VectorRotationByMatrix(ViewInfo.ViewAngleMatrix_Inverted, XYZ_dbl, ref XYZ_dbl2);
                    if ( ViewInfo.Pos_Get_Screen_XY(XYZ_dbl2, ScreenPos) )
                    {
                        if ( ScreenPos.X >= 0 & ScreenPos.X <= GLSize.X & ScreenPos.Y >= 0 & ScreenPos.Y <= GLSize.Y )
                        {
                            TextLabel = new clsTextLabel();
                            TextLabel.Colour.Red = 1.0F;
                            TextLabel.Colour.Green = 1.0F;
                            TextLabel.Colour.Blue = 0.5F;
                            TextLabel.Colour.Alpha = 0.75F;
                            TextLabel.TextFont = App.UnitLabelFont;
                            TextLabel.SizeY = SettingsManager.Settings.FontSize;
                            TextLabel.Pos = ScreenPos;
                            TextLabel.Text = ScriptArea.Label;
                            ScriptMarkerTextLabels.Add(TextLabel);
                        }
                    }
                }
                GL.PopMatrix();

                DebugGLError("Script areas");
            }

            clsTextLabels MessageTextLabels = new clsTextLabels(24);

            B = 0;
            for ( A = Math.Max(Messages.Count - MessageTextLabels.MaxCount, 0); A <= Messages.Count - 1; A++ )
            {
                if ( !MessageTextLabels.AtMaxCount() )
                {
                    TextLabel = new clsTextLabel();
                    TextLabel.Colour.Red = 0.875F;
                    TextLabel.Colour.Green = 0.875F;
                    TextLabel.Colour.Blue = 1.0F;
                    TextLabel.Colour.Alpha = 1.0F;
                    TextLabel.TextFont = App.UnitLabelFont;
                    TextLabel.SizeY = SettingsManager.Settings.FontSize;
                    TextLabel.Pos.X = 32 + MinimapSizeXY.X;
                    TextLabel.Pos.Y = 32 + (int)(Math.Ceiling((decimal)(B * TextLabel.SizeY)));
                    TextLabel.Text = Convert.ToString(Messages[A].Text);
                    MessageTextLabels.Add(TextLabel);
                    B++;
                }
            }

            //draw unit selection

            GL.Begin(BeginMode.Quads);
            foreach ( clsUnit tempLoopVar_Unit in SelectedUnits )
            {
                Unit = tempLoopVar_Unit;
                Footprint = Unit.Type.get_GetFootprintSelected(Unit.Rotation);
                RGB_sng = GetUnitGroupColour(Unit.UnitGroup);
                ColourA = new sRGBA_sng((1.0F + RGB_sng.Red) / 2.0F, (1.0F + RGB_sng.Green) / 2.0F, (1.0F + RGB_sng.Blue) / 2.0F, 0.75F);
                ColourB = new sRGBA_sng(RGB_sng.Red, RGB_sng.Green, RGB_sng.Blue, 0.75F);
                DrawUnitRectangle(Unit, 8, ColourA, ColourB);
            }
            if ( MouseOverTerrain != null )
            {
                foreach ( clsUnit tempLoopVar_Unit in MouseOverTerrain.Units )
                {
                    Unit = tempLoopVar_Unit;
                    if ( Unit != null && modTools.Tool == modTools.Tools.ObjectSelect )
                    {
                        RGB_sng = GetUnitGroupColour(Unit.UnitGroup);
                        GL.Color4((0.5F + RGB_sng.Red) / 1.5F, (0.5F + RGB_sng.Green) / 1.5F, (0.5F + RGB_sng.Blue) / 1.5F, 0.75F);
                        Footprint = Unit.Type.get_GetFootprintSelected(Unit.Rotation);
                        ColourA = new sRGBA_sng((1.0F + RGB_sng.Red) / 2.0F, (1.0F + RGB_sng.Green) / 2.0F, (1.0F + RGB_sng.Blue) / 2.0F, 0.75F);
                        ColourB = new sRGBA_sng(RGB_sng.Red, RGB_sng.Green, RGB_sng.Blue, 0.875F);
                        DrawUnitRectangle(Unit, 16, ColourA, ColourB);
                    }
                }
            }
            GL.End();

            DebugGLError("Unit selection");

            GL.MatrixMode(MatrixMode.Projection);
            Matrix4 temp_mat2 = Matrix4.CreateOrthographicOffCenter(0.0F, GLSize.X, GLSize.Y, 0.0F, -1.0F, 1.0F);
            GL.LoadMatrix(ref temp_mat2);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();

            DebugGLError("Text label matrix modes");

            GL.Enable(EnableCap.Texture2D);

            ScriptMarkerTextLabels.Draw();
            DrawObjects.UnitTextLabels.Draw();
            SelectionLabel.Draw();
            MessageTextLabels.Draw();

            DebugGLError("Text labels");

            GL.Disable(EnableCap.Texture2D);

            GL.Disable(EnableCap.Blend);

            //draw minimap

            GL.MatrixMode(MatrixMode.Projection);
            Matrix4 temp_mat3 = Matrix4.CreateOrthographicOffCenter(0.0F, GLSize.X, 0.0F, GLSize.Y, -1.0F, 1.0F);
            GL.LoadMatrix(ref temp_mat3);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();

            DebugGLError("Minimap matrix modes");

            if ( Minimap_Texture_Size > 0 & ViewInfo.Tiles_Per_Minimap_Pixel > 0.0D )
            {
                GL.Translate(0.0F, GLSize.Y - MinimapSizeXY.Y, 0.0F);

                XYZ_dbl.X = Terrain.TileSize.X / Minimap_Texture_Size;
                XYZ_dbl.Z = Terrain.TileSize.Y / Minimap_Texture_Size;

                if ( Minimap_GLTexture > 0 )
                {
                    GL.Enable(EnableCap.Texture2D);
                    GL.BindTexture(TextureTarget.Texture2D, Minimap_GLTexture);
                    GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)TextureEnvMode.Decal);

                    GL.Begin(BeginMode.Quads);

                    GL.TexCoord2(0.0F, 0.0F);
                    GL.Vertex2(0, MinimapSizeXY.Y);

                    GL.TexCoord2((float)XYZ_dbl.X, 0.0F);
                    GL.Vertex2(MinimapSizeXY.X, MinimapSizeXY.Y);

                    GL.TexCoord2((float)XYZ_dbl.X, (float)XYZ_dbl.Z);
                    GL.Vertex2(MinimapSizeXY.X, 0);

                    GL.TexCoord2(0.0F, (float)XYZ_dbl.Z);
                    GL.Vertex2(0, 0);

                    GL.End();

                    GL.Disable(EnableCap.Texture2D);

                    DebugGLError("Minimap");
                }

                //draw minimap border

                GL.LineWidth(1.0F);
                GL.Begin(BeginMode.Lines);
                GL.Color3(0.75F, 0.75F, 0.75F);
                GL.Vertex2(MinimapSizeXY.X, 0.0F);
                GL.Vertex2(MinimapSizeXY.X, MinimapSizeXY.Y);
                GL.Vertex2(0.0F, 0.0F);
                GL.Vertex2(MinimapSizeXY.X, 0.0F);
                GL.End();

                DebugGLError("Minimap border");

                //draw minimap view pos box

                if ( ShowMinimapViewPosBox )
                {
                    dblTemp = App.TerrainGridSpacing * ViewInfo.Tiles_Per_Minimap_Pixel;

                    PosA.X = ViewCorner0.X / dblTemp;
                    PosA.Y = MinimapSizeXY.Y + ViewCorner0.Y / dblTemp;
                    PosB.X = ViewCorner1.X / dblTemp;
                    PosB.Y = MinimapSizeXY.Y + ViewCorner1.Y / dblTemp;
                    PosC.X = ViewCorner2.X / dblTemp;
                    PosC.Y = MinimapSizeXY.Y + ViewCorner2.Y / dblTemp;
                    PosD.X = ViewCorner3.X / dblTemp;
                    PosD.Y = MinimapSizeXY.Y + ViewCorner3.Y / dblTemp;

                    GL.LineWidth(1.0F);
                    GL.Begin(BeginMode.LineLoop);
                    GL.Color3(1.0F, 1.0F, 1.0F);
                    GL.Vertex2(PosA.X, PosA.Y);
                    GL.Vertex2(PosB.X, PosB.Y);
                    GL.Vertex2(PosC.X, PosC.Y);
                    GL.Vertex2(PosD.X, PosD.Y);
                    GL.End();

                    DebugGLError("Minimap view position polygon");
                }

                if ( Selected_Area_VertexA != null )
                {
                    DrawIt = false;
                    if ( Selected_Area_VertexB != null )
                    {
                        //area is selected
                        MathUtil.ReorderXY(Selected_Area_VertexA.XY, Selected_Area_VertexB.XY, StartXY, FinishXY);
                        DrawIt = true;
                    }
                    else if ( modTools.Tool == modTools.Tools.TerrainSelect )
                    {
                        if ( MouseOverTerrain != null )
                        {
                            //selection is changing under mouse
                            MathUtil.ReorderXY(Selected_Area_VertexA.XY, MouseOverTerrain.Vertex.Normal, StartXY, FinishXY);
                            DrawIt = true;
                        }
                    }
                    if ( DrawIt )
                    {
                        GL.LineWidth(1.0F);
                        PosA.X = StartXY.X / ViewInfo.Tiles_Per_Minimap_Pixel;
                        PosA.Y = MinimapSizeXY.Y - StartXY.Y / ViewInfo.Tiles_Per_Minimap_Pixel;
                        PosB.X = FinishXY.X / ViewInfo.Tiles_Per_Minimap_Pixel;
                        PosB.Y = MinimapSizeXY.Y - StartXY.Y / ViewInfo.Tiles_Per_Minimap_Pixel;
                        PosC.X = FinishXY.X / ViewInfo.Tiles_Per_Minimap_Pixel;
                        PosC.Y = MinimapSizeXY.Y - FinishXY.Y / ViewInfo.Tiles_Per_Minimap_Pixel;
                        PosD.X = StartXY.X / ViewInfo.Tiles_Per_Minimap_Pixel;
                        PosD.Y = MinimapSizeXY.Y - FinishXY.Y / ViewInfo.Tiles_Per_Minimap_Pixel;
                        GL.Begin(BeginMode.LineLoop);
                        GL.Color3(1.0F, 1.0F, 1.0F);
                        GL.Vertex2(PosA.X, PosA.Y);
                        GL.Vertex2(PosB.X, PosB.Y);
                        GL.Vertex2(PosC.X, PosC.Y);
                        GL.Vertex2(PosD.X, PosD.Y);
                        GL.End();

                        DebugGLError("Minimap selection box");
                    }
                }
            }
        }
Esempio n. 8
0
        private void OpenGL_KeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            var map = MainMap;

            if (map == null)
            {
                return;
            }

            var matrixA          = new Matrix3DMath.Matrix3D();
            var mouseOverTerrain = map.ViewInfo.GetMouseOverTerrain();

            App.IsViewKeyDown.Keys[(int)e.KeyCode] = true;

            foreach (Option <KeyboardControl> control in KeyboardManager.OptionsKeyboardControls.Options)
            {
                ((KeyboardControl)(KeyboardManager.KeyboardProfile.GetValue(control))).KeysChanged(App.IsViewKeyDown);
            }

            if (KeyboardManager.KeyboardProfile.Active(KeyboardManager.Undo))
            {
                var message = "";
                if (map.UndoPosition > 0)
                {
                    message = "Undid: " + map.Undos[map.UndoPosition - 1].Name;
                    var mapMessage = new Mapping.Message();
                    mapMessage.Text = message;
                    map.Messages.Add(mapMessage);
                    map.UndoPerform();
                    DrawViewLater();
                }
                else
                {
                    message = "Nothing to undo";
                }
                DisplayUndoMessage(message);
            }
            if (KeyboardManager.KeyboardProfile.Active(KeyboardManager.Redo))
            {
                var message = "";
                if (map.UndoPosition < map.Undos.Count)
                {
                    message = "Redid: " + map.Undos[map.UndoPosition].Name;
                    var mapMessage = new Mapping.Message();
                    mapMessage.Text = message;
                    map.Messages.Add(mapMessage);
                    map.RedoPerform();
                    DrawViewLater();
                }
                else
                {
                    message = "Nothing to redo";
                }
                DisplayUndoMessage(message);
            }
            if (App.IsViewKeyDown.Keys[(int)Keys.ControlKey])
            {
                if (e.KeyCode == Keys.D1)
                {
                    App.VisionRadius_2E = 6;
                }
                else if (e.KeyCode == Keys.D2)
                {
                    App.VisionRadius_2E = 7;
                }
                else if (e.KeyCode == Keys.D3)
                {
                    App.VisionRadius_2E = 8;
                }
                else if (e.KeyCode == Keys.D4)
                {
                    App.VisionRadius_2E = 9;
                }
                else if (e.KeyCode == Keys.D5)
                {
                    App.VisionRadius_2E = 10;
                }
                else if (e.KeyCode == Keys.D6)
                {
                    App.VisionRadius_2E = 11;
                }
                else if (e.KeyCode == Keys.D7)
                {
                    App.VisionRadius_2E = 12;
                }
                else if (e.KeyCode == Keys.D8)
                {
                    App.VisionRadius_2E = 13;
                }
                else if (e.KeyCode == Keys.D9)
                {
                    App.VisionRadius_2E = 14;
                }
                else if (e.KeyCode == Keys.D0)
                {
                    App.VisionRadius_2E = 15;
                }
                App.VisionRadius_2E_Changed();
            }

            if (KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewMoveType))
            {
                if (App.ViewMoveType == ViewMoveType.Free)
                {
                    App.ViewMoveType = ViewMoveType.RTS;
                }
                else if (App.ViewMoveType == ViewMoveType.RTS)
                {
                    App.ViewMoveType = ViewMoveType.Free;
                }
            }
            if (KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewRotateType))
            {
                App.RTSOrbit = !App.RTSOrbit;
            }
            if (KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewReset))
            {
                map.ViewInfo.FovMultiplierSet(SettingsManager.Settings.FOVDefault);
                if (App.ViewMoveType == ViewMoveType.Free)
                {
                    Matrix3DMath.MatrixSetToXAngle(matrixA, Math.Atan(2.0D));
                    map.ViewInfo.ViewAngleSetRotate(matrixA);
                }
                else if (App.ViewMoveType == ViewMoveType.RTS)
                {
                    Matrix3DMath.MatrixSetToXAngle(matrixA, Math.Atan(2.0D));
                    map.ViewInfo.ViewAngleSetRotate(matrixA);
                }
            }
            if (KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewTextures))
            {
                App.Draw_TileTextures = !App.Draw_TileTextures;
                DrawViewLater();
            }
            if (KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewWireframe))
            {
                App.Draw_TileWireframe = !App.Draw_TileWireframe;
                DrawViewLater();
            }
            if (KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewUnits))
            {
                App.Draw_Units = !App.Draw_Units;

                var sectorNum = new XYInt();
                for (var y = 0; y <= map.SectorCount.Y - 1; y++)
                {
                    for (var x = 0; x <= map.SectorCount.X - 1; x++)
                    {
                        foreach (var connection in map.Sectors[x, y].Units)
                        {
                            var Unit = connection.Unit;
                            if (Unit.TypeBase.Type == UnitType.PlayerStructure)
                            {
                                if (((StructureTypeBase)Unit.TypeBase).StructureBasePlate != null)
                                {
                                    sectorNum.X = x;
                                    sectorNum.Y = y;
                                    map.SectorGraphicsChanges.Changed(sectorNum);
                                    break;
                                }
                            }
                        }
                    }
                }
                map.Update();
                DrawViewLater();
            }
            if (KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewScriptMarkers))
            {
                App.Draw_ScriptMarkers = !App.Draw_ScriptMarkers;
                DrawViewLater();
            }
            if (KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewLighting))
            {
                if (App.Draw_Lighting == DrawLighting.Off)
                {
                    App.Draw_Lighting = DrawLighting.Half;
                }
                else if (App.Draw_Lighting == DrawLighting.Half)
                {
                    App.Draw_Lighting = DrawLighting.Normal;
                }
                else if (App.Draw_Lighting == DrawLighting.Normal)
                {
                    App.Draw_Lighting = DrawLighting.Off;
                }
                DrawViewLater();
            }
            if (modTools.Tool == modTools.Tools.TextureBrush)
            {
                if (mouseOverTerrain != null)
                {
                    if (KeyboardManager.KeyboardProfile.Active(KeyboardManager.Clockwise))
                    {
                        map.ViewInfo.ApplyTextureClockwise();
                    }
                    if (KeyboardManager.KeyboardProfile.Active(KeyboardManager.CounterClockwise))
                    {
                        map.ViewInfo.ApplyTextureCounterClockwise();
                    }
                    if (KeyboardManager.KeyboardProfile.Active(KeyboardManager.TextureFlip))
                    {
                        map.ViewInfo.ApplyTextureFlipX();
                    }
                    if (KeyboardManager.KeyboardProfile.Active(KeyboardManager.TriFlip))
                    {
                        map.ViewInfo.ApplyTriFlip();
                    }
                }
            }
            if (modTools.Tool == modTools.Tools.ObjectSelect)
            {
                if (KeyboardManager.KeyboardProfile.Active(KeyboardManager.UnitDelete))
                {
                    if (map.SelectedUnits.Count > 0)
                    {
                        foreach (var unit in map.SelectedUnits.GetItemsAsSimpleList())
                        {
                            map.UnitRemoveStoreChange(unit.MapLink.ArrayPosition);
                        }
                        Program.frmMainInstance.SelectedObject_Changed();
                        map.UndoStepCreate("Object Deleted");
                        map.Update();
                        map.MinimapMakeLater();
                        DrawViewLater();
                    }
                }
                if (KeyboardManager.KeyboardProfile.Active(KeyboardManager.UnitMove))
                {
                    if (mouseOverTerrain != null)
                    {
                        if (map.SelectedUnits.Count > 0)
                        {
                            var centre = App.CalcUnitsCentrePos(map.SelectedUnits.GetItemsAsSimpleList());
                            var offset = new XYInt();
                            offset.X = Math.Round(Convert.ToDouble((mouseOverTerrain.Pos.Horizontal.X - centre.X) / Constants.TerrainGridSpacing)).ToInt() * Constants.TerrainGridSpacing;
                            offset.Y = Math.Round(Convert.ToDouble((mouseOverTerrain.Pos.Horizontal.Y - centre.Y) / Constants.TerrainGridSpacing)).ToInt() * Constants.TerrainGridSpacing;
                            var objectPosOffset = new clsObjectPosOffset
                            {
                                Map    = map,
                                Offset = offset
                            };
                            map.SelectedUnitsAction(objectPosOffset);

                            map.UndoStepCreate("Objects Moved");
                            map.Update();
                            map.MinimapMakeLater();
                            Program.frmMainInstance.SelectedObject_Changed();
                            DrawViewLater();
                        }
                    }
                }
                if (KeyboardManager.KeyboardProfile.Active(KeyboardManager.Clockwise))
                {
                    var objectRotationOffset = new clsObjectRotationOffset
                    {
                        Map    = map,
                        Offset = -90
                    };
                    map.SelectedUnitsAction(objectRotationOffset);
                    map.Update();
                    Program.frmMainInstance.SelectedObject_Changed();
                    map.UndoStepCreate("Object Rotated");
                    DrawViewLater();
                }
                if (KeyboardManager.KeyboardProfile.Active(KeyboardManager.CounterClockwise))
                {
                    var objectRotationOffset = new clsObjectRotationOffset
                    {
                        Map    = map,
                        Offset = 90
                    };
                    map.SelectedUnitsAction(objectRotationOffset);
                    map.Update();
                    Program.frmMainInstance.SelectedObject_Changed();
                    map.UndoStepCreate("Object Rotated");
                    DrawViewLater();
                }
            }

            if (KeyboardManager.KeyboardProfile.Active(KeyboardManager.Deselect))
            {
                modTools.Tool = modTools.Tools.ObjectSelect;
                DrawViewLater();
            }

            if (KeyboardManager.KeyboardProfile.Active(KeyboardManager.PreviousTool))
            {
                modTools.Tool = modTools.PreviousTool;
                DrawViewLater();
            }
        }
Esempio n. 9
0
        public void ViewAngleSetToDefault()
        {
            Matrix3DMath.Matrix3D matrixA = new Matrix3DMath.Matrix3D();
            Matrix3DMath.MatrixSetToXAngle(matrixA, Math.Atan(2.0D));
            ViewAngleSet(matrixA);

            MapViewControl.DrawViewLater();
        }
Esempio n. 10
0
        public void TimedActions(double Zoom, double Move, double Pan, double Roll, double OrbitRate)
        {
            Position.XYZ_dbl XYZ_dbl = default(Position.XYZ_dbl);
            double PanRate = Pan * FieldOfViewY;
            Angles.AnglePY AnglePY = default(Angles.AnglePY);
            Matrix3DMath.Matrix3D matrixA = new Matrix3DMath.Matrix3D();
            Matrix3DMath.Matrix3D matrixB = new Matrix3DMath.Matrix3D();
            Position.XYZ_dbl ViewAngleChange = default(Position.XYZ_dbl);
            sXYZ_int ViewPosChangeXYZ = new sXYZ_int();
            bool AngleChanged = default(bool);

            Move *= FOVMultiplier * (MapViewControl.GLSize.X + MapViewControl.GLSize.Y) * Math.Max(Math.Abs(ViewPos.Y), 512.0D);

            if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewZoomIn) )
            {
                FOV_Scale_2E_Change(Convert.ToDouble(- Zoom));
            }
            if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewZoomOut) )
            {
                FOV_Scale_2E_Change(Zoom);
            }

            if ( App.ViewMoveType == App.enumView_Move_Type.Free )
            {
                ViewPosChangeXYZ.X = 0;
                ViewPosChangeXYZ.Y = 0;
                ViewPosChangeXYZ.Z = 0;
                if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewMoveForward) )
                {
                    Matrix3DMath.VectorForwardsRotationByMatrix(ViewAngleMatrix, Move, ref XYZ_dbl);
                    ViewPosChangeXYZ.Add_dbl(XYZ_dbl);
                }
                if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewMoveBackward) )
                {
                    Matrix3DMath.VectorBackwardsRotationByMatrix(ViewAngleMatrix, Move, ref XYZ_dbl);
                    ViewPosChangeXYZ.Add_dbl(XYZ_dbl);
                }
                if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewMoveLeft) )
                {
                    Matrix3DMath.VectorLeftRotationByMatrix(ViewAngleMatrix, Move, ref XYZ_dbl);
                    ViewPosChangeXYZ.Add_dbl(XYZ_dbl);
                }
                if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewMoveRight) )
                {
                    Matrix3DMath.VectorRightRotationByMatrix(ViewAngleMatrix, Move, ref XYZ_dbl);
                    ViewPosChangeXYZ.Add_dbl(XYZ_dbl);
                }
                if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewMoveUp) )
                {
                    Matrix3DMath.VectorUpRotationByMatrix(ViewAngleMatrix, Move, ref XYZ_dbl);
                    ViewPosChangeXYZ.Add_dbl(XYZ_dbl);
                }
                if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewMoveDown) )
                {
                    Matrix3DMath.VectorDownRotationByMatrix(ViewAngleMatrix, Move, ref XYZ_dbl);
                    ViewPosChangeXYZ.Add_dbl(XYZ_dbl);
                }

                ViewAngleChange.X = 0.0D;
                ViewAngleChange.Y = 0.0D;
                ViewAngleChange.Z = 0.0D;
                if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewLeft) )
                {
                    Matrix3DMath.VectorForwardsRotationByMatrix(ViewAngleMatrix, Roll, ref XYZ_dbl);
                    ViewAngleChange += XYZ_dbl;
                }
                if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewRight) )
                {
                    Matrix3DMath.VectorBackwardsRotationByMatrix(ViewAngleMatrix, Roll, ref XYZ_dbl);
                    ViewAngleChange += XYZ_dbl;
                }
                if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewBackward) )
                {
                    Matrix3DMath.VectorLeftRotationByMatrix(ViewAngleMatrix, PanRate, ref XYZ_dbl);
                    ViewAngleChange += XYZ_dbl;
                }
                if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewForward) )
                {
                    Matrix3DMath.VectorRightRotationByMatrix(ViewAngleMatrix, PanRate, ref XYZ_dbl);
                    ViewAngleChange += XYZ_dbl;
                }
                if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewRollLeft) )
                {
                    Matrix3DMath.VectorDownRotationByMatrix(ViewAngleMatrix, PanRate, ref XYZ_dbl);
                    ViewAngleChange += XYZ_dbl;
                }
                if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewRollRight) )
                {
                    Matrix3DMath.VectorUpRotationByMatrix(ViewAngleMatrix, PanRate, ref XYZ_dbl);
                    ViewAngleChange += XYZ_dbl;
                }

                if ( ViewPosChangeXYZ.X != 0.0D | ViewPosChangeXYZ.Y != 0.0D | ViewPosChangeXYZ.Z != 0.0D )
                {
                    ViewPosChange(ViewPosChangeXYZ);
                }
                //do rotation
                if ( ViewAngleChange.X != 0.0D | ViewAngleChange.Y != 0.0D | ViewAngleChange.Z != 0.0D )
                {
                    Matrix3DMath.VectorToPY(ViewAngleChange, ref AnglePY);
                    Matrix3DMath.MatrixSetToPY(matrixA, AnglePY);
                    Matrix3DMath.MatrixRotationAroundAxis(ViewAngleMatrix, matrixA, ViewAngleChange.GetMagnitude(), matrixB);
                    ViewAngleSet_Rotate(matrixB);
                }
            }
            else if ( App.ViewMoveType == App.enumView_Move_Type.RTS )
            {
                ViewPosChangeXYZ = new sXYZ_int();

                Matrix3DMath.MatrixToPY(ViewAngleMatrix, ref AnglePY);
                Matrix3DMath.MatrixSetToYAngle(matrixA, AnglePY.Yaw);
                if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewMoveForward) )
                {
                    Matrix3DMath.VectorForwardsRotationByMatrix(matrixA, Move, ref XYZ_dbl);
                    ViewPosChangeXYZ.Add_dbl(XYZ_dbl);
                }
                if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewMoveBackward) )
                {
                    Matrix3DMath.VectorBackwardsRotationByMatrix(matrixA, Move, ref XYZ_dbl);
                    ViewPosChangeXYZ.Add_dbl(XYZ_dbl);
                }
                if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewMoveLeft) )
                {
                    Matrix3DMath.VectorLeftRotationByMatrix(matrixA, Move, ref XYZ_dbl);
                    ViewPosChangeXYZ.Add_dbl(XYZ_dbl);
                }
                if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewMoveRight) )
                {
                    Matrix3DMath.VectorRightRotationByMatrix(matrixA, Move, ref XYZ_dbl);
                    ViewPosChangeXYZ.Add_dbl(XYZ_dbl);
                }
                if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewMoveUp) )
                {
                    ViewPosChangeXYZ.Y += (int)Move;
                }
                if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewMoveDown) )
                {
                    ViewPosChangeXYZ.Y -= (int)Move;
                }

                AngleChanged = false;

                if ( App.RTSOrbit )
                {
                    if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewForward) )
                    {
                        AnglePY.Pitch = MathUtil.Clamp_dbl(AnglePY.Pitch + OrbitRate, Convert.ToDouble(- MathUtil.RadOf90Deg + 0.03125D * MathUtil.RadOf1Deg),
                            MathUtil.RadOf90Deg - 0.03125D * MathUtil.RadOf1Deg);
                        AngleChanged = true;
                    }
                    if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewBackward) )
                    {
                        AnglePY.Pitch = MathUtil.Clamp_dbl(AnglePY.Pitch - OrbitRate, Convert.ToDouble(- MathUtil.RadOf90Deg + 0.03125D * MathUtil.RadOf1Deg),
                            MathUtil.RadOf90Deg - 0.03125D * MathUtil.RadOf1Deg);
                        AngleChanged = true;
                    }
                    if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewLeft) )
                    {
                        AnglePY.Yaw = MathUtil.AngleClamp(AnglePY.Yaw + OrbitRate);
                        AngleChanged = true;
                    }
                    if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewRight) )
                    {
                        AnglePY.Yaw = MathUtil.AngleClamp(AnglePY.Yaw - OrbitRate);
                        AngleChanged = true;
                    }
                }
                else
                {
                    if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewForward) )
                    {
                        AnglePY.Pitch = MathUtil.Clamp_dbl(AnglePY.Pitch - OrbitRate, Convert.ToDouble(- MathUtil.RadOf90Deg + 0.03125D * MathUtil.RadOf1Deg),
                            MathUtil.RadOf90Deg - 0.03125D * MathUtil.RadOf1Deg);
                        AngleChanged = true;
                    }
                    if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewBackward) )
                    {
                        AnglePY.Pitch = MathUtil.Clamp_dbl(AnglePY.Pitch + OrbitRate, Convert.ToDouble(- MathUtil.RadOf90Deg + 0.03125D * MathUtil.RadOf1Deg),
                            MathUtil.RadOf90Deg - 0.03125D * MathUtil.RadOf1Deg);
                        AngleChanged = true;
                    }
                    if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewLeft) )
                    {
                        AnglePY.Yaw = MathUtil.AngleClamp(AnglePY.Yaw - OrbitRate);
                        AngleChanged = true;
                    }
                    if ( KeyboardManager.KeyboardProfile.Active(KeyboardManager.ViewRight) )
                    {
                        AnglePY.Yaw = MathUtil.AngleClamp(AnglePY.Yaw + OrbitRate);
                        AngleChanged = true;
                    }
                }

                //Dim HeightChange As Double
                //HeightChange = Map.Terrain_Height_Get(view.View_Pos.X + ViewPosChange.X, view.View_Pos.Z + ViewPosChange.Z) - Map.Terrain_Height_Get(view.View_Pos.X, view.View_Pos.Z)

                //ViewPosChange.Y = ViewPosChange.Y + HeightChange

                if ( ViewPosChangeXYZ.X != 0.0D | ViewPosChangeXYZ.Y != 0.0D | ViewPosChangeXYZ.Z != 0.0D )
                {
                    ViewPosChange(ViewPosChangeXYZ);
                }
                if ( AngleChanged )
                {
                    Matrix3DMath.MatrixSetToPY(matrixA, AnglePY);
                    ViewAngleSet_Rotate(matrixA);
                }
            }
        }
Esempio n. 11
0
        public void LookAtPos(sXY_int Horizontal)
        {
            Position.XYZ_dbl XYZ_dbl = default(Position.XYZ_dbl);
            sXYZ_int XYZ_int = new sXYZ_int();
            double dblTemp = 0;
            int A = 0;
            Matrix3DMath.Matrix3D matrixA = new Matrix3DMath.Matrix3D();
            Angles.AnglePY AnglePY = default(Angles.AnglePY);

            Matrix3DMath.VectorForwardsRotationByMatrix(ViewAngleMatrix, ref XYZ_dbl);
            dblTemp = Map.GetTerrainHeight(Horizontal);
            A = ((int)(Math.Ceiling(dblTemp))) + 128;
            if ( ViewPos.Y < A )
            {
                ViewPos.Y = A;
            }
            if ( XYZ_dbl.Y > -0.33333333333333331D )
            {
                XYZ_dbl.Y = -0.33333333333333331D;
                Matrix3DMath.VectorToPY(XYZ_dbl, ref AnglePY);
                Matrix3DMath.MatrixSetToPY(matrixA, AnglePY);
                ViewAngleSet(matrixA);
            }
            dblTemp = (ViewPos.Y - dblTemp) / XYZ_dbl.Y;

            XYZ_int.X = (int)(Horizontal.X + dblTemp * XYZ_dbl.X);
            XYZ_int.Y = ViewPos.Y;
            XYZ_int.Z = (int)(- Horizontal.Y + dblTemp * XYZ_dbl.Z);

            ViewPosSet(XYZ_int);
        }
Esempio n. 12
0
            public void GLDraw()
            {
                Angles.AngleRPY AngleRPY = default(Angles.AngleRPY);
                Matrix3DMath.Matrix3D matrixA = new Matrix3DMath.Matrix3D();
                clsAttachment Attachment = default(clsAttachment);
                clsModel Model = default(clsModel);

                foreach ( clsModel tempLoopVar_Model in Models )
                {
                    Model = tempLoopVar_Model;
                    Model.GLDraw();
                }

                foreach ( clsAttachment tempLoopVar_Attachment in Attachments )
                {
                    Attachment = tempLoopVar_Attachment;
                    GL.PushMatrix();
                    Matrix3DMath.MatrixInvert(Attachment.AngleOffsetMatrix, matrixA);
                    Matrix3DMath.MatrixToRPY(matrixA, ref AngleRPY);
                    GL.Translate(Attachment.Pos_Offset.X, Attachment.Pos_Offset.Y, Convert.ToDouble(- Attachment.Pos_Offset.Z));
                    GL.Rotate((float)(AngleRPY.Roll / MathUtil.RadOf1Deg), 0.0F, 0.0F, -1.0F);
                    GL.Rotate((float)(AngleRPY.Pitch / MathUtil.RadOf1Deg), 1.0F, 0.0F, 0.0F);
                    GL.Rotate((float)(AngleRPY.Yaw / MathUtil.RadOf1Deg), 0.0F, 1.0F, 0.0F);
                    Attachment.GLDraw();
                    GL.PopMatrix();
                }
            }
Esempio n. 13
0
 private void OpenGL_KeyDown(object sender, PreviewKeyDownEventArgs e)
 {
     clsMap mainMap = this.MainMap;
     if (mainMap != null)
     {
         IEnumerator enumerator;
         Matrix3DMath.Matrix3D matrix = new Matrix3DMath.Matrix3D();
         clsViewInfo.clsMouseOver.clsOverTerrain mouseOverTerrain = mainMap.ViewInfo.GetMouseOverTerrain();
         modProgram.IsViewKeyDown.Keys[(int) e.KeyCode] = true;
         try
         {
             enumerator = modControls.Options_KeyboardControls.Options.GetEnumerator();
             while (enumerator.MoveNext())
             {
                 clsOption<clsKeyboardControl> current = (clsOption<clsKeyboardControl>) enumerator.Current;
                 ((clsKeyboardControl) modControls.KeyboardProfile.get_Value(current)).KeysChanged(modProgram.IsViewKeyDown);
             }
         }
         finally
         {
             if (enumerator is IDisposable)
             {
                 (enumerator as IDisposable).Dispose();
             }
         }
         if (modControls.KeyboardProfile.Active(modControls.Control_Undo))
         {
             string str;
             if (mainMap.UndoPosition > 0)
             {
                 str = "Undid: " + mainMap.Undos[mainMap.UndoPosition - 1].Name;
                 clsMap.clsMessage newItem = new clsMap.clsMessage {
                     Text = str
                 };
                 mainMap.Messages.Add(newItem);
                 mainMap.UndoPerform();
                 this.DrawViewLater();
             }
             else
             {
                 str = "Nothing to undo";
             }
             this.DisplayUndoMessage(str);
         }
         if (modControls.KeyboardProfile.Active(modControls.Control_Redo))
         {
             string str2;
             if (mainMap.UndoPosition < mainMap.Undos.Count)
             {
                 str2 = "Redid: " + mainMap.Undos[mainMap.UndoPosition].Name;
                 clsMap.clsMessage message2 = new clsMap.clsMessage {
                     Text = str2
                 };
                 mainMap.Messages.Add(message2);
                 mainMap.RedoPerform();
                 this.DrawViewLater();
             }
             else
             {
                 str2 = "Nothing to redo";
             }
             this.DisplayUndoMessage(str2);
         }
         if (modProgram.IsViewKeyDown.Keys[0x11])
         {
             if (e.KeyCode == Keys.D1)
             {
                 modProgram.VisionRadius_2E = 6;
             }
             else if (e.KeyCode == Keys.D2)
             {
                 modProgram.VisionRadius_2E = 7;
             }
             else if (e.KeyCode == Keys.D3)
             {
                 modProgram.VisionRadius_2E = 8;
             }
             else if (e.KeyCode == Keys.D4)
             {
                 modProgram.VisionRadius_2E = 9;
             }
             else if (e.KeyCode == Keys.D5)
             {
                 modProgram.VisionRadius_2E = 10;
             }
             else if (e.KeyCode == Keys.D6)
             {
                 modProgram.VisionRadius_2E = 11;
             }
             else if (e.KeyCode == Keys.D7)
             {
                 modProgram.VisionRadius_2E = 12;
             }
             else if (e.KeyCode == Keys.D8)
             {
                 modProgram.VisionRadius_2E = 13;
             }
             else if (e.KeyCode == Keys.D9)
             {
                 modProgram.VisionRadius_2E = 14;
             }
             else if (e.KeyCode == Keys.D0)
             {
                 modProgram.VisionRadius_2E = 15;
             }
             modProgram.VisionRadius_2E_Changed();
         }
         if (modControls.KeyboardProfile.Active(modControls.Control_View_Move_Type))
         {
             if (modProgram.ViewMoveType == modProgram.enumView_Move_Type.Free)
             {
                 modProgram.ViewMoveType = modProgram.enumView_Move_Type.RTS;
             }
             else if (modProgram.ViewMoveType == modProgram.enumView_Move_Type.RTS)
             {
                 modProgram.ViewMoveType = modProgram.enumView_Move_Type.Free;
             }
         }
         if (modControls.KeyboardProfile.Active(modControls.Control_View_Rotate_Type))
         {
             modProgram.RTSOrbit = !modProgram.RTSOrbit;
         }
         if (modControls.KeyboardProfile.Active(modControls.Control_View_Reset))
         {
             mainMap.ViewInfo.FOV_Multiplier_Set(modSettings.Settings.FOVDefault);
             if (modProgram.ViewMoveType == modProgram.enumView_Move_Type.Free)
             {
                 Matrix3DMath.MatrixSetToXAngle(matrix, Math.Atan(2.0));
                 mainMap.ViewInfo.ViewAngleSet_Rotate(matrix);
             }
             else if (modProgram.ViewMoveType == modProgram.enumView_Move_Type.RTS)
             {
                 Matrix3DMath.MatrixSetToXAngle(matrix, Math.Atan(2.0));
                 mainMap.ViewInfo.ViewAngleSet_Rotate(matrix);
             }
         }
         if (modControls.KeyboardProfile.Active(modControls.Control_View_Textures))
         {
             modProgram.Draw_TileTextures = !modProgram.Draw_TileTextures;
             this.DrawViewLater();
         }
         if (modControls.KeyboardProfile.Active(modControls.Control_View_Wireframe))
         {
             modProgram.Draw_TileWireframe = !modProgram.Draw_TileWireframe;
             this.DrawViewLater();
         }
         if (modControls.KeyboardProfile.Active(modControls.Control_View_Units))
         {
             modProgram.Draw_Units = !modProgram.Draw_Units;
             int num3 = mainMap.SectorCount.Y - 1;
             for (int i = 0; i <= num3; i++)
             {
                 int num4 = mainMap.SectorCount.X - 1;
                 for (int j = 0; j <= num4; j++)
                 {
                     IEnumerator enumerator2;
                     try
                     {
                         enumerator2 = mainMap.Sectors[j, i].Units.GetEnumerator();
                         while (enumerator2.MoveNext())
                         {
                             clsMap.clsUnitSectorConnection connection = (clsMap.clsUnitSectorConnection) enumerator2.Current;
                             clsMap.clsUnit unit = connection.Unit;
                             if ((unit.Type.Type == clsUnitType.enumType.PlayerStructure) && (((clsStructureType) unit.Type).StructureBasePlate != null))
                             {
                                 modMath.sXY_int _int;
                                 _int.X = j;
                                 _int.Y = i;
                                 mainMap.SectorGraphicsChanges.Changed(_int);
                                 continue;
                             }
                         }
                     }
                     finally
                     {
                         if (enumerator2 is IDisposable)
                         {
                             (enumerator2 as IDisposable).Dispose();
                         }
                     }
                 }
             }
             mainMap.Update();
             this.DrawViewLater();
         }
         if (modControls.KeyboardProfile.Active(modControls.Control_View_ScriptMarkers))
         {
             modProgram.Draw_ScriptMarkers = !modProgram.Draw_ScriptMarkers;
             this.DrawViewLater();
         }
         if (modControls.KeyboardProfile.Active(modControls.Control_View_Lighting))
         {
             if (modProgram.Draw_Lighting == modProgram.enumDrawLighting.Off)
             {
                 modProgram.Draw_Lighting = modProgram.enumDrawLighting.Half;
             }
             else if (modProgram.Draw_Lighting == modProgram.enumDrawLighting.Half)
             {
                 modProgram.Draw_Lighting = modProgram.enumDrawLighting.Normal;
             }
             else if (modProgram.Draw_Lighting == modProgram.enumDrawLighting.Normal)
             {
                 modProgram.Draw_Lighting = modProgram.enumDrawLighting.Off;
             }
             this.DrawViewLater();
         }
         if ((modTools.Tool == modTools.Tools.TextureBrush) && (mouseOverTerrain != null))
         {
             if (modControls.KeyboardProfile.Active(modControls.Control_Clockwise))
             {
                 mainMap.ViewInfo.Apply_Texture_Clockwise();
             }
             if (modControls.KeyboardProfile.Active(modControls.Control_CounterClockwise))
             {
                 mainMap.ViewInfo.Apply_Texture_CounterClockwise();
             }
             if (modControls.KeyboardProfile.Active(modControls.Control_Texture_Flip))
             {
                 mainMap.ViewInfo.Apply_Texture_FlipX();
             }
             if (modControls.KeyboardProfile.Active(modControls.Control_Tri_Flip))
             {
                 mainMap.ViewInfo.Apply_Tri_Flip();
             }
         }
         if (modTools.Tool == modTools.Tools.ObjectSelect)
         {
             if (modControls.KeyboardProfile.Active(modControls.Control_Unit_Delete) && (mainMap.SelectedUnits.Count > 0))
             {
                 IEnumerator enumerator3;
                 try
                 {
                     enumerator3 = mainMap.SelectedUnits.GetItemsAsSimpleList().GetEnumerator();
                     while (enumerator3.MoveNext())
                     {
                         clsMap.clsUnit unit2 = (clsMap.clsUnit) enumerator3.Current;
                         mainMap.UnitRemoveStoreChange(unit2.MapLink.ArrayPosition);
                     }
                 }
                 finally
                 {
                     if (enumerator3 is IDisposable)
                     {
                         (enumerator3 as IDisposable).Dispose();
                     }
                 }
                 modMain.frmMainInstance.SelectedObject_Changed();
                 mainMap.UndoStepCreate("Object Deleted");
                 mainMap.Update();
                 mainMap.MinimapMakeLater();
                 this.DrawViewLater();
             }
             if ((modControls.KeyboardProfile.Active(modControls.Control_Unit_Move) && (mouseOverTerrain != null)) && (mainMap.SelectedUnits.Count > 0))
             {
                 modMath.sXY_int _int2;
                 Position.XY_dbl _dbl = modProgram.CalcUnitsCentrePos(mainMap.SelectedUnits.GetItemsAsSimpleList());
                 _int2.X = ((int) Math.Round(Math.Round((double) ((mouseOverTerrain.Pos.Horizontal.X - _dbl.X) / 128.0)))) * 0x80;
                 _int2.Y = ((int) Math.Round(Math.Round((double) ((mouseOverTerrain.Pos.Horizontal.Y - _dbl.Y) / 128.0)))) * 0x80;
                 clsMap.clsObjectPosOffset tool = new clsMap.clsObjectPosOffset {
                     Map = mainMap,
                     Offset = _int2
                 };
                 mainMap.SelectedUnitsAction(tool);
                 mainMap.UndoStepCreate("Objects Moved");
                 mainMap.Update();
                 mainMap.MinimapMakeLater();
                 modMain.frmMainInstance.SelectedObject_Changed();
                 this.DrawViewLater();
             }
             if (modControls.KeyboardProfile.Active(modControls.Control_Clockwise))
             {
                 clsMap.clsObjectRotationOffset offset2 = new clsMap.clsObjectRotationOffset {
                     Map = mainMap,
                     Offset = -90
                 };
                 mainMap.SelectedUnitsAction(offset2);
                 mainMap.Update();
                 modMain.frmMainInstance.SelectedObject_Changed();
                 mainMap.UndoStepCreate("Object Rotated");
                 this.DrawViewLater();
             }
             if (modControls.KeyboardProfile.Active(modControls.Control_CounterClockwise))
             {
                 clsMap.clsObjectRotationOffset offset3 = new clsMap.clsObjectRotationOffset {
                     Map = mainMap,
                     Offset = 90
                 };
                 mainMap.SelectedUnitsAction(offset3);
                 mainMap.Update();
                 modMain.frmMainInstance.SelectedObject_Changed();
                 mainMap.UndoStepCreate("Object Rotated");
                 this.DrawViewLater();
             }
         }
         if (modControls.KeyboardProfile.Active(modControls.Control_Deselect))
         {
             modTools.Tool = modTools.Tools.ObjectSelect;
             this.DrawViewLater();
         }
         if (modControls.KeyboardProfile.Active(modControls.Control_PreviousTool))
         {
             modTools.Tool = modTools.PreviousTool;
             this.DrawViewLater();
         }
     }
 }