コード例 #1
0
        /// <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
            });
        }
コード例 #2
0
ファイル: HelixView3D.cs プロジェクト: msruzy/hydronumerics
 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));
 }
コード例 #3
0
ファイル: HelixView3D.cs プロジェクト: msruzy/hydronumerics
 public Point3D?FindNearestPoint(Point pt)
 {
     return(Viewport3DHelper.FindNearestPoint(Viewport, pt));
 }
コード例 #4
0
ファイル: HelixView3D.cs プロジェクト: msruzy/hydronumerics
 public Visual3D FindNearestVisual(Point pt)
 {
     return(Viewport3DHelper.FindNearestVisual(Viewport, pt));
 }
コード例 #5
0
ファイル: HelixView3D.cs プロジェクト: msruzy/hydronumerics
 public void Copy()
 {
     Viewport3DHelper.Copy(Viewport, Viewport.ActualWidth * 2, Viewport.ActualHeight * 2, Brushes.White);
 }
コード例 #6
0
ファイル: HelixView3D.cs プロジェクト: msruzy/hydronumerics
 public void Export(string fileName)
 {
     Viewport3DHelper.Export(Viewport, fileName);
 }
コード例 #7
0
        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;
        }
コード例 #8
0
 /// <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));
 }