Пример #1
0
        /// <summary>
        /// Invoked when an unhandled MouseLeftButtonDown routed event is raised on this element.
        /// </summary>
        /// <param name="e">The MouseButtonEventArgs that contains the event data.</param>
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            Keyboard.Focus(this);
            // if (!System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
            {
                if (!((Keyboard.Modifiers & ModifierKeys.Control) > 0) && (!this.IsDragging))
                {
                    // Memorizations must occur before CaptureAndHideMouse() call
                    // GetCursorPos(out _dragOriginScreenPoint);

                    // Mouse.GetPosition(
                    // _dragOriginScreenPoint = _viewport.PointToScreen(point);

                    _viewport = Helper3D.GetViewport3D(this);

                    _dragOriginPoint = e.GetPosition(this);

                    // CaptureAndHideMouse Moves the mouse
                    CaptureAndHideMouse();

                    base.SetValue(IsDraggingPropertyKey, true);
                    base.SetValue(IsSelectedPropertyKey, true);
                }
            }
            base.OnMouseLeftButtonDown(e);
        }
Пример #2
0
 /// <summary>
 /// Build a MeshGeometry3D object from the Sculptor object.
 /// Points should be initialized before the call.
 /// Fires a BuiltMesh event, where custom texture coordinates may be created.
 /// </summary>
 /// <returns>MeshGeometry3D object</returns>
 public void BuildMesh()
 {
     CreateTriangles();
     _mesh = new MeshGeometry3D();
     foreach (Point3DTriplet tpl in this._triangles)
     {
         Helper3D.BuildTriangleMesh(_mesh, tpl.Points[0], tpl.Points[1], tpl.Points[2]);
     }
 }
Пример #3
0
        /// <summary>
        /// Captures and hides the mouse.
        /// </summary>
        protected void CaptureAndHideMouse()
        {
            base.CaptureMouse();
            Mouse.OverrideCursor = Cursors.None;

            // code specific to 3D
            Viewport3D viewport = Helper3D.GetViewport3D(this);

            // GeneralTransform3DTo2D transform = this.TransformToAncestor(ancestor);
            // Point pScreen = transform.Transform(<3d point from the mesh in myVisual3D space>);

            Point p = new Point(
                _dragOriginPoint.X,
                _dragOriginPoint.Y - (DragHeight * Rate));
            Point pScreen = viewport.PointToScreen(p);

            SetCursorPos(
                Convert.ToInt32(pScreen.X),
                Convert.ToInt32(pScreen.Y));
        }
Пример #4
0
        /// <summary>
        /// Rounds a vertex of a triangle.
        /// </summary>
        /// <param name="pA">First point.</param>
        /// <param name="pB">Second point. Vertex to round</param>
        /// <param name="pC">Third point.</param>
        /// <param name="roundingRate">Vertex rounding rate. The value must be comprized between 0.0 and 0.5.</param>
        /// <returns></returns>
        public static Point3DCollection RoundCorner(Point3D pA, Point3D pB, Point3D pC, double roundingRate)
        {
            if (!((pA.Z == pB.Z) && (pB.Z == pC.Z))
                )
            {
                throw new ArgumentOutOfRangeException("pA");
            }

            if ((roundingRate < 0.0) ||
                (roundingRate > 0.5)
                )
            {
                throw new ArgumentOutOfRangeException("roundingRate");
            }

            Point3DCollection points = new Point3DCollection();

            int roundingDefinition = (int)(roundingRate * 40.0);

            Vector3D v1 = new Vector3D();

            v1   = pA - pB;
            v1.X = Math.Round(v1.X, 3);
            v1.Y = Math.Round(v1.Y, 3);
            v1.Z = Math.Round(v1.Z, 3);
            Point3D p1 = Point3D.Add(pB, Vector3D.Multiply(v1, roundingRate));

            Vector3D v2 = new Vector3D();

            v2   = pC - pB;
            v2.X = Math.Round(v2.X, 3);
            v2.Y = Math.Round(v2.Y, 3);
            v2.Z = Math.Round(v2.Z, 3);
            Point3D p2 = Point3D.Add(pB, Vector3D.Multiply(v2, roundingRate));

            // v1 is the normal vector for the linear curve
            // v1.X*x + v1.Y*y + c1 = 0;
            // p1 is woned by this curve so
            double c1 = -(v1.X * p1.X) - (v1.Y * p1.Y);

            // same for v2 and p2
            double c2 = -(v2.X * p2.X) - (v2.Y * p2.Y);

            // center for the arc that owns p1 and p2
            Point3D center = new Point3D();

            if (v1.Y == 0.0)
            {
                if (v1.X == 0.0)
                {
                    throw new InvalidOperationException();
                }
                center.X = -c1 / v1.X;
                if (v2.Y == 0.0)
                {
                    throw new InvalidOperationException();
                }
                else
                {
                    center.Y = (-c2 - v2.X * center.X) / v2.Y;
                }
            }
            else
            {
                if (v2.Y == 0.0)
                {
                    if (v2.X == 0.0)
                    {
                        throw new InvalidOperationException();
                    }
                    center.X = -c2 / v2.X;
                }
                else
                {
                    center.X = (c1 / v1.Y - c2 / v2.Y) / (v2.X / v2.Y - v1.X / v1.Y);
                }
                center.Y = (-c1 - v1.X * center.X) / v1.Y;
            }
            center.Z = pB.Z;

            // angle of the arc between p1 and p2
            // 360 - 180 - Vector3D.AngleBetween(v1, v2)
            double angleArc = Helper3D.DegreeToRadian(180 - Vector3D.AngleBetween(v1, v2));

            // angle of each part
            double angleStep = angleArc / roundingDefinition;

            Vector3D vRadius = p1 - center;

            double angleBaseDeg = Vector3D.AngleBetween(new Vector3D(1, 0, 0), vRadius);

            // necessar adjustment because of Vector3D.AngleBetween() - see documentation
            if (p1.Y < 0.0)
            {
                angleBaseDeg = 360 - angleBaseDeg;
            }
            double angleBase = Helper3D.DegreeToRadian(angleBaseDeg);

            points.Add(p1);
            // points of the arc
            for (int j = 1; j <= roundingDefinition - 1; j++)
            {
                double  angle = angleBase + (angleStep * j);
                Point3D p     = new Point3D();
                p.X = center.X + Math.Cos(angle) * vRadius.Length;
                p.Y = center.Y + Math.Sin(angle) * vRadius.Length;
                p.Z = pB.Z;
                points.Add(p);
            }
            points.Add(p2);

            return(points);
        }