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(); } }
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_LostFocus(object sender, EventArgs e) { ActionKey.LostFocus(); }
public void glControl_KeyUp(object sender, KeyEventArgs e) { ActionKey.KeyUp(e); }
public void glControl_MouseLeave(object sender, EventArgs e) { //this.Focus(); ActionKey.LostFocus(); }