public clsAttachment CopyAttachment(clsAttachment Other) { var result = new clsAttachment { PosOffset = Other.PosOffset }; Attachments.Add(result); Matrix3DMath.MatrixCopy(Other.AngleOffsetMatrix, result.AngleOffsetMatrix); result.Models.AddRange(Other.Models); result.Attachments.AddRange(Other.Attachments); return(result); }
public clsAttachment AddCopyOfAttachment(clsAttachment AttachmentToCopy) { var ResultAttachment = new clsAttachment(); var Attachment = default(clsAttachment); Attachments.Add(ResultAttachment); Matrix3DMath.MatrixCopy(AttachmentToCopy.AngleOffsetMatrix, ResultAttachment.AngleOffsetMatrix); ResultAttachment.Models.AddRange(AttachmentToCopy.Models); foreach (var tempLoopVar_Attachment in AttachmentToCopy.Attachments) { Attachment = tempLoopVar_Attachment; ResultAttachment.AddCopyOfAttachment(Attachment); } return(ResultAttachment); }
public void OpenGL_MouseWheel(object sender, MouseEventArgs e) { var map = MainMap; if (map == null) { return; } var move = new XYZInt(0, 0, 0); var xyzDbl = default(XYZDouble); for (var a = 0; a <= Math.Abs(e.Delta / 120.0D).ToInt(); a++) { Matrix3DMath.VectorForwardsRotationByMatrix(map.ViewInfo.ViewAngleMatrix, Convert.ToDouble(Math.Sign(e.Delta) * Math.Max(map.ViewInfo.ViewPos.Y, 512.0D) / 24.0D), ref xyzDbl); move.SetDbl(xyzDbl); map.ViewInfo.ViewPosChange(move); } }
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(); } }
public override void ActionPerform() { var X = 0; var Y = 0; var A = 0; for (Y = PosNum.Y * Constants.SectorTileSize; Y <= Math.Min(Convert.ToInt32((PosNum.Y + 1) * Constants.SectorTileSize - 1), Map.Terrain.TileSize.Y); Y++) { for (X = PosNum.X * Constants.SectorTileSize; X <= Math.Min((PosNum.X + 1) * Constants.SectorTileSize - 1, Map.Terrain.TileSize.X); X++) { if (Map.Terrain.Vertices[X, Y].Terrain != null) { A = Map.Terrain.Vertices[X, Y].Terrain.Num; if (A < Map.Painter.TerrainCount) { if (Map.Painter.Terrains[A].Tiles.TileCount >= 1) { _rgb = Map.Tileset.Tiles[Map.Painter.Terrains[A].Tiles.Tiles[0].TextureNum].AverageColour; if (_rgb.Red + _rgb.Green + _rgb.Blue < 1.5F) { RGB_sng2.Red = (_rgb.Red + 1.0F) / 2.0F; RGB_sng2.Green = (_rgb.Green + 1.0F) / 2.0F; RGB_sng2.Blue = (_rgb.Blue + 1.0F) / 2.0F; } else { RGB_sng2.Red = _rgb.Red / 2.0F; RGB_sng2.Green = _rgb.Green / 2.0F; RGB_sng2.Blue = _rgb.Blue / 2.0F; } XYZ_dbl.X = X * Constants.TerrainGridSpacing; XYZ_dbl.Y = Convert.ToDouble(Map.Terrain.Vertices[X, Y].Height * Map.HeightMultiplier); XYZ_dbl.Z = -Y * Constants.TerrainGridSpacing; XYZ_dbl2.X = 10.0D; XYZ_dbl2.Y = 10.0D; XYZ_dbl2.Z = 0.0D; Matrix3DMath.VectorRotationByMatrix(ViewAngleMatrix, XYZ_dbl2, ref XYZ_dbl3); Vertex0.X = XYZ_dbl.X + XYZ_dbl3.X; Vertex0.Y = XYZ_dbl.Y + XYZ_dbl3.Y; Vertex0.Z = XYZ_dbl.Z + XYZ_dbl3.Z; XYZ_dbl2.X = -10.0D; XYZ_dbl2.Y = 10.0D; XYZ_dbl2.Z = 0.0D; Matrix3DMath.VectorRotationByMatrix(ViewAngleMatrix, XYZ_dbl2, ref XYZ_dbl3); Vertex1.X = XYZ_dbl.X + XYZ_dbl3.X; Vertex1.Y = XYZ_dbl.Y + XYZ_dbl3.Y; Vertex1.Z = XYZ_dbl.Z + XYZ_dbl3.Z; XYZ_dbl2.X = -10.0D; XYZ_dbl2.Y = -10.0D; XYZ_dbl2.Z = 0.0D; Matrix3DMath.VectorRotationByMatrix(ViewAngleMatrix, XYZ_dbl2, ref XYZ_dbl3); Vertex2.X = XYZ_dbl.X + XYZ_dbl3.X; Vertex2.Y = XYZ_dbl.Y + XYZ_dbl3.Y; Vertex2.Z = XYZ_dbl.Z + XYZ_dbl3.Z; XYZ_dbl2.X = 10.0D; XYZ_dbl2.Y = -10.0D; XYZ_dbl2.Z = 0.0D; Matrix3DMath.VectorRotationByMatrix(ViewAngleMatrix, XYZ_dbl2, ref XYZ_dbl3); Vertex3.X = XYZ_dbl.X + XYZ_dbl3.X; Vertex3.Y = XYZ_dbl.Y + XYZ_dbl3.Y; Vertex3.Z = XYZ_dbl.Z + XYZ_dbl3.Z; GL.Begin(BeginMode.Quads); GL.Color3(_rgb.Red, _rgb.Green, _rgb.Blue); GL.Vertex3(Vertex0.X, Vertex0.Y, Convert.ToDouble(-Vertex0.Z)); GL.Vertex3(Vertex1.X, Vertex1.Y, Convert.ToDouble(-Vertex1.Z)); GL.Vertex3(Vertex2.X, Vertex2.Y, Convert.ToDouble(-Vertex2.Z)); GL.Vertex3(Vertex3.X, Vertex3.Y, Convert.ToDouble(-Vertex3.Z)); GL.End(); GL.Begin(BeginMode.LineLoop); GL.Color3(RGB_sng2.Red, RGB_sng2.Green, RGB_sng2.Blue); GL.Vertex3(Vertex0.X, Vertex0.Y, Convert.ToDouble(-Vertex0.Z)); GL.Vertex3(Vertex1.X, Vertex1.Y, Convert.ToDouble(-Vertex1.Z)); GL.Vertex3(Vertex2.X, Vertex2.Y, Convert.ToDouble(-Vertex2.Z)); GL.Vertex3(Vertex3.X, Vertex3.Y, Convert.ToDouble(-Vertex3.Z)); GL.End(); } } } } } }
public void ViewAngleSet_Rotate(Matrix3DMath.Matrix3D NewMatrix) { bool flag; Position.XYZ_dbl _dbl2; if ((modProgram.ViewMoveType == modProgram.enumView_Move_Type.RTS) & modProgram.RTSOrbit) { Position.XY_dbl _dbl; flag = true; if (this.ScreenXY_Get_ViewPlanePos_ForwardDownOnly((int) Math.Round(Conversion.Int((double) (((double) this.MapView.GLSize.X) / 2.0))), (int) Math.Round(Conversion.Int((double) (((double) this.MapView.GLSize.Y) / 2.0))), 127.5, ref _dbl)) { _dbl2.X = _dbl.X; _dbl2.Y = 127.5; _dbl2.Z = -_dbl.Y; } else { flag = false; } } else { flag = false; } Matrix3DMath.MatrixToRPY(NewMatrix, ref this.ViewAngleRPY); if (flag && (this.ViewAngleRPY.Pitch < 0.17453292519943295)) { this.ViewAngleRPY.Pitch = 0.17453292519943295; } Matrix3DMath.MatrixSetToRPY(this.ViewAngleMatrix, this.ViewAngleRPY); Matrix3DMath.MatrixInvert(this.ViewAngleMatrix, this.ViewAngleMatrix_Inverted); if (flag) { Position.XYZ_dbl _dbl3; _dbl3.X = this.ViewPos.X; _dbl3.Y = this.ViewPos.Y; _dbl3.Z = 0 - this.ViewPos.Z; this.MoveToViewTerrainPosFromDistance(_dbl2, (_dbl3 - _dbl2).GetMagnitude()); } this.MapView.DrawViewLater(); }
public void ViewAngleSet(Matrix3DMath.Matrix3D NewMatrix) { Matrix3DMath.MatrixCopy(NewMatrix, this.ViewAngleMatrix); Matrix3DMath.MatrixNormalize(this.ViewAngleMatrix); Matrix3DMath.MatrixInvert(this.ViewAngleMatrix, this.ViewAngleMatrix_Inverted); Matrix3DMath.MatrixToRPY(this.ViewAngleMatrix, ref this.ViewAngleRPY); this.MapView.DrawViewLater(); }
public clsAttachment() { Models.AddNullItemBehavior = AddNullItemBehavior.DisallowIgnore; Matrix3DMath.MatrixSetToIdentity(AngleOffsetMatrix); }
public override void ActionPerform() { if (!Started) { Debugger.Break(); return; } var Unit = default(Unit); var Sector = Map.Sectors[PosNum.X, PosNum.Y]; var DrawUnitLabel = default(bool); var ViewInfo = Map.ViewInfo; var MouseOverTerrain = ViewInfo.GetMouseOverTerrain(); var TextLabel = default(clsTextLabel); var XYZ_dbl = default(XYZDouble); var XYZ_dbl2 = default(XYZDouble); var ScreenPos = new XYInt(); var Connection = default(clsUnitSectorConnection); foreach (var tempLoopVar_Connection in Sector.Units) { Connection = tempLoopVar_Connection; Unit = Connection.Unit; if (!UnitDrawn[Unit.MapLink.ArrayPosition]) { UnitDrawn[Unit.MapLink.ArrayPosition] = true; XYZ_dbl.X = Unit.Pos.Horizontal.X - ViewInfo.ViewPos.X; XYZ_dbl.Y = Unit.Pos.Altitude - ViewInfo.ViewPos.Y; XYZ_dbl.Z = -Unit.Pos.Horizontal.Y - ViewInfo.ViewPos.Z; DrawUnitLabel = false; if (Unit.TypeBase.IsUnknown) { DrawUnitLabel = true; } else { GL.PushMatrix(); GL.Translate(XYZ_dbl.X, XYZ_dbl.Y, Convert.ToDouble(-XYZ_dbl.Z)); Unit.TypeBase.GLDraw(Unit.Rotation); GL.PopMatrix(); if (Unit.TypeBase.Type == UnitType.PlayerDroid) { if (((DroidDesign)Unit.TypeBase).AlwaysDrawTextLabel) { DrawUnitLabel = true; } } if (MouseOverTerrain != null) { if (MouseOverTerrain.Units.Count > 0) { if (MouseOverTerrain.Units[0] == Unit) { DrawUnitLabel = true; } } } } if (DrawUnitLabel && !UnitTextLabels.AtMaxCount()) { Matrix3DMath.VectorRotationByMatrix(ViewInfo.ViewAngleMatrixInverted, XYZ_dbl, ref XYZ_dbl2); if (ViewInfo.PosGetScreenXY(XYZ_dbl2, ref ScreenPos)) { if (ScreenPos.X >= 0 & ScreenPos.X <= ViewInfo.MapViewControl.GLSize.X & ScreenPos.Y >= 0 & ScreenPos.Y <= ViewInfo.MapViewControl.GLSize.Y) { TextLabel = new clsTextLabel(); TextLabel.TextFont = App.UnitLabelFont; TextLabel.SizeY = SettingsManager.Settings.FontSize; TextLabel.Colour.Red = 1.0F; TextLabel.Colour.Green = 1.0F; TextLabel.Colour.Blue = 1.0F; TextLabel.Colour.Alpha = 1.0F; TextLabel.Pos.X = ScreenPos.X + 32; TextLabel.Pos.Y = ScreenPos.Y; TextLabel.Text = Unit.TypeBase.GetDisplayTextCode(); UnitTextLabels.Add(TextLabel); } } } } } }
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(); } }
public void ViewAngleSet_Rotate(Matrix3DMath.Matrix3D NewMatrix) { bool Flag = default(bool); Position.XYZ_dbl XYZ_dbl = default(Position.XYZ_dbl); Position.XYZ_dbl XYZ_dbl2 = default(Position.XYZ_dbl); //Dim XYZ_lng As sXYZ_lng Position.XY_dbl XY_dbl = default(Position.XY_dbl); if ( App.ViewMoveType == App.enumView_Move_Type.RTS & App.RTSOrbit ) { Flag = true; //If ScreenXY_Get_TerrainPos(CInt(Int(GLSize.X / 2.0#)), CInt(Int(GLSize.Y / 2.0#)), XYZ_lng) Then // XYZ_dbl.X = XYZ_lng.X // XYZ_dbl.Y = XYZ_lng.Y // XYZ_dbl.Z = XYZ_lng.Z //Else if ( ScreenXY_Get_ViewPlanePos_ForwardDownOnly((int)(Conversion.Int(MapViewControl.GLSize.X / 2.0D)), (int)(Conversion.Int(MapViewControl.GLSize.Y / 2.0D)), 127.5D, XY_dbl) ) { XYZ_dbl.X = XY_dbl.X; XYZ_dbl.Y = 127.5D; XYZ_dbl.Z = Convert.ToDouble(- XY_dbl.Y); } else { Flag = false; } //End If } else { Flag = false; } Matrix3DMath.MatrixToRPY(NewMatrix, ref ViewAngleRPY); if ( Flag ) { if ( ViewAngleRPY.Pitch < MathUtil.RadOf1Deg * 10.0D ) { ViewAngleRPY.Pitch = MathUtil.RadOf1Deg * 10.0D; } } Matrix3DMath.MatrixSetToRPY(ViewAngleMatrix, ViewAngleRPY); Matrix3DMath.MatrixInvert(ViewAngleMatrix, ViewAngleMatrix_Inverted); if ( Flag ) { XYZ_dbl2.X = ViewPos.X; XYZ_dbl2.Y = ViewPos.Y; XYZ_dbl2.Z = Convert.ToDouble(- ViewPos.Z); MoveToViewTerrainPosFromDistance(XYZ_dbl, Convert.ToDouble((XYZ_dbl2 - XYZ_dbl).GetMagnitude())); } MapViewControl.DrawViewLater(); }
public void ViewAngleSet(Matrix3DMath.Matrix3D NewMatrix) { Matrix3DMath.MatrixCopy(NewMatrix, ViewAngleMatrix); Matrix3DMath.MatrixNormalize(ViewAngleMatrix); Matrix3DMath.MatrixInvert(ViewAngleMatrix, ViewAngleMatrix_Inverted); Matrix3DMath.MatrixToRPY(ViewAngleMatrix, ref ViewAngleRPY); MapViewControl.DrawViewLater(); }