/// <summary> /// Get the ray into the view volume given by the position in 2D (screen coordinates) /// </summary> /// <param name="position"></param> /// <returns></returns> public Ray3D GetRay(Point position) { Point3D point1, point2; bool ok = Viewport3DHelper.Point2DtoPoint3D(Viewport, position, out point1, out point2); if (!ok) { return(null); } return(new Ray3D { Origin = point1, Direction = point2 - point1 }); }
public bool FindNearest(Point pt, out Point3D pos, out Vector3D normal, out DependencyObject obj) { return(Viewport3DHelper.FindNearest(Viewport, pt, out pos, out normal, out obj)); }
public Point3D?FindNearestPoint(Point pt) { return(Viewport3DHelper.FindNearestPoint(Viewport, pt)); }
public Visual3D FindNearestVisual(Point pt) { return(Viewport3DHelper.FindNearestVisual(Viewport, pt)); }
public void Copy() { Viewport3DHelper.Copy(Viewport, Viewport.ActualWidth * 2, Viewport.ActualHeight * 2, Brushes.White); }
public void Export(string fileName) { Viewport3DHelper.Export(Viewport, fileName); }
private void MouseDownHandler(object sender, MouseButtonEventArgs e) { if (!Enabled) { return; } if (Viewport == null) { throw new NullReferenceException("Viewport"); } var element = (UIElement)sender; if (element.IsMouseCaptured) { return; } mouseDownPosition = e.GetPosition(this); fixRelative = new Vector3D(); // reset camera if (CheckButton(e, MouseAction.ResetCamera)) { ResetCamera(); } Point3D point; Vector3D normal; DependencyObject visual; if (Viewport3DHelper.FindNearest(Viewport, mouseDownPosition, out point, out normal, out visual)) { mouseDownPoint3D = point; } else { mouseDownPoint3D = null; } lastPoint3D = UnProject(mouseDownPosition, CameraTarget, LookDirection); // select object if (CheckButton(e, MouseAction.Select) && visual != null) { OnSelectionChanged(visual); } zooming = CheckButton(e, MouseAction.Zoom); panning = CheckButton(e, MouseAction.Pan); rotating = CheckButton(e, MouseAction.Rotate); isFixed = false; // change the 'lookat' point if (mouseDownPoint3D != null && CheckButton(e, MouseAction.ChangeLookAt)) { LookAt(mouseDownPoint3D.Value, 0); rotating = true; } if (zooming || panning || rotating) { bool rightWinKey = (Keyboard.IsKeyDown(Key.RWin)); if (FixedMouseDownPoint || rightWinKey) { if (!panning && mouseDownPoint3D != null) { fixRelative = mouseDownPoint3D.Value - CameraTarget; ShowTargetAdorner(mouseDownPosition); isFixed = true; } } else { // show the adorner in the middle ShowTargetAdorner(new Point(Viewport.ActualWidth / 2, Viewport.ActualHeight / 2)); } /* * Position += _fixRelative; * ShowTargetModel(); * Position -= _fixRelative; */ if (zooming || panning || rotating) { e.Handled = true; element.CaptureMouse(); } spinWatch.Reset(); spinWatch.Start(); // ProjectToTrackball(EventSurface.ActualWidth, EventSurface.ActualHeight, _mouseDownPosition); lastPosition = mouseDownPosition; } isSpinning = false; }
/// <summary> /// Calculate the screen position of a 3D point /// </summary> /// <param name="p"></param> /// <returns></returns> public Point Project(Point3D p) { return(Viewport3DHelper.Point3DtoPoint2D(Viewport, p)); }