예제 #1
0
        public Point3D To3DPoint(Vector point)
        {
            LineRange r = new LineRange();

            ViewportInfo.Point2DtoPoint3D(viewPort, point.ToPoint(), out r);

            return(r.PointFromZ(-100));
        }
예제 #2
0
        /* This MouseDown event handler prints:
         * (1) the current position of the mouse
         * (2) the 3D mouse location on the ground plane (z = 0)
         * (3) the 2D mouse location converted from the 3D location */
        private void Window_MouseDown(object sender, MouseEventArgs e)
        {
            var range   = new LineRange();
            var isValid = ViewportInfo.Point2DtoPoint3D(Viewport, e.GetPosition(Viewport), out range);

            if (!isValid)
            {
                MouseLabel.Content = "(no data)";
            }
            else
            {
                var point3D = range.PointFromZ(0);
                var point   = ViewportInfo.Point3DtoPoint2D(Viewport, point3D);
                MouseLabel.Content = e.GetPosition(Viewport) + "\n" + point3D + "\n" + point;
            }
        }
예제 #3
0
        private MousePosInfo3D GetPosition3D(Point pos2d)
        {
            LineRange lineRange;

            if (ViewportInfo.Point2DtoPoint3D(viewport3d, pos2d, out lineRange))
            {
                return new MousePosInfo3D {
                           Pos2D = pos2d, Ray3D = lineRange
                }
            }
            ;
            else
            {
                return new MousePosInfo3D {
                           Pos2D = pos2d, Ray3D = null
                }
            };
        }
예제 #4
0
        // Mouse moves occur in the Z=0 plane.
        protected override void OnMouseMove(MouseEventArgs args)
        {
            base.OnMouseMove(args);

            if (!isTracking)
            {
                return;
            }

            // Get the mouse position and adjust the translate transform.
            Point     ptMouse = args.GetPosition(viewport);
            LineRange range;

            ViewportInfo.Point2DtoPoint3D(viewport, ptMouse, out range);
            Point3D pointNew = range.PointFromZ(transTracking.OffsetZ);

            AdjustTranslateTransform(pointNew);
        }
예제 #5
0
        // Left mouse button click initiates tracking operation.
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs args)
        {
            base.OnMouseLeftButtonDown(args);

            Point         ptMouse = args.GetPosition(viewport);
            HitTestResult result  = VisualTreeHelper.HitTest(viewport, ptMouse);

            // We're only interested in 3D hits.
            RayMeshGeometry3DHitTestResult result3d =
                result as RayMeshGeometry3DHitTestResult;

            if (result3d == null)
            {
                return;
            }

            // We're only interested in ModelVisual3D hits.
            ModelVisual3D vis3d = result3d.VisualHit as ModelVisual3D;

            if (vis3d == null)
            {
                return;
            }

            // We're only interested in visuals with translate transforms.
            transTracking = vis3d.Transform as TranslateTransform3D;
            if (transTracking == null)
            {
                return;
            }

            LineRange range;

            ViewportInfo.Point2DtoPoint3D(viewport, ptMouse, out range);
            pointOriginal = range.PointFromZ(transTracking.OffsetZ);
            transOriginal = transTracking.Clone();
            isTracking    = true;
            CaptureMouse();
            Focus();

            args.Handled = true;
        }