Exemplo n.º 1
0
        private void AutoZoom()
        {
            bool             success;
            Viewport3DVisual vp3dv = MeshDiagram3DMath.GetViewport3DVisual(mainViewport, out success);

            if (TooBig(vp3dv, out success) && success)
            {
                while (TooBig(vp3dv, out success) && success)
                {
                    Scale += 0.1;
                }
                while (!TooBig(vp3dv, out success) && Scale > 0 && success)
                {
                    Scale -= 0.01;
                }
                Scale += 0.01;
            }
            else
            {
                while (!TooBig(vp3dv, out success) && success)
                {
                    Scale -= 0.1;
                    if (Scale <= 0)
                    {
                        Scale = 0.01;
                        break;
                    }
                }
                while (TooBig(vp3dv, out success) && success)
                {
                    Scale += 0.01;
                }
            }
        }
Exemplo n.º 2
0
        bool IModelVisual3D.Match(Point point2D)
        {
            bool success  = false;
            Rect my2DRect = MeshDiagram3DMath.Get2DBoundingBox(lastModelVisual3D, out success);

            if (!success)
            {
                return(false);
            }
            return(my2DRect.Contains(point2D));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Test whether curent 3D scene is too big for current Viewport3DVisual: vp3dv  .
        /// </summary>
        /// <param name="vp3dv">Current Viewport3DVisual.</param>
        /// <param name="success">if set to <c>true</c> the scene is too big for this Viewport.</param>
        /// <returns></returns>
        private static bool TooBig(Viewport3DVisual vp3dv, out bool success)
        {
            Rect r = MeshDiagram3DMath.Get2DBoundingBox(vp3dv, out success);

            if (success && r.Height > 0 && r.Width > 0)
            {
                if (r.Left < 0 || r.Top < 0 || r.Right > vp3dv.Viewport.Width || r.Bottom > vp3dv.Viewport.Height)
                {
                    return(true);
                }
            }
            else
            {
                //The vieweport has 0 size
                success = false;
            }
            return(false);
        }
Exemplo n.º 4
0
        public void AddModels()
        {
            if (elements != null && mainViewport != null)
            {
                PerspectiveCamera camera           = (PerspectiveCamera)mainViewport.Camera;
                Vector3D          newlookdirection = camera.LookDirection;
                bool             success;
                Viewport3DVisual vp3dv = MeshDiagram3DMath.GetViewport3DVisual(mainViewport, out success);
                if (success)
                {
                    foreach (IModelVisual3D element in elements)
                    {
                        this.mainViewport.Children.Add(element.GetModelVisual3D(filter, false)); // this is the beginning so no item is selected

                        this.mainViewportCanvas.Children.Add(element.GetUIElement(filter, vp3dv));
                    }
                }
            }
        }
Exemplo n.º 5
0
 //void IModelVisual3D.UpdateViewToLookDirection( Vector3D LookDirection )
 //{
 //  Vector3D look = LookDirection;
 //  look.Normalize();
 //  TextVectorOver = new Vector3D( -look.Y, look.X, 0 );
 //  TextVectorUp = new Vector3D( -look.Z * look.X, -look.Z * look.Y, look.Y * look.Y + look.X * look.X );
 //  TextVectorOver.Normalize();
 //  TextVectorUp.Normalize();
 //}
 UIElement IModelVisual3D.GetUIElement(ModelVisual3DFilter FilterSettings, Viewport3DVisual DestinationViewport3D)
 {
     if (FilterSettings.Texts2D)
     {
         TextBlock tb = new TextBlock();
         tb.FontSize  += 1;
         tb.FontWeight = FontWeights.Bold;
         tb.Foreground = new SolidColorBrush(Colors.DarkGreen);
         tb.Text       = Text;
         Point p2d = MeshDiagram3DMath.Get2DPoint(this.Point3D, DestinationViewport3D);
         Canvas.SetTop(tb, p2d.Y + 0);
         Canvas.SetLeft(tb, p2d.X + 10);
         return(tb);
     }
     else
     {
         return(new UIElement());
     }
 }
Exemplo n.º 6
0
        private void meshDiagramViewport3D_CameraIsChanged(object sender, System.EventArgs e)
        {
            if (lastModelVisual3D != null && displayDescriptionFrontToCamera)
            {
                //        Transform3D tr = meshDiagramViewport3D.GetCamera().Transform;
                Viewport3DVisual mv3dv      = Utilities.GetViewport3DVisual(lastModelVisual3D);
                Matrix3D         mt3d       = Utilities.GetTotalTransformModelVisual3D(lastModelVisual3D);
                Matrix3D         mt3dcamera = Utilities.GetCameraTransform(mv3dv);
                //mt3d.Invert();
                Transform3D      tr                 = new MatrixTransform3D(mt3d);
                ProjectionCamera camera             = mv3dv.Camera as ProjectionCamera;
                Vector3D         BaseTextVectorOver = MeshDiagram3DMath.GetCrossProduct(camera.LookDirection, camera.UpDirection);
                //Vector3D BaseTextVectorUp = new Vector3D( -camera.LookDirection.Z * camera.LookDirection.X, -camera.LookDirection.Z * camera.LookDirection.Y, camera.LookDirection.Y * camera.LookDirection.Y + camera.LookDirection.X * camera.LookDirection.X );
                Vector3D BaseTextVectorUp = new Vector3D(camera.UpDirection.X, camera.UpDirection.Y, camera.UpDirection.Z);

                //bool TransformationResultOK;
                //Matrix3D m = _3DTools.MathUtils.TryWorldToViewportTransform( mv3dv, out TransformationResultOK );
                ////BaseTextVectorOver.Normalize();
                //// BaseTextVectorUp.Normalize();

                //// model.Transform = tr;
                //lastModelVisual3D.Children.Clear();
                //// TextVectorOver = Panel3DMath.Transform3DVector( tr, TextVectorOver );
                //// TextVectorUp = Panel3DMath.Transform3DVector( tr, TextVectorUp );
                //if ( TransformationResultOK )
                //{
                //  TextVectorOver = BaseTextVectorOver * m;
                //  TextVectorUp = BaseTextVectorUp * m;
                //}
                //else
                //{
                //  TextVectorOver = BaseTextVectorOver * mt3dcamera;
                //  TextVectorUp = BaseTextVectorUp * mt3dcamera;
                //}
                TextVectorOver = BaseTextVectorOver;
                TextVectorUp   = BaseTextVectorUp;

                TextVectorOver.Normalize();
                TextVectorUp.Normalize();
                FillModel(false);//TODO: I am not sure whether false is OK??
            }
        }