private void sliderFogDensity_Scroll(object sender, EventArgs e) { ignoreFogDensityChange = true; Map.FogDensity = (float)sliderFogDensity.Value / 100; ignoreFogDensityChange = false; Renderer.Invalidate(); }
private void buttonOpenMap_Click(object sender, EventArgs e) { if (Directory.Exists(LastOpenLocation)) { openMapDialog.InitialDirectory = LastOpenLocation; } DialogResult result = openMapDialog.ShowDialog(); if (result == DialogResult.OK) { LastOpenLocation = Path.GetDirectoryName(openMapDialog.FileName); Map.Clear(); gridProblems.Rows.Clear(); Problem.Problems.Clear(); LuaMap.LoadMap(openMapDialog.FileName); Map.Path = openMapDialog.FileName; Program.Camera.ResetCamera(); Program.main.UpdateProblems(); Renderer.InvalidateMeshData(); Renderer.InvalidateView(); Renderer.Invalidate(); } }
private void sliderFogAlpha_Scroll(object sender, EventArgs e) { ignoreFogAlphaChange = true; Map.FogColor = new Vector4(Map.FogColor.X, Map.FogColor.Y, Map.FogColor.Z, (float)sliderFogAlpha.Value / 100); ignoreFogAlphaChange = false; Renderer.Invalidate(); }
public void UpdatePanning() { float angleFactor = (float)(Angles.X - Math.PI) / (float)(Math.PI * 1.5f) * 3; bool posChanged = false; if (ActionKey.IsDown(Action.PAN_RIGHT) || ActionKey.IsDown(Action.PAN_LEFT) || ActionKey.IsDown(Action.PAN_FORWARDS) || ActionKey.IsDown(Action.PAN_BACKWARDS) || ActionKey.IsDown(Action.PAN_UP) || ActionKey.IsDown(Action.PAN_DOWN)) { posChanged = true; } if (ActionKey.IsDown(Action.PAN_RIGHT)) { panDelta += new Vector3(Renderer.View.M11, Renderer.View.M21, Renderer.View.M31); } else if (ActionKey.IsDown(Action.PAN_LEFT)) { panDelta += -new Vector3(Renderer.View.M11, Renderer.View.M21, Renderer.View.M31); } if (ActionKey.IsDown(Action.PAN_FORWARDS)) { panDelta += Vector3.Divide(Vector3.Divide(new Vector3(Renderer.View.M12, 0, Renderer.View.M32), angleFactor), 1.2f); //Ignore x and z rotation of the matrix } else if (ActionKey.IsDown(Action.PAN_BACKWARDS)) { panDelta += -Vector3.Divide(Vector3.Divide(new Vector3(Renderer.View.M12, 0, Renderer.View.M32), angleFactor), 1.2f); //Ignore x and z rotation of the matrix } if (ActionKey.IsDown(Action.PAN_UP)) { panDelta += Vector3.UnitY; } else if (ActionKey.IsDown(Action.PAN_DOWN)) { panDelta += -Vector3.UnitY; } if (Program.GLControl.Focused) //VERY UGLY, THERE HAS TO BE A BETTER SOLUTION? { float finalPanSpeed = 1; if (!Orthographic) { finalPanSpeed = (float)Math.Max(PanSpeed * zoom, PAN_MIN_SPEED); } else { finalPanSpeed = (float)Math.Max(1 / OrthographicSize * 700, PAN_MIN_SPEED); //The orthographic size gets smaller the more you zoom out, so the speed should raise the lower the size gets } LookAt += panDelta * finalPanSpeed * (float)Program.ElapsedSeconds; panDelta = Vector3.Zero; UpdatePosition(); Renderer.InvalidateView(); Renderer.Invalidate(); } }
public void glControl_Resize(object sender, EventArgs e) { if (!Loaded) { return; } Renderer.Resize(); Renderer.Invalidate(); }
private void checkFogActive_CheckedChanged(object sender, EventArgs e) { Map.FogActive = checkFogActive.Checked; numericFogStart.Enabled = checkFogActive.Checked; numericFogEnd.Enabled = checkFogActive.Checked; buttonFogColor.Enabled = checkFogActive.Checked; sliderFogAlpha.Enabled = checkFogActive.Checked; comboFogType.Enabled = checkFogActive.Checked; sliderFogDensity.Enabled = checkFogActive.Checked; Renderer.Invalidate(); }
private void buttonFogColor_Click(object sender, EventArgs e) { colorDialog.Color = buttonFogColor.BackColor; DialogResult result = colorDialog.ShowDialog(); if (result == DialogResult.OK) { buttonFogColor.BackColor = colorDialog.Color; Map.FogColor = new Vector4((float)colorDialog.Color.R / 255, (float)colorDialog.Color.G / 255, (float)colorDialog.Color.B / 255, Map.FogColor.W); Renderer.Invalidate(); } }
public static void SetSkyboxFade(float fade) { foreach (Drawable face in Skybox) { if (face != null) { face.Mesh.Material.TextureFactor = fade; } } if (Program.GLControl != null) { Renderer.Invalidate(); } }
public static void UpdateRectangleSelection(int mouseX, int mouseY) { if (clickingLeft) { float diffX = Math.Abs(mouseClickX - mouseX); float diffY = Math.Abs(mouseClickY - mouseY); if (diffX + diffY > 5 && !rectangleSelecting) { rectangleSelecting = true; selectionLineA.Visible = true; selectionLineB.Visible = true; selectionLineC.Visible = true; selectionLineD.Visible = true; } if (rectangleSelecting) { float clickXRel = ((float)mouseClickX / Program.GLControl.ClientSize.Width); clickXRel = (clickXRel - 0.5f) * 2; float clickYRel = ((float)mouseClickY / Program.GLControl.ClientSize.Height); clickYRel = (clickYRel - 0.5f) * 2; float mouseXRel = ((float)mouseX / Program.GLControl.ClientSize.Width); mouseXRel = (mouseXRel - 0.5f) * 2; float mouseYRel = ((float)mouseY / Program.GLControl.ClientSize.Height); mouseYRel = (mouseYRel - 0.5f) * 2; selectionLineA.Start = new Vector2(clickXRel, clickYRel); selectionLineA.End = new Vector2(mouseXRel, clickYRel); selectionLineB.Start = new Vector2(mouseXRel, clickYRel); selectionLineB.End = new Vector2(mouseXRel, mouseYRel); selectionLineC.Start = new Vector2(mouseXRel, mouseYRel); selectionLineC.End = new Vector2(clickXRel, mouseYRel); selectionLineD.Start = new Vector2(clickXRel, mouseYRel); selectionLineD.End = new Vector2(clickXRel, clickYRel); Renderer.Update2DMeshData(); Renderer.Invalidate(); } } }
public void glControl_Load(object sender, EventArgs e) { Log.WriteLine("Initializing..."); Texture.Init(); Importer.Init(); Renderer.Init(); HWData.ParseDataPaths(); Background.LoadBackgroundFades(); Creation.Init(); Selection.Init(); LuaMap.SetupInterpreter(); Application.Idle += glControl_Update; Program.DeltaCounter.Start(); FPSCounter.LabelFPS = labelFPS; Loaded = true; gridProblems.RowTemplate.DefaultCellStyle.WrapMode = DataGridViewTriState.True; gridProblems.DefaultCellStyle.WrapMode = DataGridViewTriState.True; gridProblems.Columns[0].DefaultCellStyle.WrapMode = DataGridViewTriState.True; this.WindowState = Settings.LastWindowState; this.Location = Settings.LastWindowLocation; this.Size = Settings.LastWindowSize; Map.Clear(); Program.Camera.ResetCamera(); if (Updater.CheckForUpdatesOnStart) { Updater.CheckForUpdates(); } Program.main.UpdateProblems(); Renderer.InvalidateMeshData(); Renderer.InvalidateView(); Renderer.Invalidate(); }
private static void comboGizmoMode_SelectedIndexChanged(object sender, EventArgs e) { if (ignoreGizmoModeChange) { return; } if (Program.main.comboGizmoMode.SelectedIndex == 0) //Translation { GizmoMode = GizmoMode.TRANSLATION; Renderer.InvalidateView(); Renderer.Invalidate(); } else if (Program.main.comboGizmoMode.SelectedIndex == 1) //Rotation { GizmoMode = GizmoMode.ROTATION; Renderer.InvalidateView(); Renderer.Invalidate(); } }
private void comboFogType_SelectedIndexChanged(object sender, EventArgs e) { string type = "linear"; switch (comboFogType.SelectedIndex) { case 0: type = "linear"; break; case 1: type = "exp"; break; case 2: type = "exp2"; break; } Map.FogType = type; Renderer.Invalidate(); }
public void ResetCamera() { Angles.X = (float)Math.PI / 2 + (float)Math.PI * 0.75f; Angles.Y = (float)Math.PI; LookAt = Vector3.Zero; System.Drawing.Point position = Cursor.Position; lastPos = position; this.Orthographic = false; this.Zoom = CalculatedZoom; this.perspectiveZoom = this.Zoom; this.orthographicSize = 0.009f; UpdatePosition(); Renderer.InvalidateView(); Renderer.Invalidate(); Program.main.UpdatePerspectiveOrthoCombo(); }
public static void KeyDown() { if (ActionKey.IsDown(Action.MODE_TRANSLATION)) { GizmoMode = GizmoMode.TRANSLATION; Renderer.InvalidateView(); Renderer.Invalidate(); } else if (ActionKey.IsDown(Action.MODE_ROTATION)) { bool allowRotation = true; foreach (ISelectable selectable in Selected) { if (!selectable.AllowRotation) { allowRotation = false; break; } } if (allowRotation) //Don't allow rotation changes if the object cannot be rotated { GizmoMode = GizmoMode.ROTATION; Renderer.InvalidateView(); Renderer.Invalidate(); } else { SystemSounds.Beep.Play(); } } if (ActionKey.IsDown(Action.CAM_FOCUS_SELECTION)) { if (Selected.Count > 0) { Program.Camera.LookAt = AveragePosition; Renderer.InvalidateView(); Renderer.Invalidate(); } else { SystemSounds.Beep.Play(); } } if (ActionKey.IsDown(Action.SELECTION_DELETE)) { if (Selected.Count > 0) { new ActionDelete(Selected.ToArray()); } else { SystemSounds.Beep.Play(); } } if (ActionKey.IsDown(Action.SELECTION_COPY)) { Copied = Selected.ToList(); } else if (ActionKey.IsDown(Action.SELECTION_PASTE)) { Selected.Clear(); foreach (IElement obj in Copied) { Selected.Add((IElement)obj.Copy()); } } }
public static void UpdateDragging(int mouseX, int mouseY) { if (draggingState != DraggingState.NONE) { float mouseXDelta = mouseX - lastMouseX; float mouseYDelta = mouseY - lastMouseY; float cameraDistanceApprox = (Program.Camera.Position - AveragePosition).LengthFast; float posX = AveragePosition.X; float posY = AveragePosition.Y; float posZ = AveragePosition.Z; //float rotX = selectedDrawable.Rotation.X; //float rotY = selectedDrawable.Rotation.Y; //float rotZ = selectedDrawable.Rotation.Z; float rotX = 0; float rotY = 0; float rotZ = 0; float speedMultiplier = 1; if (!Program.Camera.Orthographic) { speedMultiplier = cameraDistanceApprox / 800; } else { speedMultiplier = 1 / Program.Camera.OrthographicSize; //The orthographic size gets smaller the more you zoom out, so the speed should raise the lower the size gets } switch (draggingState) { //Position case DraggingState.MOVING_X: if (Program.Camera.Position.Z > AveragePosition.Z) //To fix the user experience { posX = AveragePosition.X + mouseXDelta * speedMultiplier; } else { posX = AveragePosition.X - mouseXDelta * speedMultiplier; } break; case DraggingState.MOVING_Y: posY = AveragePosition.Y + mouseYDelta * speedMultiplier; break; case DraggingState.MOVING_Z: if (Program.Camera.Position.X > AveragePosition.X) //To fix the user experience { posZ = AveragePosition.Z - mouseXDelta * speedMultiplier; } else { posZ = AveragePosition.Z + mouseXDelta * speedMultiplier; } break; //Rotation case DraggingState.ROTATING_X: if (Program.Camera.Position.X > AveragePosition.X) //To fix the user experience //rotX = selectedDrawable.Rotation.X - mouseXDelta; { rotX = -mouseXDelta; } else { //rotX = selectedDrawable.Rotation.X + mouseXDelta; rotX = mouseXDelta; } break; case DraggingState.ROTATING_Y: //rotY = selectedDrawable.Rotation.Y + mouseXDelta; rotY = mouseXDelta; break; case DraggingState.ROTATING_Z: if (Program.Camera.Position.Z > AveragePosition.Z) //To fix the user experience //rotZ = selectedDrawable.Rotation.Z - mouseXDelta; { rotZ = -mouseXDelta; } else { //rotZ = selectedDrawable.Rotation.Z + mouseXDelta; rotZ = -mouseXDelta; } break; } Vector3 deltaPos = new Vector3(posX, posY, posZ); Vector3 deltaRot = new Vector3(rotX, rotY, rotZ); foreach (ISelectable selectable in Selected) { selectable.Position -= AveragePosition - deltaPos; selectable.Rotation += deltaRot; } AveragePosition = deltaPos; gizmoRotX.Rotation += deltaRot; gizmoRotY.Rotation += deltaRot; gizmoRotZ.Rotation += deltaRot; UpdateSelectionGizmos(); UpdateSelectionGizmoScale(); Renderer.InvalidateView(); Renderer.Invalidate(); } lastMouseX = mouseX; lastMouseY = mouseY; }
private void checkFogDisplay_CheckedChanged(object sender, EventArgs e) { Renderer.DisplayFog = checkFogDisplay.Checked; Renderer.Invalidate(); }
public static void LeftMouseUp(int x, int y) { if (Creation.CreatedElement != null) { return; //Don't select when the user is creating an object } if (draggingState == DraggingState.NONE) { if (rectangleSelecting) //Rectangle selection { selectionLineA.Visible = false; selectionLineB.Visible = false; selectionLineC.Visible = false; selectionLineD.Visible = false; int startX = Math.Min(mouseClickX, x); int startY = Math.Min(mouseClickY, y); int width = Math.Abs(mouseClickX - x); int height = Math.Abs(mouseClickY - y); List <ISelectable> objects = GetObjectsInRectangle(startX, startY, width, height); if (objects.Count > 0) { if (!ActionKey.IsDown(Action.SELECTION_ADD) && !ActionKey.IsDown(Action.SELECTION_REMOVE)) //Clear previous selection if the user does not want to add to selection { Selected.Clear(); } foreach (ISelectable obj in objects) { if (obj is IElement) { if (!ActionKey.IsDown(Action.SELECTION_REMOVE)) { if (!Selected.Contains(obj)) { Selected.Add((IElement)obj); } } else { if (Selected.Contains(obj)) { Selected.Remove((IElement)obj); } } } } } } else //Single selection { ISelectable objectAtMouse = GetObjectAtPixel(x, y); if (objectAtMouse != null) { if (objectAtMouse is IElement) { if (ActionKey.IsDown(Action.SELECTION_ADD)) { if (!Selected.Contains(objectAtMouse)) { Selected.Add((IElement)objectAtMouse); } else if (ActionKey.IsDown(Action.SELECTION_REMOVE)) { if (Selected.Contains((IElement)objectAtMouse)) { Selected.Remove((IElement)objectAtMouse); } } } else { TimeSpan timeSinceLastClick = DateTime.Now.Subtract(lastSingleSelectTime); if (timeSinceLastClick.Milliseconds > 200) { if (!ActionKey.IsDown(Action.SELECTION_REMOVE)) { Selected.Clear(); Selected.Add((IElement)objectAtMouse); } else if (Selected.Contains((IElement)objectAtMouse)) { Selected.Remove((IElement)objectAtMouse); } } else { if (Selected.Count == 1) { if (Selected[0] == objectAtMouse) { foreach (Drawable drawable in Drawable.Drawables) { if (!(drawable is IElement selectable)) { continue; } if (selectable.GetType() == Selected[0].GetType()) { if (selectable != Selected[0]) { if (!ActionKey.IsDown(Action.SELECTION_REMOVE)) { Selected.Add(selectable); } else if (Selected.Contains(selectable)) { Selected.Remove(selectable); } } } } } } } } lastSingleSelectTime = DateTime.Now; } } else if (!ActionKey.IsDown(Action.SELECTION_ADD) && !ActionKey.IsDown(Action.SELECTION_REMOVE)) { Selected.Clear(); } } rectangleSelecting = false; } else if (draggingState == DraggingState.MOVING_X || draggingState == DraggingState.MOVING_Y || draggingState == DraggingState.MOVING_Z) { new ActionMove(Selected.ToArray(), Vector3.Subtract(AveragePosition, positionAtStart)); Program.main.propertySelection.Refresh(); } else if (draggingState == DraggingState.ROTATING_X || draggingState == DraggingState.ROTATING_Y || draggingState == DraggingState.ROTATING_Z) { new ActionRotate(Selected.ToArray(), Vector3.Subtract(Selected[0].Rotation, rotationAtStart)); Program.main.propertySelection.Refresh(); } draggingState = DraggingState.NONE; gizmoLineX.Visible = false; gizmoLineY.Visible = false; gizmoLineZ.Visible = false; gizmoRotX.Rotation = Vector3.Zero; gizmoRotY.Rotation = Vector3.Zero; gizmoRotZ.Rotation = Vector3.Zero; clickingLeft = false; Renderer.InvalidateView(); Renderer.Invalidate(); }
private void numericFogEnd_ValueChanged(object sender, EventArgs e) { Map.FogEnd = (float)numericFogEnd.Value; Renderer.Invalidate(); }
public void Update(bool forceUpdate = false) { if (Program.GLControl == null) { return; } MouseState mouse = Mouse.GetState(); System.Drawing.Point position = Cursor.Position; if (Program.GLControl.Focused && Program.main.FormActive) { float zoomDelta = mouse.WheelPrecise - lastWheelPrecise; if (mouse.RightButton == OpenTK.Input.ButtonState.Pressed || forceUpdate) { float deltaX = position.X - lastPos.X; float deltaY = position.Y - lastPos.Y; Angles.X += deltaY * 0.01f; Angles.Y -= deltaX * 0.01f; Angles.X = (float)Utilities.Clamp(Angles.X, Math.PI / 2, Math.PI * 1.5f - 0.01f); if (Angles.Y > Math.PI * 2) { Angles.Y = 0; } if (Angles.Y < 0) { Angles.Y = (float)Math.PI * 2; } Renderer.InvalidateView(); Renderer.Invalidate(); } if (!this.Orthographic) { zoom -= zoomDelta * ZoomSpeed * (zoom / 3000000); zoom = Utilities.Clamp(zoom, MinZoom, MaxZoom); } else { orthographicSize += zoomDelta * (orthographicSize / 25); orthographicSize = Utilities.Clamp(orthographicSize, 0.01f, 1); } UpdatePosition(); } if (lastZoom != zoom) { Renderer.InvalidateView(); Renderer.Invalidate(); } if (lastOrthographicSize != orthographicSize) { Renderer.InvalidateView(); Renderer.Invalidate(); } lastPos = position; lastZoom = zoom; lastOrthographicSize = orthographicSize; lastWheelPrecise = mouse.WheelPrecise; }
public void KeyDown() { if (ActionKey.IsDown(Action.TOGGLE_ORTHOGRAPHIC)) //Toggle orthographic view { this.Orthographic = !this.Orthographic; if (this.Orthographic) { this.perspectiveZoom = this.Zoom; this.Zoom = CalculatedZoom; } else { this.Zoom = perspectiveZoom; } Program.main.UpdatePerspectiveOrthoCombo(); Renderer.InvalidateView(); Renderer.Invalidate(); } else if (ActionKey.IsDown(Action.VIEW_FRONT)) { Angles.X = (float)Math.PI; Angles.Y = (float)Math.PI; UpdatePosition(); Renderer.InvalidateView(); Renderer.Invalidate(); } else if (ActionKey.IsDown(Action.VIEW_BACK)) { Angles.X = (float)Math.PI; Angles.Y = 0; UpdatePosition(); Renderer.InvalidateView(); Renderer.Invalidate(); } else if (ActionKey.IsDown(Action.VIEW_LEFT)) { Angles.X = (float)Math.PI; Angles.Y = (float)Math.PI * 1.5f; UpdatePosition(); Renderer.InvalidateView(); Renderer.Invalidate(); } else if (ActionKey.IsDown(Action.VIEW_RIGHT)) { Angles.X = (float)Math.PI; Angles.Y = (float)Math.PI / 2; UpdatePosition(); Renderer.InvalidateView(); Renderer.Invalidate(); } else if (ActionKey.IsDown(Action.VIEW_TOP)) { Angles.X = (float)Math.PI * 1.5f; Angles.Y = (float)Math.PI; Angles.X = (float)Utilities.Clamp(Angles.X, Math.PI / 2, Math.PI * 1.5f - 0.01f); UpdatePosition(); Renderer.InvalidateView(); Renderer.Invalidate(); } else if (ActionKey.IsDown(Action.VIEW_BOTTOM)) { Angles.X = 0; Angles.Y = (float)Math.PI; Angles.X = (float)Utilities.Clamp(Angles.X, Math.PI / 2, Math.PI * 1.5f - 0.01f); UpdatePosition(); Renderer.InvalidateView(); Renderer.Invalidate(); } else if (ActionKey.IsDown(Action.CAM_RESET)) { ResetCamera(); } }