Ejemplo n.º 1
0
        void _CheckMouseInModel(object sender, MouseEventArgs e)
        {
            // don't bother checking the mouse position if we are dragging
            if (e.LeftButton == MouseButtonState.Pressed || e.RightButton == MouseButtonState.Pressed)
            {
                return;
            }

            // see if the the mouse is over a cube
            // N.B we are looking at the border as it is superimposed over the viewPort
            Cube             foundCube = null;
            SearchResult     correspondingSearchResult = null;
            HitTestResult    result    = VisualTreeHelper.HitTest(viewPort, e.GetPosition(viewPort));
            RayHitTestResult rayResult = result as RayHitTestResult;

            if (rayResult != null)
            {
                RayMeshGeometry3DHitTestResult rayMeshResult = rayResult as RayMeshGeometry3DHitTestResult;
                if (rayMeshResult != null)
                {
                    GeometryModel3D model = rayMeshResult.ModelHit as GeometryModel3D;
                    for (int i = 0, len = _cube.Length; i < len; i++)
                    {
                        var item = _cube[i];
                        if (item.Content == model)
                        {
                            foundCube = item;
                            correspondingSearchResult = _searchResult[i];
                            break;
                        }
                    }
                }
            }

            // update the selection as appropriate
            if (foundCube != _currentHilightedCube)
            {
                if (_currentHilightedCube != null)
                {
                    _currentHilightedCube.Reset();
                }
                if (foundCube != null)
                {
                    correspondingSearchResult.BringIntoView();

                    SolidColorBrush brush     = new SolidColorBrush(Colors.Red);
                    ColorAnimation  animation = new ColorAnimation(Colors.Red, Color.FromRgb(0xff, 0xff, 0xff), new Duration(TimeSpan.FromMilliseconds(750)));
                    brush.BeginAnimation(SolidColorBrush.ColorProperty, animation);
                    correspondingSearchResult.Background = brush;
                    foundCube.Ping();
                }
                _currentHilightedCube = foundCube;
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Performs hit testing for this residue.
 /// </summary>
 /// <param name="rayHitTestResult">A 3D mesh hit test result from the WPF visual tree hit
 /// testing framework</param>
 /// <returns>True if the mesh hit belongs to this residue, otherwise false.</returns>
 internal virtual bool HoverHitTest(RayMeshGeometry3DHitTestResult rayHitTestResult)
 {
     if (this.cartoon != null)
     {
         return(this.cartoon.HoverHitTest(rayHitTestResult));
     }
     else
     {
         return(false);
     }
 }
        /// <summary>
        /// 采用命中测试得到三维场景中选中的商品
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void viewport3D_MouseLeftButtonDown(object sender, MouseButtonEventArgs args)
        {
            Point mousePosition = args.GetPosition(viewport3D);
            PointHitTestParameters pointparams = new PointHitTestParameters(mousePosition);

            //测试 Viewport3D 中的结果
            VisualTreeHelper.HitTest(viewport3D, null, rawresult =>
            {
                RayHitTestResult rayResult = rawresult as RayHitTestResult;
                if (rayResult != null)
                {
                    RayMeshGeometry3DHitTestResult rayMeshResult = rayResult as RayMeshGeometry3DHitTestResult;
                    if (rayMeshResult != null)
                    {
                        GeometryModel3D hitgeo         = rayMeshResult.ModelHit as GeometryModel3D;
                        MaterialGroup priorMaterial    = hitgeo.Material as MaterialGroup;
                        DiffuseMaterial difuseMaterial = priorMaterial.Children[0] as DiffuseMaterial;
                        if (difuseMaterial != null && difuseMaterial.Brush is ImageBrush)
                        {
                            ImageBrush imgBrush = difuseMaterial.Brush as ImageBrush;
                            try
                            {
                                string imagesource = imgBrush.ImageSource.ToString();
                                string imageName   = System.IO.Path.GetFileName(imagesource);
                                int selIndex       = 0;
                                for (int i = 0; i < Global.ProductDemoImages.Count; i++)
                                {
                                    if (System.IO.Path.GetFileName(Global.ProductDemoImages[i]) == imageName)
                                    {
                                        selIndex = i;
                                    }
                                }
                                ProductBiz selPruduct = HomeProductDic[selIndex];
                                if (selPruduct != null)
                                {
                                    Grid.SetRowSpan(Global.MainFrame, 1);
                                    if (Global.UserInterface == UserInterface.FittingRoom)
                                    {
                                        Global.MainFrame.Navigate(new Uri("/Views/ProductTryingOnControl.xaml", UriKind.Relative), selPruduct);
                                    }
                                    else
                                    {
                                        Global.MainFrame.Navigate(new Uri("/Views/ProductDetailControl.xaml", UriKind.Relative), selPruduct);
                                    }
                                    Global.MainFrame.Navigated += MainFrame_Navigated;
                                }
                            }
                            catch { }
                        }
                    }
                }
                return(HitTestResultBehavior.Stop);
            }, pointparams);
        }
Ejemplo n.º 4
0
        public HitTestResultBehavior MyHitTestResult(HitTestResult result)
        {
            if (result != null && result.GetType() == typeof(RayMeshGeometry3DHitTestResult))
            {
                RayMeshGeometry3DHitTestResult res = (RayMeshGeometry3DHitTestResult)result;

                _hitTestResultList.Add(res);
            }
            // Set the behavior to return visuals at all z-order levels.
            return(HitTestResultBehavior.Continue);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the nearest 3D point of the model underneath the specified 2D point.
        /// </summary>
        /// <param name="pt">The 2D point in viewport space.</param>
        /// <returns>The 3D point in model space.</returns>
        public Point3D GetHitPoint(Point pt)
        {
            RayMeshGeometry3DHitTestResult htr = Math3D.HitTest(this, pt);

            if (htr == null)
            {
                return(new Point3D(double.NaN, 0, 0));
            }

            return(htr.PointHit);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets the normal for a hit test result.
        /// </summary>
        /// <param name="rayHit">
        /// The ray hit.
        /// </param>
        /// <returns>
        /// The normal.
        /// </returns>
        private static Vector3D?GetNormalHit(RayMeshGeometry3DHitTestResult rayHit)
        {
            if ((rayHit.MeshHit.Normals == null) || (rayHit.MeshHit.Normals.Count < 1))
            {
                return(null);
            }

            return((rayHit.MeshHit.Normals[rayHit.VertexIndex1] * rayHit.VertexWeight1)
                   + (rayHit.MeshHit.Normals[rayHit.VertexIndex2] * rayHit.VertexWeight2)
                   + (rayHit.MeshHit.Normals[rayHit.VertexIndex3] * rayHit.VertexWeight3));
        }
Ejemplo n.º 7
0
        public HitTestResultBehavior resultCallback(HitTestResult result)
        {
            rayResult = result as RayHitTestResult;
            if (rayResult != null)
            {
                // Did we hit a MeshGeometry3D?
                RayMeshGeometry3DHitTestResult rayMeshResult =
                    rayResult as RayMeshGeometry3DHitTestResult;
            }

            return(HitTestResultBehavior.Stop);
        }
Ejemplo n.º 8
0
 //<SnippetHitTest3D3DN7>
 public void UpdateResultInfo(RayMeshGeometry3DHitTestResult rayMeshResult)
 {
     HitVisualInfo.Text = rayMeshResult.VisualHit.ToString();
     HitModelInfo.Text  = rayMeshResult.ModelHit.ToString();
     HitMeshInfo.Text   = rayMeshResult.MeshHit.ToString();
     //HitMaterialInfo.Text = (rayMeshResult.ModelHit as GeometryModel3D).Material.GetType().Name;
     //HitMaterialBrushInfo.Text = ((rayMeshResult.ModelHit as GeometryModel3D).Material as DiffuseMaterial).Brush.ToString();
     HitDistanceInfo.Text = rayMeshResult.DistanceToRayOrigin.ToString();
     Vertex1Info.Text     = (rayMeshResult.VertexWeight1 * 100) + "%";
     Vertex2Info.Text     = (rayMeshResult.VertexWeight2 * 100) + "%";
     Vertex3Info.Text     = (rayMeshResult.VertexWeight3 * 100) + "%";
 }
Ejemplo n.º 9
0
        private HitTestResultBehavior Viewport_HitTestResult(HitTestResult result)
        {
            RayMeshGeometry3DHitTestResult rayHTResult = result as RayMeshGeometry3DHitTestResult;

            if (rayHTResult != null)
            {
                _hitModel = rayHTResult.ModelHit as GeometryModel3D;
                return(HitTestResultBehavior.Stop);
            }

            return(HitTestResultBehavior.Continue);
        }
Ejemplo n.º 10
0
        public HitTestResultBehavior ResultCallback_DoubleClick(HitTestResult result)//双击货架展示某一排货物  可以旋转 展示
        {
            try
            {
                var tempModel = result.VisualHit as ModelVisual3D;
                if (tempModel != null)
                {
                }
                RayHitTestResult rayHitTest = result as RayHitTestResult;
                if (rayHitTest != null)
                {
                    RayMeshGeometry3DHitTestResult rayMeshGeometry3DHitTestResult = rayHitTest as RayMeshGeometry3DHitTestResult;
                    if (rayMeshGeometry3DHitTestResult != null)
                    {
                        foreach (var temp in shelf_Info.Values)
                        {
                            if (temp.Model.Content == rayMeshGeometry3DHitTestResult.ModelHit)
                            {
                                selected_shelfInfo.Clear();
                                selected_productInfo.Clear();
                                string[] strs = temp.ModelName.Split('_');
                                string   selectedShelfLineNo = strs[1];
                                foreach (var shelfInfo in shelf_Info.Keys)
                                {
                                    strs = shelfInfo.Split('_');
                                    if (strs[1].Equals(selectedShelfLineNo))
                                    {
                                        selected_shelfInfo.Add(shelfInfo, shelf_Info[shelfInfo]);
                                    }
                                }
                                foreach (var productInfo in product_Info.Keys)
                                {
                                    strs = productInfo.Split('.');
                                    if (strs[0].Equals(selectedShelfLineNo.PadLeft(2, '0')))
                                    {
                                        selected_productInfo.Add(productInfo, (ProductInfo)product_Info[productInfo]);
                                    }
                                }
                                SetNotSelectedAppearance(pervSelectedShelfNo);
                                ShowShelf(selected_shelfInfo, selected_productInfo);
                                return(HitTestResultBehavior.Stop);;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                HintEvent(string.Format("ResultCallback" + ex.ToString()));
            }

            return(HitTestResultBehavior.Continue);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 命中的模型移动动画
        /// </summary>
        /// <param name="axisname"></param>
        /// <param name="rayresultname"></param>
        public void AxisRatationEvent(AxisAngleRotation3D axisname,
                                      RayMeshGeometry3DHitTestResult rayresultname, Vector3D vec)
        {
            ///axisname.Axis = new Vector3D(rayresultname.PointHit.X, -rayresultname.PointHit.Y, rayresultname.PointHit.Z);
            axisname.Axis = vec;
            DoubleAnimation animation = new DoubleAnimation();

            animation.To = 20;
            animation.DecelerationRatio = 1;
            animation.Duration          = TimeSpan.FromSeconds(0.15);
            animation.AutoReverse       = true;
            axisname.BeginAnimation(AxisAngleRotation3D.AngleProperty, animation);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// On mouse click, select the specific board
        /// where the click happened.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void OnViewportMouseDown(
            object sender,
            System.Windows.Input.MouseEventArgs args)
        {
            if (vstuff.models == null)
            {
                return;
            }

            if (
                Keyboard.IsKeyDown(Key.LeftCtrl) ||
                Keyboard.IsKeyDown(Key.RightCtrl)
                )
            {
                // extending the selection.
                // don't unselect all first.
            }
            else
            {
                UnselectAll();
            }

            RayMeshGeometry3DHitTestResult rayMeshResult =
                (RayMeshGeometry3DHitTestResult)
                VisualTreeHelper.HitTest(myVP, args.GetPosition(myVP));

            if (rayMeshResult != null)
            {
                PartialModel found = null;
                foreach (PartialModel pm in vstuff.models)
                {
                    if (pm.mesh == rayMeshResult.MeshHit)
                    {
                        found = pm;
                        break;
                    }
                }

                if (found != null)
                {
                    if (IsSelected(found.bag.solid))
                    {
                        Unselect(found.bag.solid);
                    }
                    else
                    {
                        Select(found.bag.solid);
                    }
                }
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Find the 3D model point beneath a 2D viewport point.
        /// </summary>
        Point3D GetTouchPoint(Point pt2D)
        {
            RayMeshGeometry3DHitTestResult htr = Math3D.HitTest(Viewport, pt2D);

            if (htr == null)
            {
                return(Math3D.Origin);
            }

            Point3D  pt3D = htr.PointHit;           //--- in model space
            Matrix3D m    = Math3D.GetTransformationMatrix(htr.VisualHit);

            pt3D = m.Transform(pt3D);            //--- in global space
            return(pt3D);
        }
Ejemplo n.º 14
0
        public HitTestResultBehavior ResultCallback(HitTestResult result)
        {
            RayHitTestResult rayResult = result as RayHitTestResult;

            if (rayResult != null)
            {
                RayMeshGeometry3DHitTestResult rayMeshResult = rayResult as RayMeshGeometry3DHitTestResult;

                if (rayMeshResult != null)
                {
                }
            }

            return(HitTestResultBehavior.Continue);
        }
Ejemplo n.º 15
0
        private void ViewPort3D_OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            // Perform the hit test on the mouse's position relative to the viewport.
            HitTestResult result = VisualTreeHelper.HitTest(viewPort3d, e.GetPosition(viewPort3d));
            RayMeshGeometry3DHitTestResult mesh_result = result as RayMeshGeometry3DHitTestResult;

            if (oldSelectedModel != null)
            {
                unselectModel();
            }

            if (mesh_result != null)
            {
                selectModel(mesh_result.ModelHit);
            }
        }
Ejemplo n.º 16
0
        private void port3d_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Viewport3D viewport = (Viewport3D)sender;
            Point      location = e.GetPosition(viewport);

            HitTestResult hitResult = VisualTreeHelper.HitTest(viewport, location);
            RayMeshGeometry3DHitTestResult meshHitResult = hitResult as RayMeshGeometry3DHitTestResult;

            if (meshHitResult != null)
            {
                Perspective.LookDirection = new Vector3D(meshHitResult.PointHit.X, meshHitResult.PointHit.Y, zdirection);
                x = meshHitResult.PointHit.X;
                y = meshHitResult.PointHit.Y;
                Perspective.Position = new Point3D(x, y, -distance);
            }
        }
Ejemplo n.º 17
0
        private HitTestResultBehavior HitTestResultHandler(HitTestResult hitResult)
        {
            _lastHitResult = hitResult as RayMeshGeometry3DHitTestResult;

            // Instead of filtering with HitTestFilterCallback
            // we could also filter here:
            // In case we hit a _glassPlaneVisual3D, then continue hit testing (get the next hit object)
            // This would be done with the following code
            //if (ReferenceEquals(hitResult.VisualHit, _glassPlaneVisual3D))
            //    return HitTestResultBehavior.Continue;

            // We can return Stop to stop hit testing,
            // or Continue to continue hit testing (get the next hit object).
            // This can be used to get all hit objects under the mouse (for example with adding hit objects to a List of hit objects).
            return(HitTestResultBehavior.Stop);
        }
        private Point GetUV(RayMeshGeometry3DHitTestResult result3D)
        {
            int limit = result3D.MeshHit.TextureCoordinates.Count;

            if (result3D.VertexIndex1 < limit &&
                result3D.VertexIndex2 < limit &&
                result3D.VertexIndex3 < limit)
            {
                return(Interpolate(result3D.VertexWeight1, result3D.VertexWeight2, result3D.VertexWeight3,
                                   result3D.MeshHit.TextureCoordinates[result3D.VertexIndex1],
                                   result3D.MeshHit.TextureCoordinates[result3D.VertexIndex2],
                                   result3D.MeshHit.TextureCoordinates[result3D.VertexIndex3]));
            }

            return(new Point(double.NaN, double.NaN));
        }
Ejemplo n.º 19
0
        private void Window_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.RightButton == MouseButtonState.Pressed)
            {
                // Returns the topmost Visual object of a hit test by specifying a Point.
                HitTestResult rayResult = VisualTreeHelper.HitTest(myViewport3D, e.GetPosition(myViewport3D));

                // Represents an intersection between a ray hit test and a MeshGeometry3D.
                RayMeshGeometry3DHitTestResult rayMeshResult = rayResult as RayMeshGeometry3DHitTestResult;

                if (rayMeshResult != null)
                {
                    // Add the group of models to the ModelVisual3d.
                    myModelVisual3D.Content = TerrainEditor.Scene.CreateModel(rayMeshResult.PointHit);
                }
            }
        }
Ejemplo n.º 20
0
        private void ringVisual_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Point location = e.GetPosition(viewport);

            RayMeshGeometry3DHitTestResult meshHitResult = (RayMeshGeometry3DHitTestResult)VisualTreeHelper.HitTest(viewport, location);

            axisRotation.Axis = new Vector3D(
                -meshHitResult.PointHit.Y, meshHitResult.PointHit.X, 0);

            DoubleAnimation animation = new DoubleAnimation();

            animation.To = 40;
            animation.DecelerationRatio = 1;
            animation.Duration          = TimeSpan.FromSeconds(0.15);
            animation.AutoReverse       = true;
            axisRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, animation);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Updates the cached mouse position as well as the visual 3D marker for the mouse.
        /// </summary>
        protected void UpdatePointer()
        {
            //Hit-test on the Viewport3D to determine what screen x,y coordinate is being pointed at.
            Point pt = Mouse.GetPosition(this);
            RayMeshGeometry3DHitTestResult result =
                VisualTreeHelper.HitTest(viewport, pt) as RayMeshGeometry3DHitTestResult;

            Point oldPosition = PointerPosition;

            //Move the spinney pointer.
            if (result != null)
            {
                if (object.ReferenceEquals(result.VisualHit, modelFloor))
                {
                    Point3D ptHit = result.PointHit;
                    PointerPosition           = new Point(ptHit.X, ptHit.Y);
                    translatorPointer.OffsetX = ptHit.X;
                    translatorPointer.OffsetY = ptHit.Y;
                    //PointerPosition = new Point(ptHit.X, ptHit.Y);
                }
                else if (result.VisualHit is Food3D)
                {
                    PointerPosition = new Point(((Food3D)result.VisualHit).Model.X,
                                                ((Food3D)result.VisualHit).Model.Y);
                }
                else if (result.VisualHit is Cube3D)
                {
                    PointerPosition = new Point(((Cube3D)result.VisualHit).Model.X,
                                                ((Cube3D)result.VisualHit).Model.Y);
                }
            }

            //Since the pointer is updated, send a request to move, but only if the socket has not
            //been disconnected.
            if (networkState != null && networkState.ConnectionState != NetworkState.ConnectionStates.DISCONNECTED)
            {
                // Send the move command
                // For some reason, the server requires the coordinates to be an int. This should not be a big deal.
                if ((int)oldPosition.X != (int)PointerPosition.X || (int)oldPosition.Y != (int)PointerPosition.Y)
                {
                    Network.Send(networkState.Socket, "(move, " + (int)PointerPosition.X + ", "
                                 + (int)PointerPosition.Y + ")\n");
                }
            }
        }
Ejemplo n.º 22
0
        private Point3D GetHitPoint3DOnMeshGeometry(RayMeshGeometry3DHitTestResult rayMeshResult, MeshGeometry3D hitmesh)
        {
            Point3D p1 = hitmesh.Positions.ElementAt(rayMeshResult.VertexIndex1);
            Point3D p2 = hitmesh.Positions.ElementAt(rayMeshResult.VertexIndex2);
            Point3D p3 = hitmesh.Positions.ElementAt(rayMeshResult.VertexIndex3);

            double weight1 = rayMeshResult.VertexWeight1;
            double weight2 = rayMeshResult.VertexWeight2;
            double weight3 = rayMeshResult.VertexWeight3;

            double x = p1.X * weight1 + p2.X * weight2 + p3.X * weight3;
            double y = p1.Y * weight1 + p2.Y * weight2 + p3.Y * weight3;
            double z = p1.Z * weight1 + p2.Z * weight2 + p3.Z * weight3;

            Point3D hitPoint3D = new Point3D(x, y, z);

            return(hitPoint3D);
        }
Ejemplo n.º 23
0
        private void grid_MouseUp(object sender, MouseButtonEventArgs e)
        {
            _controlStatus = "";
            _pcenter       = null;
            Cursor         = null;

            Point newPoint = e.GetPosition(mainViewport3D);

            if (showDetail != null && (newPoint - orgPoint).Length < 5)
            {
                HitTestResult result = VisualTreeHelper.HitTest(mainViewport3D, newPoint);
                if (result is RayMeshGeometry3DHitTestResult)
                {
                    RayMeshGeometry3DHitTestResult ray3DResult = (RayMeshGeometry3DHitTestResult)result;
                    showDetail(ray3DResult, newPoint);
                }
            }
        }
Ejemplo n.º 24
0
        //http://csharphelper.com/blog/2014/10/perform-hit-testing-in-a-3d-program-that-uses-wpf-xaml-and-c/
        private void MainViewport_MouseDown(object sender, MouseButtonEventArgs e)
        {
            // Get the mouse's position relative to the viewport.
            Point mouse_pos = e.GetPosition(MainViewport);

            // Perform the hit test.
            HitTestResult result = VisualTreeHelper.HitTest(MainViewport, mouse_pos);

            // Display information about the hit.
            RayMeshGeometry3DHitTestResult mesh_result = result as RayMeshGeometry3DHitTestResult;

            try
            {
                // Display the name of the model.
                this.PeekName.Content = markers[mesh_result.ModelHit];
            }
            catch { }
        }
Ejemplo n.º 25
0
        static HitTestResultBehavior HitTestResultCallback(HitTestResult result)
        {
            RayMeshGeometry3DHitTestResult htr = result as RayMeshGeometry3DHitTestResult;

            if (htr != null)
            {
                if (hitTestResult == null)
                {
                    hitTestResult = htr;
                }

                else if (htr.DistanceToRayOrigin < hitTestResult.DistanceToRayOrigin)
                {
                    hitTestResult = htr;
                }
            }
            return(HitTestResultBehavior.Continue);
        }
Ejemplo n.º 26
0
        // Animate leaf when user clicks a page.
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs args)
        {
            Point         pt     = args.GetPosition(this);
            HitTestResult result = VisualTreeHelper.HitTest(this, pt);

            if (result is RayMeshGeometry3DHitTestResult)
            {
                RayMeshGeometry3DHitTestResult result3d =
                    result as RayMeshGeometry3DHitTestResult;

                if (result3d.VisualHit is Billboard)
                {
                    // Get the clicked billboard and prepare for animations.
                    Billboard board          = result3d.VisualHit as Billboard;
                    int       indexBillboard = lstBillboards.IndexOf(board);
                    Billboard boardAnimate   = null;

                    // Clicked a recto: forward page turn (right to left).
                    if (indexBillboard >= leafView)
                    {
                        boardAnimate   = lstBillboards[leafView];
                        animaAngle.To  = -90;
                        animaRadius.To = (leafView + 1) * leafGap;
                        leafView++;
                    }
                    // Clicked a verso: back page turn (left to right).
                    else
                    {
                        boardAnimate   = lstBillboards[leafView - 1];
                        animaAngle.To  = 90;
                        animaRadius.To = (leafCount - leafView + 1) * leafGap;
                        leafView--;
                    }
                    // Start the animations.
                    PageTurner turn =
                        boardAnimate.AlgorithmicTransforms[0] as PageTurner;

                    turn.Random1 = rand.NextDouble() - 0.5;
                    turn.Random2 = rand.NextDouble() - 0.5;
                    turn.BeginAnimation(PageTurner.AngleProperty, animaAngle);
                    turn.BeginAnimation(PageTurner.RadiusProperty, animaRadius);
                }
            }
        }
Ejemplo n.º 27
0
        private void OnViewportMouseDown(object pSender, System.Windows.Input.MouseButtonEventArgs e)
        {
            System.Windows.Point pos = e.GetPosition(m_Viewport);
            var hitRes = VisualTreeHelper.HitTest(m_Viewport, pos);
            RayMeshGeometry3DHitTestResult rayMeshRes = hitRes as RayMeshGeometry3DHitTestResult;

            if (rayMeshRes != null)
            {
                OnViewDown(rayMeshRes.VisualHit, new Vector2(rayMeshRes.PointHit.X, rayMeshRes.PointHit.Y), e.ChangedButton);
            }


            if (m_Mode == Mode.Calibration)
            {
                m_LastHoveredPos = pos;
                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    m_MouseMovesCamera = true;
                }
                else if (e.RightButton == MouseButtonState.Pressed)
                {
                    m_MouseMovesCameraAngle = true;
                }
                else if (e.MiddleButton == MouseButtonState.Pressed)
                {
                    m_MouseMovesCameraFOV = true;
                }
            }
            else
            {
                if (hitRes != null)
                {
                    if (hitRes.VisualHit is SceneItem && (hitRes.VisualHit as SceneItem).Touchy == true)
                    {
                        SceneItem s = hitRes.VisualHit as SceneItem;
                        SceneManager.Instance.CurrentScene.SelectedItem = s;
                        isDragged = true;
                        BackendControl.Instance.refreshGUI();
                    }

                    m_LastHoveredPoint = m_HoveredPoint;
                }
            }
        }
Ejemplo n.º 28
0
        public void OnMouseDown(object sender, EventArgs arg)
        {
            if ((arg is MouseButtonEventArgs) & (sender is Viewport3D))
            {
                Point p = (arg as MouseButtonEventArgs).GetPosition(sender as Viewport3D);
                RayMeshGeometry3DHitTestResult ray = (RayMeshGeometry3DHitTestResult)VisualTreeHelper.HitTest(sender as Viewport3D, p);

                if (ray != null)
                {
                    foreach (var prim in primitiveList)
                    {
                        if (prim.model.Geometry == ray.MeshHit)
                        {
                            prim.IsSelected = (arg as MouseButtonEventArgs).ButtonState == MouseButtonState.Pressed;
                        }
                    }
                }
            }
        }
Ejemplo n.º 29
0
        public HitTestResultBehavior ResultCallback(HitTestResult result)
        {
            // Did we hit 3D?
            RayHitTestResult rayResult = result as RayHitTestResult;

            if (rayResult != null)
            {
                // Did we hit a MeshGeometry3D?
                RayMeshGeometry3DHitTestResult rayMeshResult = rayResult as RayMeshGeometry3DHitTestResult;
                geom.Transform = new TranslateTransform3D(new Vector3D(rayResult.PointHit.X, rayResult.PointHit.Y, rayResult.PointHit.Z));

                if (rayMeshResult != null)
                {
                    // Yes we did!
                }
            }

            return(HitTestResultBehavior.Continue);
        }
Ejemplo n.º 30
0
        private HitTestResultBehavior HTResultCallback(HitTestResult result)
        {
            // Did we hit 3D?
            RayHitTestResult rayResult = result as RayHitTestResult;

            if (rayResult != null)
            {
                // Did we hit a MeshGeometry3D?
                RayMeshGeometry3DHitTestResult rayMeshResult =
                    rayResult as RayMeshGeometry3DHitTestResult;

                if (rayMeshResult != null)
                {
                    // Yes we did!
                }
            }

            return(HitTestResultBehavior.Continue);
        }