Пример #1
0
        /// <summary>
        /// Updates the polygon.
        /// </summary>
        /// <param name="updatedPoints">The Updated Points</param>
        /// <param name="interior">The Interior</param>
        /// <param name="visibility">The Visibility</param>
        internal void Update(Vector3D[] updatedPoints, Brush interior, Visibility visibility)
        {
            VectorPoints = updatedPoints;
            var segmentPath = Element as Path;

            if (segmentPath == null)
            {
                return;
            }
            segmentPath.Visibility = visibility;
            if (Graphics3D == null)
            {
                return;
            }
            var transform       = Graphics3D.Transform;
            var figure          = new PathFigure();
            var segmentGeometry = new PathGeometry();

            var actualBrush = (Fill is SolidColorBrush) ?
                              ((SolidColorBrush)Fill).Color :
                              ((Fill is LinearGradientBrush) && ((LinearGradientBrush)Fill).GradientStops.Count > 0) ?
                              ((LinearGradientBrush)Fill).GradientStops[0].Color :
                              new SolidColorBrush(Colors.Transparent).Color;

            if (transform != null)
            {
                figure.StartPoint = transform.ToScreen(VectorPoints[0]);
                foreach (var lineSegment in VectorPoints.Select(item => new WindowsLineSegment {
                    Point = transform.ToScreen(item)
                }))
                {
                    figure.Segments.Add(lineSegment);
                }
            }

            segmentGeometry.Figures.Add(figure);
            var lightCoefZ = (int)(2 * (Math.Abs(normal & new Vector3D(0, 0, 1)) - 1));
            var lightCoefY = (int)(2 * (Math.Abs(normal & new Vector3D(0, 1, 0)) - 1));
            var lightCoefX = (int)(2 * (Math.Abs(normal & new Vector3D(1, 0, 0)) - 1));

            if (lightCoefZ == lightCoefX && interior != null)
            {
                segmentPath.Fill = ApplyZLight(actualBrush);
            }
            else if (((lightCoefY == lightCoefZ) || (lightCoefZ != 0 && lightCoefY < lightCoefZ)) &&
                     !(Tag is LineSegment3D) && !(Tag is AreaSegment3D) && interior != null)
            {
                segmentPath.Fill = Polygon3D.ApplyXLight(actualBrush);
            }
            else if (lightCoefZ < 0 && interior != null)
            {
                segmentPath.Fill = ApplyZLight(actualBrush);
            }
            else
            {
                segmentPath.Fill = interior;
            }

            segmentPath.Data = segmentGeometry;
        }
Пример #2
0
        /// <summary>
        /// Redraws the segments.
        /// </summary>
        internal void ReDraw()
        {
            if (VectorPoints == null || VectorPoints.Length <= 0)
            {
                return;
            }
            var transform   = Graphics3D.Transform;
            var segmentPath = Element as Path;

            if (segmentPath == null)
            {
                return;
            }
            var figure          = new PathFigure();
            var segmentGeometry = new PathGeometry();

            if (transform != null)
            {
                figure.StartPoint = transform.ToScreen(VectorPoints[0]);
                foreach (var lineSegment in VectorPoints.Select(item => new WindowsLineSegment {
                    Point = transform.ToScreen(item)
                }))
                {
                    figure.Segments.Add(lineSegment);
                }
            }

            segmentGeometry.Figures.Add(figure);
            segmentPath.Data = segmentGeometry;
            var lightCoefZ = (int)(2 * (Math.Abs(normal & new Vector3D(0, 0, 1)) - 1));
            var lightCoefY = (int)(2 * (Math.Abs(normal & new Vector3D(0, 1, 0)) - 1));
            var lightCoefX = (int)(2 * (Math.Abs(normal & new Vector3D(1, 0, 0)) - 1));

            var actualBrush = (Fill is SolidColorBrush) ?
                              ((SolidColorBrush)Fill).Color :
                              ((Fill is LinearGradientBrush) && ((LinearGradientBrush)Fill).GradientStops.Count > 0) ?
                              ((LinearGradientBrush)Fill).GradientStops[0].Color :
                              new SolidColorBrush(Colors.Transparent).Color;

            if (lightCoefZ == lightCoefX && Fill != null)
            {
                segmentPath.Fill = ApplyZLight(actualBrush);
            }
            else if (((lightCoefY == lightCoefZ) || (lightCoefZ != 0 && lightCoefY < lightCoefZ)) &&
                     !(Tag is LineSegment3D) && !(Tag is AreaSegment3D) && !(Tag is PieSegment3D) && Fill != null)
            {
                segmentPath.Fill = Polygon3D.ApplyXLight(actualBrush);
            }
            else if (lightCoefZ < 0 && Fill != null)
            {
                segmentPath.Fill = ApplyZLight(actualBrush);
            }
            else
            {
                segmentPath.Fill = Fill;
            }

            segmentPath.StrokeThickness = strokeThickness;
            segmentPath.Stroke          = Stroke;
        }