/// <summary>
        /// Draws the polygon based on the saved point list.
        /// </summary>
        private void DrawPolygon()
        {
            //In order to draw the whole drawing in the center of the viewer some additional
            //calculation is required.

            if (Points != null && BoundBox != null)
            {
                REXxyz          dx       = BoundBox.Max - BoundBox.Min;
                PolyLineSegment polyline = new PolyLineSegment();

                //The assumption is that there will be empty frame of 0.1*Max(width,height) around
                //the drawing. To get the most extreme case the coefficients in x any y direction are
                //calculated.
                double coeffX = 0.8 * this.ActualWidth / dx.x;
                double coeffY = 0.8 * this.ActualHeight / dx.y;

                double coeff;
                double xstart;
                double ystart;
                if (coeffX < coeffY)
                {
                    coeff  = coeffX;
                    xstart = 0.1 * this.ActualWidth;
                    ystart = 0.1 * this.ActualHeight + (0.8 * this.ActualHeight - (coeffX * dx.y)) / 2;
                }
                else
                {
                    coeff  = coeffY;
                    ystart = 0.1 * this.ActualHeight;
                    xstart = 0.1 * this.ActualWidth + (0.8 * this.ActualWidth - (coeffY * dx.x)) / 2;
                }

                for (int i = 0; i < Points.Count; i++)
                {
                    REXxyz pt = Points[i];
                    polyline.Points.Add(new Point(xstart + (pt.x - BoundBox.Min.x) * coeff, this.ActualHeight - (ystart + (pt.y - BoundBox.Min.y) * coeff)));
                }
                pathGeometry.Figures.Clear();

                REXxyz startPt = Points[0];

                PathFigure pathFigure = new PathFigure(new Point(xstart + (startPt.x - BoundBox.Min.x) * coeff, this.ActualHeight - (ystart + (startPt.y - BoundBox.Min.y) * coeff)), new List <PathSegment>()
                {
                    polyline
                }, true);
                pathFigure.Segments.Add(polyline);

                pathGeometry.Figures.Add(pathFigure);
            }
        }
        /// <summary>
        /// Draws the specified triangle.
        /// </summary>
        /// <param name="triangle">The triangle.</param>
        /// <param name="geometry">The geometry.</param>
        void DrawTriangle(Main.Triangle triangle, MeshGeometry3D geometry)
        {
            int    count          = geometry.Positions.Count;
            REXxyz centerBoundBox = BoundBox.GetCenter();

            //All points are translated in this way to obtain the center of the bounding box in (0,0,0).

            geometry.Positions.Add(GetPoint3D(triangle.Pt1 - centerBoundBox));
            geometry.Positions.Add(GetPoint3D(triangle.Pt2 - centerBoundBox));
            geometry.Positions.Add(GetPoint3D(triangle.Pt3 - centerBoundBox));

            geometry.TriangleIndices.Add(count);
            geometry.TriangleIndices.Add(count + 1);
            geometry.TriangleIndices.Add(count + 2);
        }
        /// <summary>
        /// Sets the camera position.
        /// </summary>
        void SetCameraPosition()
        {
            //The 0,0,0 point is the center of the scene.
            //Animation rotates the object about Z axis.
            REXxyz boundBoxDX = BoundBox.Max - BoundBox.Min;
            REXxyz centerBox  = BoundBox.GetCenter();

            //The start LookDirection is calculated based on the center and the maximum point
            //of the bounding box.
            REXxyz dx = centerBox - BoundBox.Max;

            //The camera used in this sample is an OrthographicCamera and to be sure that all
            //content is visible on the viewer the appropriate width is calculated based on
            //the diagonal of the bounding box
            double width = dx.GetLength() * 2.2;

            //In order to have better view of the element some modification of the LookDirection
            //is required
            //for horizontal elements - to see them more from the top
            if (boundBoxDX.x > boundBoxDX.z || boundBoxDX.y > boundBoxDX.z)
            {
                dx.z *= 10;
            }
            else//for vertical elements - to see them more from the side
            {
                dx.z /= 10;
            }

            REXxyz dxUnit = dx.GetUnitVector();

            //The position of the camera is calculated based on the center of the bounding box
            //(which is in 0,0,0) and some default distance - here 100
            camera.Position           = new Point3D(-dxUnit.x * 100, -dxUnit.y * 100, -dxUnit.z * 100);
            camera.LookDirection      = new Vector3D(dxUnit.x, dxUnit.y, dxUnit.z);
            directionLight.Direction  = camera.LookDirection;
            directionLight2.Direction = new Vector3D(dxUnit.x, dxUnit.y, 0);
            REXxyz upDir = dxUnit.CrossProduct(new REXxyz(0, 0, 1)).CrossProduct(new REXxyz(dxUnit));

            camera.UpDirection = new Vector3D(upDir.x, upDir.y, upDir.z);
            camera.Width       = width;
        }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Triangle"/> class.
 /// </summary>
 /// <param name="pt1">The first point.</param>
 /// <param name="pt2">The second point.</param>
 /// <param name="pt3">The third point.</param>
 public Triangle(REXxyz pt1, REXxyz pt2, REXxyz pt3)
 {
     Pt1 = pt1;
     Pt2 = pt2;
     Pt3 = pt3;
 }
 Point3D GetPoint3D(REXxyz pt)
 {
     return(new Point3D(pt.x, pt.y, pt.z));
 }