private ScreenSpaceLines3D AddVehiclePoints(Viewport3D mainViewport, Point3D[] pointsArray)
        {
            ScreenSpaceLines3D wireVehicle=new ScreenSpaceLines3D();
            Color color = Colors.Red;
            const int width = 1;

            wireVehicle.Thickness = width;
            wireVehicle.Color = color;
            wireVehicle.Points.Add(pointsArray[0]);
            wireVehicle.Points.Add(pointsArray[1]);
            wireVehicle.Points.Add(pointsArray[1]);
            wireVehicle.Points.Add(pointsArray[2]);
            wireVehicle.Points.Add(pointsArray[2]);
            wireVehicle.Points.Add(pointsArray[3]);
            wireVehicle.Points.Add(pointsArray[3]);
            wireVehicle.Points.Add(pointsArray[0]);
            wireVehicle.Points.Add(pointsArray[4]);
            wireVehicle.Points.Add(pointsArray[5]);
            wireVehicle.Points.Add(pointsArray[5]);
            wireVehicle.Points.Add(pointsArray[6]);
            wireVehicle.Points.Add(pointsArray[6]);
            wireVehicle.Points.Add(pointsArray[7]);
            wireVehicle.Points.Add(pointsArray[7]);
            wireVehicle.Points.Add(pointsArray[4]);
            wireVehicle.Points.Add(pointsArray[0]);
            wireVehicle.Points.Add(pointsArray[4]);
            wireVehicle.Points.Add(pointsArray[1]);
            wireVehicle.Points.Add(pointsArray[5]);
            wireVehicle.Points.Add(pointsArray[2]);
            wireVehicle.Points.Add(pointsArray[6]);
            wireVehicle.Points.Add(pointsArray[3]);
            wireVehicle.Points.Add(pointsArray[7]);
            return wireVehicle;
        }
Exemple #2
0
 public static void CreateWireframe(
     Point3D p0, Point3D p1, Point3D p2, Point3D p3,
     Color lineColor, Viewport3D viewport)
 {
     ScreenSpaceLines3D ssl = new ScreenSpaceLines3D();
     ssl.Points.Add(p0);
     ssl.Points.Add(p1);
     ssl.Points.Add(p1);
     ssl.Points.Add(p2);
     ssl.Points.Add(p2);
     ssl.Points.Add(p3);
     ssl.Points.Add(p3);
     ssl.Points.Add(p0);
     ssl.Color = lineColor;
     ssl.Thickness = 2;
     viewport.Children.Add(ssl);
 }
        private void DrawBox()
        {
            ScreenSpaceLines3D lineCollection = new ScreenSpaceLines3D();
            int width = 3;
            lineCollection.Thickness = width;
            lineCollection.Color = Colors.Red;

            DrawLine(lineCollection, LeftTopBack, RightTopBack);
            DrawLine(lineCollection, LeftBottomBack, RightBottomBack);
            DrawLine(lineCollection, LeftTopBack, LeftBottomBack);
            DrawLine(lineCollection, RightTopBack, RightBottomBack);

            DrawLine(lineCollection, LeftTopBack, LeftTopFront);
            DrawLine(lineCollection, RightTopBack, RightTopFront);
            DrawLine(lineCollection, LeftBottomBack, LeftBottomFront);
            DrawLine(lineCollection, RightBottomBack, RightBottomFront);

            Viewport.Children.Add(lineCollection);
        }
        private Model3DGroup BuildNormals(
    Point3D p0,
    Point3D p1,
    Point3D p2,
    Vector3D normal)
        {
            Model3DGroup normalGroup = new Model3DGroup();
            Point3D p;
            ScreenSpaceLines3D normal0Wire = new ScreenSpaceLines3D();
            ScreenSpaceLines3D normal1Wire = new ScreenSpaceLines3D();
            ScreenSpaceLines3D normal2Wire = new ScreenSpaceLines3D();
            Color c = Colors.Blue;
            int width = 1;
            normal0Wire.Thickness = width;
            normal0Wire.Color = c;
            normal1Wire.Thickness = width;
            normal1Wire.Color = c;
            normal2Wire.Thickness = width;
            normal2Wire.Color = c;
            double num = 1;
            double mult = .01;
            double denom = mult * Convert.ToDouble(normalSizeTextBox.Text);
            double factor = num / denom;
            p = Vector3D.Add(Vector3D.Divide(normal, factor), p0);
            normal0Wire.Points.Add(p0);
            normal0Wire.Points.Add(p);
            p = Vector3D.Add(Vector3D.Divide(normal, factor), p1);
            normal1Wire.Points.Add(p1);
            normal1Wire.Points.Add(p);
            p = Vector3D.Add(Vector3D.Divide(normal, factor), p2);
            normal2Wire.Points.Add(p2);
            normal2Wire.Points.Add(p);

            //Normal wires are not models, so we can't
            //add them to the normal group.  Just add them
            //to the viewport for now...
            this.mainViewport.Children.Add(normal0Wire);
            this.mainViewport.Children.Add(normal1Wire);
            this.mainViewport.Children.Add(normal2Wire);

            return normalGroup;
        }
        private void drawGrid()
        {
            ScreenSpaceLines3D normal0Wire = new ScreenSpaceLines3D();
            int width = 2;
            normal0Wire.Thickness = width;
            normal0Wire.Color = Colors.Red;

            normal0Wire.Points.Add(startV);
            normal0Wire.Points.Add(endV);

            normal0Wire.Points.Add(new Point3D(0.530, -0.29, -0.5));
            normal0Wire.Points.Add(new Point3D(0.530, 0.29, -0.5));

            normal0Wire.Points.Add(new Point3D(0.530, 0.29, -0.5));
            normal0Wire.Points.Add(new Point3D(-0.530, 0.29, -0.5));

            normal0Wire.Points.Add(startH);
            normal0Wire.Points.Add(endH);

            normal0Wire.Points.Add(new Point3D(0, 0, 0));
            normal0Wire.Points.Add(new Point3D(0, 0, -0.5));

            normal0Wire.Points.Add(new Point3D(0, 0, -0.25));
            normal0Wire.Points.Add(new Point3D(0.530, 0, -0.25));

            normal0Wire.Points.Add(new Point3D(0, 0, -0.25));
            normal0Wire.Points.Add(new Point3D(0, 0.29, -0.25));

            normal0Wire.Points.Add(new Point3D(-0.530, -0.289, -0.5));
            normal0Wire.Points.Add(new Point3D(-0.530, -0.289, -0.042));

            normal0Wire.Points.Add(new Point3D(0.530, -0.289, -0.5));
            normal0Wire.Points.Add(new Point3D(0.530, -0.289, -0.042));

            normal0Wire.Points.Add(new Point3D(-0.530, 0.289, -0.5));
            normal0Wire.Points.Add(new Point3D(-0.530, 0.289, -0.042));

            normal0Wire.Points.Add(new Point3D(0.530, 0.289, -0.5));
            normal0Wire.Points.Add(new Point3D(0.530, 0.289, -0.042));

            viewport.Children.Add(normal0Wire);
        }
        public void SetAllPlaceEx(string place, string city)
        {
            txtsociety.Visibility = Visibility.Hidden;
            txteconomic.Visibility = Visibility.Hidden;
            txtecology.Visibility = Visibility.Hidden;

            Introduce.Text = "本市各年份综合指标走势";
            myState = WpfApplication3.Enum.MapState.Egg2;

            ecologyHigh = DataLib.DA_Index.QueryIndexByZone(place).Where(c => c.Name == "生态子系统综合指标" && c.FromDate.Year == _currentYear).First().WarnValueHigh.Value;
            //double ecologyLow = DataLib.DA_Index.QueryIndexByZone(place).Where(c => c.Name == "生态子系统综合指标" && c.FromDate.Year == _currentYear).First().WarnValueLow.Value;
            economicHigh = DataLib.DA_Index.QueryIndexByZone(place).Where(c => c.Name == "经济子系统综合指标" && c.FromDate.Year == _currentYear).First().WarnValueHigh.Value;
            //double economicLow = DataLib.DA_Index.QueryIndexByZone(place).Where(c => c.Name == "经济子系统综合指标" && c.FromDate.Year == _currentYear).First().WarnValueLow.Value;
            socialHigh = DataLib.DA_Index.QueryIndexByZone(place).Where(c => c.Name == "社会子系统综合指标" && c.FromDate.Year == _currentYear).First().WarnValueHigh.Value;
            //double socialLow = DataLib.DA_Index.QueryIndexByZone(place).Where(c => c.Name == "社会子系统综合指标" && c.FromDate.Year == _currentYear).First().WarnValueLow.Value;

            //List<Point3D> list = new List<Point3D>();
            list.Clear();
            for (int i = 2000; i < 2010; i++)
            {
                double indexEcology = DataLib.DA_Index.QueryIndexByZone(place).Where(c => c.Name == "生态子系统综合指标" && c.FromDate.Year == i).First().Value;
                double indexEconomic = DataLib.DA_Index.QueryIndexByZone(place).Where(c => c.Name == "经济子系统综合指标" && c.FromDate.Year == i).First().Value;
                double indexSocial = DataLib.DA_Index.QueryIndexByZone(place).Where(c => c.Name == "社会子系统综合指标" && c.FromDate.Year == i).First().Value;

                ///////////////////////////////////////////////////////////////////

                /////////////////////////////////////////////////////////////////////

                //画点///////////////////////////////////////////////////////////////
                drawPoint2Ex(new Point3D(indexEcology - ecologyHigh / 2, indexEconomic - economicHigh / 2, indexSocial - socialHigh / 2), i);
                list.Add(new Point3D(indexEcology, indexEconomic, indexSocial));
                if (indexEcology > ecologyHigh)
                    isEcology.Add("NO|" + indexEcology);
                else
                {
                    isEcology.Add("YES|" + indexEcology);
                }
                if (indexEconomic > economicHigh)
                    isEconomic.Add("NO|" + indexEconomic);
                else
                {
                    isEconomic.Add("YES|" + indexEconomic);
                }
                if (indexSocial > socialHigh)
                    isSocial.Add("NO|" + indexSocial);
                else
                {
                    isSocial.Add("YES|" + indexSocial);
                }
            }
            //画九条线
            for (int i = 0; i < list.Count - 1; i++)
            {
                ScreenSpaceLines3D screenSpaceLines3D = new ScreenSpaceLines3D();
                Point3DCollection point3DCollection = new Point3DCollection();
                Point3D point3D = new Point3D(list[i].X - ecologyHigh / 2, list[i].Y - economicHigh / 2, list[i].Z - socialHigh / 2);
                Point3D point3D1 = new Point3D(list[i + 1].X - ecologyHigh / 2, list[i + 1].Y - economicHigh / 2, list[i + 1].Z - socialHigh / 2);
                point3DCollection.Add(point3D);
                point3DCollection.Add(point3D1);
                screenSpaceLines3D.Points = point3DCollection;
                screenSpaceLines3D.Thickness = 3;
                screenSpaceLines3D.Color = Color.FromRgb(0, 0, 0);
                //if (screenSpaceLines3Ds.Length != 0)
                //MyViewport.Children.Remove(screenSpaceLines3Ds[i]);
                screenSpaceLines3Ds[i] = screenSpaceLines3D;
                MyViewport.Children.Insert(0, screenSpaceLines3Ds[i]);
            }

            //_perspectiveCamera1 = MakeCamera();
            //_perspectiveCamera2 = MakeCamera();
            if (model3DGroup1 != null)
                model3DGroup1.Children.Clear();
            if (model3DGroup2 != null)
                model3DGroup2.Children.Clear();
            InitiateGroup();
            GenerateViewPort(ecologyHigh, 0, economicHigh, 0, socialHigh, 0);
            GenerateViewPort2((ecologyHigh - 0) / 2, (economicHigh - 0) / 2, (socialHigh - 0) / 2, (ecologyHigh + 0) / 2, (economicHigh + 0) / 2, (socialHigh + 0) / 2);

            Show();
        }
        /// <summary>
        /// Set All Place
        /// </summary>
        /// <param name="place"></param>
        /// <param name="city"></param>
        /// <author>ZhangMiao</author>
        /// <date>20100324</date>
        public void SetAllPlace(string place, string city)
        {
            Introduce.Text = "本市各年份综合指标走势";
            myState = WpfApplication3.Enum.MapState.Egg2;
            //List<Point3D> list = new List<Point3D>();
            for (int i = 2000; i < 2008; i++)
            {
                SetPlace(place, city, i, list, allValue, false);
            }
            List<Point3D> newList = new List<Point3D>();

            for (int i = 0; i < list.Count - 1; i++)
            {
                double x = list[i + 1].X - list[i].X / list[i].X;
                double y = list[i + 1].Y - list[i].Y / list[i].Y;
                double z = list[i + 1].Z - list[i].Z / list[i].Z;

                newList.Add(new Point3D(x, y, z));
            }

            double sumx = 0; double sumy = 0; double sumz = 0;
            for (int i = 0; i < newList.Count; i++)
            {
                sumx = sumx + newList[i].X;
                sumy = sumy + newList[i].Y;
                sumz = sumz + newList[i].Z;
            }
            double avex = sumx / newList.Count;
            double avey = sumy / newList.Count;
            double avez = sumz / newList.Count;

            //List<Point3D> endList = new List<Point3D>();
            for (int i = 0; i < newList.Count; i++)
            {
                endList.Add(new Point3D((newList[i].X - avex), (newList[i].Y - avey), (newList[i].Z - avez)));
            }
            double average = allValue.Sum() / allValue.Count;
            double variance = 0.0;
            foreach (double v in allValue)
            {
                variance += Math.Pow((v - average), 2);
            }
            warnValue = average - 2.33 * Math.Pow((variance / allValue.Count), 0.5);
            foreach (Point3D p in endList)
            {

                drawPoint2(p, endList.IndexOf(p) + 2000);
            }

            Point3D pback = new Point3D();
            Point3D pfront = new Point3D();
            pback = endList[0];
            for (int i = 0; i < endList.Count - 1; i++)
            {
                pfront = pback;
                pback = endList[i + 1];
                ScreenSpaceLines3D pt = new ScreenSpaceLines3D();
                pt.Points.Add(pfront);
                pt.Points.Add(pback);
                pt.Thickness = 2;
                pt.Color = Colors.Blue;
                MyViewport.Children.Insert(0, pt);

                double DArrow = Math.PI / 6;
                double MArrow = 0.3;

                #region 代码
                double ZXYLong = Math.Sqrt((pback.Z - pfront.Z) * (pback.Z - pfront.Z) +
                    (pback.X - pfront.X) * (pback.X - pfront.X) +
                    (pback.Y - pfront.Y) * (pback.Y - pfront.Y));
                if (ZXYLong == 0)
                    continue;
                Point3D arrow1 = new Point3D();
                Point3D arrow2 = new Point3D();

                if (pback.Y == pfront.Y && pback.X == pfront.Y)
                {

                    double MArrowY = MArrow * Math.Sin(DArrow);
                    double MArrowZ = MArrow * Math.Cos(DArrow);
                    int SignedZ;
                    if (pback.Z > pfront.Z)
                        SignedZ = -1;
                    else
                        SignedZ = 1;

                    arrow1.X = pback.X;
                    arrow1.Y = pback.Y - MArrow * Math.Sin(DArrow);
                    arrow1.Z = pback.Z + SignedZ * MArrow * Math.Cos(DArrow);

                    arrow2.X = pback.X;
                    arrow2.Y = pback.Y + MArrow * Math.Sin(DArrow);
                    arrow2.Z = pback.Z + SignedZ * MArrow * Math.Cos(DArrow);

                }
                else
                {

                    double DegreeZ = Math.Asin((pback.Z - pfront.Z) / ZXYLong);

                    double De2 = Math.PI / 2 - DegreeZ;
                    double De1 = Math.PI - DArrow - De2;
                    double De3 = Math.PI - De2;
                    double De4 = Math.PI - De3 - DArrow;

                    double LArrow = MArrow * Math.Sin(De1) / Math.Sin(De2);

                    double MiddelZ = LArrow * (pback.Z - pfront.Z) / ZXYLong;// Math.Sin(DegreeZ);
                    double MiddelY = LArrow * (pback.Y - pfront.Y) / ZXYLong;//Math.Sin(DegreeY);
                    double MiddelX = LArrow * (pback.X - pfront.X) / ZXYLong;//Math.Sin(DegreeX);

                    double MiddleZ = pback.Z - MiddelZ;
                    double MiddleY = pback.Y - MiddelY;
                    double MiddleX = pback.X - MiddelX;

                    double ArOP = MArrow * Math.Sin(De1) / Math.Sin(De4);
                    double Middle2 = MArrow * LArrow / ArOP;
                    //double Middle2 = MArrow * Math.Sin(De4);

                    double Z1 = LArrow * Math.Sin(DArrow) / Math.Sin(De1);
                    double Z2 = MArrow * Math.Sin(DArrow) / Math.Sin(De3);

                    arrow1.X = MiddleX;
                    arrow1.Y = MiddleY;
                    arrow1.Z = MiddleZ + Z1;

                    arrow2.X = pback.X - Middle2 * ((pback.X - pfront.X) / ZXYLong);
                    arrow2.Y = pback.Y - Middle2 * ((pback.Y - pfront.Y) / ZXYLong);
                    arrow2.Z = pback.Z - Middle2 * ((pback.Z - pfront.Z) / ZXYLong) - Z2;

                }

                ScreenSpaceLines3D temp1 = new ScreenSpaceLines3D();
                ScreenSpaceLines3D temp2 = new ScreenSpaceLines3D();
                temp1.Points.Add(pback);
                temp2.Points.Add(pback);
                temp1.Points.Add(arrow1);
                temp2.Points.Add(arrow2);
                temp1.Thickness = 1;
                temp2.Thickness = 1;
                temp1.Color = Colors.Red;
                temp2.Color = Colors.Red;
                MyViewport.Children.Insert(0, temp1);
                MyViewport.Children.Insert(0, temp2);

                #endregion
            }

            double ecologyHigh = DataLib.DA_Index.QueryIndexByZone(place).Where(c => c.Name == "生态子系统综合指标" && c.FromDate.Year == _currentYear).First().WarnValueHigh.Value;
            //double ecologyLow = DataLib.DA_Index.QueryIndexByZone(place).Where(c => c.Name == "生态子系统综合指标" && c.FromDate.Year == _currentYear).First().WarnValueLow.Value;
            double economicHigh = DataLib.DA_Index.QueryIndexByZone(place).Where(c => c.Name == "经济子系统综合指标" && c.FromDate.Year == _currentYear).First().WarnValueHigh.Value;
            //double economicLow = DataLib.DA_Index.QueryIndexByZone(place).Where(c => c.Name == "经济子系统综合指标" && c.FromDate.Year == _currentYear).First().WarnValueLow.Value;
            double socialHigh = DataLib.DA_Index.QueryIndexByZone(place).Where(c => c.Name == "社会子系统综合指标" && c.FromDate.Year == _currentYear).First().WarnValueHigh.Value;
            //double socialLow = DataLib.DA_Index.QueryIndexByZone(place).Where(c => c.Name == "社会子系统综合指标" && c.FromDate.Year == _currentYear).First().WarnValueLow.Value;

            _perspectiveCamera1 = MakeCamera();
            _perspectiveCamera2 = MakeCamera();
            GenerateViewPort(ecologyHigh, 0, economicHigh, 0, socialHigh, 0);
            GenerateViewPort2((ecologyHigh - 0) / 2, (economicHigh - 0) / 2, (socialHigh - 0) / 2, (ecologyHigh + 0) / 2, (economicHigh + 0) / 2, (socialHigh + 0) / 2);

            Show();
        }
 ModelVisual3D IModelVisual3D.GetModelVisual3D(ModelVisual3DFilter filterSettings)
 {
     if (filterSettings != null && filterSettings.Lines)
     {
         ScreenSpaceLines3D line = new ScreenSpaceLines3D();
         line.Thickness = 1;
         line.Color = Colors.Black;
         line.Points.Add(Start.Point3D);
         line.Points.Add(End.Point3D);
         return line;
     }
     else return new ModelVisual3D();
 }
Exemple #9
0
        /// <summary>
        /// Creates the geometry for this piece.
        /// </summary>
        protected internal override void Generate()
        {
            if (_Geometry == null)
            {
                MeshGeometry3D mg3d = new MeshGeometry3D();
                mg3d.Positions.Add(new Point3D(0, 0, 0));

                // Create the top.
                double rad = _StartRadix;
                int steps = 0;
                while (true)
                {
                    double x = PieGraph.Radius * Math.Sin(rad);
                    double y = PieGraph.Radius * Math.Cos(rad);
                    mg3d.Positions.Add(new Point3D(x, y, 0));
                    if (rad == _EndRadix)
                        break;
                    rad += RadStep;
                    if (rad > _EndRadix)
                        rad = _EndRadix;
                    steps++;
                }

                for (int i = 1; i <= steps; i++)
                {
                    mg3d.TriangleIndices.Add(0);
                    mg3d.TriangleIndices.Add(i);
                    mg3d.TriangleIndices.Add(i + 1);
                }

                // Create the bottom.
                mg3d.Positions.Add(new Point3D(0, 0, 1));
                int placeMarker = steps + 2;
                mg3d.TriangleIndices.Add(0);
                mg3d.TriangleIndices.Add(placeMarker);
                mg3d.TriangleIndices.Add(placeMarker);

                rad = _StartRadix;
                steps = 0;
                while (true)
                {
                    double x = PieGraph.Radius * Math.Sin(rad);
                    double y = PieGraph.Radius * Math.Cos(rad);
                    mg3d.Positions.Add(new Point3D(x, y, 1));
                    if (rad == _EndRadix)
                        break;
                    rad += RadStep;
                    if (rad > _EndRadix)
                        rad = _EndRadix;
                    steps++;
                }

                for (int i = placeMarker + 1; i <= steps + placeMarker; i++)
                {
                    mg3d.TriangleIndices.Add(placeMarker);
                    mg3d.TriangleIndices.Add(i + 1);
                    mg3d.TriangleIndices.Add(i);
                }

                // Create the outer edge.
                for (int i = 1, j = placeMarker + 1; i < steps; i++, j++)
                {
                    mg3d.TriangleIndices.Add(i);
                    mg3d.TriangleIndices.Add(j);
                    mg3d.TriangleIndices.Add(j + 1);
                    mg3d.TriangleIndices.Add(j + 1);
                    mg3d.TriangleIndices.Add(i + 1);
                    mg3d.TriangleIndices.Add(i);
                }

                // Create the ending edge.
                mg3d.TriangleIndices.Add(steps);
                mg3d.TriangleIndices.Add(steps + placeMarker);
                mg3d.TriangleIndices.Add(placeMarker);
                mg3d.TriangleIndices.Add(placeMarker);
                mg3d.TriangleIndices.Add(0);
                mg3d.TriangleIndices.Add(steps);

                // Create the leading edge.
                mg3d.TriangleIndices.Add(0);
                mg3d.TriangleIndices.Add(placeMarker);
                mg3d.TriangleIndices.Add(placeMarker + 1);
                mg3d.TriangleIndices.Add(placeMarker + 1);
                mg3d.TriangleIndices.Add(1);
                mg3d.TriangleIndices.Add(0);

                ScreenSpaceLines3D lines = new ScreenSpaceLines3D();
                lines.Color = Colors.Black;
                for (int i = 0; i <= steps; i++)
                    lines.Points.Add(mg3d.Positions[i]);
                lines.Points.Add(mg3d.Positions[0]);
                lines.Points.Add(mg3d.Positions[1]);
                lines.Points.Add(mg3d.Positions[placeMarker + 1]);
                lines.Points.Add(mg3d.Positions[placeMarker]);
                lines.Points.Add(mg3d.Positions[0]);
                lines.Points.Add(mg3d.Positions[steps]);
                lines.Points.Add(mg3d.Positions[placeMarker + steps]);
                for (int i = placeMarker; i <= placeMarker + steps; i++)
                    lines.Points.Add(mg3d.Positions[i]);
                lines.Points.Add(mg3d.Positions[placeMarker]);
                lines.Thickness = 1;
                _Outline = lines;

                _Geometry = new GeometryModel3D();
                _Geometry.Geometry = mg3d;
                MaterialGroup matg = new MaterialGroup();
                matg.Children.Add(new DiffuseMaterial(new SolidColorBrush(_Color)));
                matg.Children.Add(new SpecularMaterial(new SolidColorBrush(Colors.White), 85));
                _Geometry.Material = matg;
            }
        }
Exemple #10
0
 private static ScreenSpaceLines3D xa27fac46e21ed5f4(Point3D x54acfcf5460fb360, Point3D x08eef91ccd7eb033)
 {
     ScreenSpaceLines3D linesd;
     ScreenSpaceLines3D linesd2 = new ScreenSpaceLines3D {
         Thickness = 3.0
     };
     if (0 == 0)
     {
         linesd = linesd2;
         linesd.Points.Add(x54acfcf5460fb360);
     }
     linesd.Points.Add(x08eef91ccd7eb033);
     linesd.Color = Colors.BlueViolet;
     return linesd;
 }
 private void DrawLine(ScreenSpaceLines3D lineCollection, Point3D start, Point3D end)
 {
     lineCollection.Points.Add(start);
     lineCollection.Points.Add(end);
 }
        private ScreenSpaceLines3D DrawWireCube(Container v)
        {
            ScreenSpaceLines3D wireCube = new ScreenSpaceLines3D();
            Color c = Colors.Black;
            const int width = 2;
            Point3D p0 = new Point3D(v.FirstPoint.X, v.FirstPoint.Z, v.FirstPoint.Y);
            Point3D p1 = new Point3D(v.FirstPoint.X + v.Width, v.FirstPoint.Z, v.FirstPoint.Y);
            Point3D p2 = new Point3D(v.FirstPoint.X + v.Width, v.FirstPoint.Z, v.FirstPoint.Y + v.Length);
            Point3D p3 = new Point3D(v.FirstPoint.X, v.FirstPoint.Z, v.FirstPoint.Y + v.Length);
            Point3D p4 = new Point3D(v.FirstPoint.X, v.FirstPoint.Z + v.Height, v.FirstPoint.Y);
            Point3D p5 = new Point3D(v.FirstPoint.X + v.Width, v.FirstPoint.Z + v.Height, v.FirstPoint.Y);
            Point3D p6 = new Point3D(v.FirstPoint.X + v.Width, v.FirstPoint.Z + v.Height, v.FirstPoint.Y + v.Length);
            Point3D p7 = new Point3D(v.FirstPoint.X, v.FirstPoint.Z + v.Height, v.FirstPoint.Y + v.Length);

            wireCube.Thickness = width;
            wireCube.Color = c;
            //рисуем нижнюю грань
            wireCube.Points.Add(p0);
            wireCube.Points.Add(p1);
            wireCube.Points.Add(p1);
            wireCube.Points.Add(p2);
            wireCube.Points.Add(p2);
            wireCube.Points.Add(p3);
            wireCube.Points.Add(p3);
            wireCube.Points.Add(p0);
            //рисуем верхнюю грань
            wireCube.Points.Add(p4);
            wireCube.Points.Add(p5);
            wireCube.Points.Add(p5);
            wireCube.Points.Add(p6);
            wireCube.Points.Add(p6);
            wireCube.Points.Add(p7);
            wireCube.Points.Add(p7);
            wireCube.Points.Add(p4);

            //рисуем Боковую грань
            wireCube.Points.Add(p0);
            wireCube.Points.Add(p4);
            wireCube.Points.Add(p1);
            wireCube.Points.Add(p5);
            wireCube.Points.Add(p2);
            wireCube.Points.Add(p6);
            wireCube.Points.Add(p3);
            wireCube.Points.Add(p7);
            if (v.Kind == "VerticalPallet")
            {//рисуем диагональные линии на боковую грань
                wireCube.Points.Add(p6);
                wireCube.Points.Add(p3);
                wireCube.Points.Add(p2);
                wireCube.Points.Add(p7);
            }
            return wireCube;
        }
Exemple #13
0
        public Window2(CModel cmodel, bool bDebugging)
        {
            InitializeComponent();

              if (cmodel != null)
              {
              Model3DGroup gr = new Model3DGroup();
              //gr.Children.Add(new AmbientLight());

              // Default color
              SolidColorBrush brushDefault = new SolidColorBrush(Color.FromRgb(255, 0, 0));

              EGCS eGCS = EGCS.eGCSLeftHanded;
              //EGCS eGCS = EGCS.eGCSRightHanded;

              // Global coordinate system - axis
              ScreenSpaceLines3D sAxisX_3D = new ScreenSpaceLines3D();
              ScreenSpaceLines3D sAxisY_3D = new ScreenSpaceLines3D();
              ScreenSpaceLines3D sAxisZ_3D = new ScreenSpaceLines3D();
              Point3D pGCS_centre = new Point3D(0,0,0);
              Point3D pAxisX = new Point3D(1, 0, 0);
              Point3D pAxisY = new Point3D(0, 1, 0);
              Point3D pAxisZ = new Point3D(0, 0, 1);

              sAxisX_3D.Points.Add(pGCS_centre);
              sAxisX_3D.Points.Add(pAxisX);
              sAxisX_3D.Color = Colors.Red;
              sAxisX_3D.Thickness = 2;

              sAxisY_3D.Points.Add(pGCS_centre);
              sAxisY_3D.Points.Add(pAxisY);
              sAxisY_3D.Color = Colors.Green;
              sAxisY_3D.Thickness = 2;

              sAxisZ_3D.Points.Add(pGCS_centre);
              sAxisZ_3D.Points.Add(pAxisZ);
              sAxisZ_3D.Color = Colors.Blue;
              sAxisZ_3D.Thickness = 2;

              //I made ViewPort public property to Access ViewPort object inside TrackPort3D
              //to ViewPort add 3 children (3 axis)
              _trackport.ViewPort.Children.Add(sAxisX_3D);
              _trackport.ViewPort.Children.Add(sAxisY_3D);
              _trackport.ViewPort.Children.Add(sAxisZ_3D);

              // Check that real model exists and create model geometry
              if (cmodel != null)
              {
              if (cmodel.m_arrMembers != null) // Some members exist
              {
                  // Auxialiary for generation of colors numbers
                  float j = 0;

                  // Model Group of Members
                  // Prepare member model
                  for (int i = 0; i < cmodel.m_arrMembers.Length; i++) // !!! BUG pocet prvkov sa nacitava z xls aj z prazdnych riadkov pokial su nejako formatovane / nie default
                  {
                      if (cmodel.m_arrMembers[i] != null &&
                          cmodel.m_arrMembers[i].NodeStart != null &&
                          cmodel.m_arrMembers[i].NodeEnd != null &&
                          cmodel.m_arrMembers[i].CrScStart != null) // Member object is valid (not empty)
                      {
                          if (bDebugging)
                          {
                              System.Console.Write("\n" + "Member ID:" + (i + 1).ToString() + "\n"); // Write Member ID in console window
                              System.Console.Write("Start Node ID:" + cmodel.m_arrMembers[i].NodeStart.ID.ToString() + "\n"); // Write Start Node ID and coordinates in console window
                              System.Console.Write(cmodel.m_arrMembers[i].NodeStart.X.ToString() + "\t" + cmodel.m_arrMembers[i].NodeStart.Y.ToString() + "\t" + cmodel.m_arrMembers[i].NodeStart.Z.ToString() + "\n");
                              System.Console.Write("End Node ID:" + cmodel.m_arrMembers[i].NodeEnd.ID.ToString() + "\n");     // Write   End Node ID and coordinates in console window
                              System.Console.Write(cmodel.m_arrMembers[i].NodeEnd.X.ToString() + "\t" + cmodel.m_arrMembers[i].NodeEnd.Y.ToString() + "\t" + cmodel.m_arrMembers[i].NodeEnd.Z.ToString() + "\n\n");

                              cmodel.m_arrMembers[i].BIsDebugging = bDebugging;
                          }

                          if (cmodel.m_arrMembers[i].CrScStart.CrScPointsOut != null) // CCrSc is abstract without geometrical properties (dimensions), only centroid line could be displayed
                          {
                              // Member material color
                              byte R = (byte)(250);
                              byte G = (byte)(240);
                              byte B = (byte)(230);

                              SolidColorBrush br = new SolidColorBrush(Color.FromRgb(R, G, B)); // Material color
                              br.Opacity = 0.8;

                              // Set different color for each member
                              bool bDiffMemberColors = false;

                              if (bDiffMemberColors)
                              {
                                  if (j < 20) // 20*10 = 200, 200 + 55 - 255 (maxium number of color)
                                  {
                                      br.Color = Color.FromRgb((byte)(55 + j * 10), (byte)(55 + j * 7), (byte)(55 + j * 5));
                                      j++;
                                  }
                                  else
                                  {
                                      j = 0;
                                  }
                              }

                              bool bFastRendering = false;

                              if (bFastRendering ||
                                  (cmodel.m_arrMembers[i].CrScStart.TriangleIndicesFrontSide == null ||
                                      cmodel.m_arrMembers[i].CrScStart.TriangleIndicesShell == null ||
                                      cmodel.m_arrMembers[i].CrScStart.TriangleIndicesBackSide == null)
                                   ) // Check if are particular surfaces defined
                              {
                                  // Create Member model - one geometry model
                                  // GeometryModel3D memberModel3D;
                                  // Add current member model to the model group
                                  gr.Children.Add((Model3D)cmodel.m_arrMembers[i].getG_M_3D_Member(eGCS, br));
                              }
                              else
                              {
                                  // Create Member model - consist of 3 geometry models (member is one model group)
                                  // Model3DGroup memberModel3D;
                                  // Add current member model to the model group

                                  SolidColorBrush br1 = new SolidColorBrush(Color.FromRgb(255, 64, 64)); // Material color - Front Side (red)
                                  SolidColorBrush br2 = new SolidColorBrush(Color.FromRgb(141, 238, 238)); // Material color - Shell (red)
                                  SolidColorBrush br3 = new SolidColorBrush(Color.FromRgb(238, 154, 73)); // Material color - Back Side (orange)
                                  br1.Opacity = br3.Opacity = 0.8;
                                  br2.Opacity = 0.4;
                                  gr.Children.Add(cmodel.m_arrMembers[i].getM_3D_G_Member(eGCS, br1, br2, br3));
                              }
                          }
                          else
                          {
                          // Display axis line, member is not valid to display in 3D
                          }
                      }
                  }
              }

              if (cmodel.m_arrGOAreas != null) // Some areas exist
              {
                  // Model Groups of Areas

              }

              if (cmodel.m_arrGOVolumes != null) // Some volumes exist
              {
                  // Model Groups of Volumes
                  for (int i = 0; i < cmodel.m_arrGOVolumes.Length; i++)
                  {
                      if (cmodel.m_arrGOVolumes[i] != null &&
                          cmodel.m_arrGOVolumes[i].m_pControlPoint != null &&
                          cmodel.m_arrGOVolumes[i].BIsDisplayed == true) // Volume object is valid (not empty) and should be displayed
                      {
                          // Get shape - prism , sphere, ...
                          gr.Children.Add(cmodel.m_arrGOVolumes[i].CreateM_3D_G_Volume_8Edges()); // Add solid to model group
                      }
                  }
              }

              if (cmodel.m_arrGOStrWindows != null) // Some windows exist
              {
                  // Model Groups of Windows
                  for (int i = 0; i < cmodel.m_arrGOStrWindows.Length; i++)
                  {
                      if (cmodel.m_arrGOStrWindows[i] != null &&
                          cmodel.m_arrGOStrWindows[i].m_pControlPoint != null &&
                          cmodel.m_arrGOStrWindows[i].BIsDisplayed == true) // Volume object is valid (not empty) and should be displayed
                      {
                          if (cmodel.m_arrGOStrWindows[i].EShapeType == EWindowShapeType.eClassic)
                              gr.Children.Add(cmodel.m_arrGOStrWindows[i].CreateM_3D_G_Window()); // Add solid to model group
                          else
                          {
                              //Exception - not implemented
                          }
                      }
                  }
              }

              if (cmodel.m_arrNSupports != null) // Some nodal supports exist
              {
                  // Model Groups of Nodal Suports
                  for (int i = 0; i < cmodel.m_arrNSupports.Length; i++)
                  {
                      if (cmodel.m_arrNSupports[i] != null && cmodel.m_arrNSupports[i].BIsDisplayed == true) // Support object is valid (not empty) and should be displayed
                      {
                          gr.Children.Add(cmodel.m_arrNSupports[i].CreateM_3D_G_NSupport()); // Add solid to model group

                          // Set support for all assigned nodes

                      }
                  }
              }

              if (cmodel.m_arrNReleases != null) // Some member release exist
              {
                  // Model Groups of Member Releases
                  for (int i = 0; i < cmodel.m_arrNReleases.Length; i++)
                  {
                      if (cmodel.m_arrNReleases[i] != null && cmodel.m_arrNReleases[i].BIsDisplayed == true) // Support object is valid (not empty) and should be displayed
                      {
                          /*
                          for (int j = 0; j < cmodel.m_arrNReleases[i].m_iMembCollection.Length; j++) // Set release for all assigned members (member nodes)
                          {
                              Model3DGroup model_gr = new Model3DGroup();
                              model_gr = cmodel.m_arrNReleases[i].CreateM_3D_G_MNRelease();
                              // Transform modelgroup from LCS to GCS
                              model_gr = cmodel.m_arrNReleases[i].Transform3D_OnMemberEntity_fromLCStoGCS(model_gr, cmodel.m_arrMembers[cmodel.m_arrNReleases[i].m_iMembCollection[j]]);

                              gr.Children.Add(model_gr); // Add Release to model group
                          }*/

                          Model3DGroup model_gr = new Model3DGroup();
                          model_gr = cmodel.m_arrNReleases[i].CreateM_3D_G_MNRelease();
                          // Transform modelgroup from LCS to GCS
                          model_gr = cmodel.m_arrNReleases[i].Transform3D_OnMemberEntity_fromLCStoGCS(model_gr, cmodel.m_arrNReleases[i].Member);

                          gr.Children.Add(model_gr); // Add Release to model group

                      }
                  }
              }

              if (cmodel.m_arrNLoads != null) // Some nodal loads exist
              {
                  // Model Groups of Nodal Loads
                  for (int i = 0; i < cmodel.m_arrNLoads.Length; i++)
                  {
                      if (cmodel.m_arrNLoads[i] != null && cmodel.m_arrNLoads[i].BIsDisplayed == true) // Load object is valid (not empty) and should be displayed
                      {
                          gr.Children.Add(cmodel.m_arrNLoads[i].CreateM_3D_G_Load()); // Add to model group

                          // Set load for all assigned nodes

                      }
                  }
              }

              if (cmodel.m_arrMLoads != null) // Some member loads exist
              {
                  // Model Groups of Member Loads
                  for (int i = 0; i < cmodel.m_arrMLoads.Length; i++)
                  {
                      if (cmodel.m_arrMLoads[i] != null && cmodel.m_arrMLoads[i].BIsDisplayed == true) // Load object is valid (not empty) and should be displayed
                      {
                          Model3DGroup model_gr = new Model3DGroup();
                          model_gr = cmodel.m_arrMLoads[i].CreateM_3D_G_Load();
                          // Transform modelgroup from LCS to GCS
                          model_gr = cmodel.m_arrMLoads[i].Transform3D_OnMemberEntity_fromLCStoGCS(model_gr, cmodel.m_arrMLoads[i].Member);

                          gr.Children.Add(model_gr); // Add Release to model group

                          // Set load for all assigned member

                      }
                  }
              }

              /*
                The following lights derive from the base class Light:
                AmbientLight : Provides ambient lighting that illuminates all objects uniformly regardless of their location or orientation.
                DirectionalLight : Illuminates like a distant light source. Directional lights have a Direction specified as a Vector3D, but no specified location.
                PointLight : Illuminates like a nearby light source. PointLights have a position and cast light from that position. Objects in the scene are illuminated depending on their position and distance with respect to the light. PointLightBase exposes a Range property, which determines a distance beyond which models will not be illuminated by the light. PointLight also exposes attenuation properties which determine how the light's intensity diminishes over distance. You can specify constant, linear, or quadratic interpolations for the light's attenuation.
                SpotLight : Inherits from PointLight. Spotlights illuminate like PointLight and have both position and direction. They project light in a cone-shaped area set by InnerConeAngle and OuterConeAngle properties, specified in degrees.
              */

              // Directional Light
              DirectionalLight Dir_Light = new DirectionalLight();
              Dir_Light.Color = Colors.White;
              Dir_Light.Direction = new Vector3D(0, 0, -1);
              gr.Children.Add(Dir_Light);

              // Point light values
              PointLight Point_Light = new PointLight();
              Point_Light.Position = new Point3D(0, 0, 30);
              Point_Light.Color = System.Windows.Media.Brushes.White.Color;
              Point_Light.Range = 30.0;
              Point_Light.ConstantAttenuation=0;
              Point_Light.LinearAttenuation=0;
              Point_Light.QuadraticAttenuation = 0.2f;
              Point_Light.ConstantAttenuation = 5.0;
              gr.Children.Add(Point_Light);

              SpotLight Spot_Light = new SpotLight();
              Spot_Light.InnerConeAngle = 30;
              Spot_Light.OuterConeAngle = 30;
              Spot_Light.Color = System.Windows.Media.Brushes.White.Color;
              Spot_Light.Direction = new Vector3D(0, 0, -1);
              Spot_Light.Position = new Point3D(8.5, 8.5, 20);
              Spot_Light.Range = 30;
              gr.Children.Add(Spot_Light);

              //Set Ambient Light
              AmbientLight Ambient_Light = new AmbientLight();
              Ambient_Light.Color = Color.FromRgb(250, 250, 230);
              gr.Children.Add(new AmbientLight());

              if (cmodel.m_arrGOLines != null) // Some lines exist
              {
                  Point3D solidCenter = new Point3D(-5, 0, 0);

                  float fa = 0.5f;

                  Point3D p0 = new Point3D(-fa, -fa, -fa);
                  Point3D p1 = new Point3D(fa, -fa, -fa);
                  Point3D p2 = new Point3D(fa, fa, -fa);
                  Point3D p3 = new Point3D(-fa, fa, -fa);
                  Point3D p4 = new Point3D(-fa, -fa, fa);
                  Point3D p5 = new Point3D(fa, -fa, fa);
                  Point3D p6 = new Point3D(fa, fa, fa);
                  Point3D p7 = new Point3D(-fa, fa, fa);

                  // Lines

                  ScreenSpaceLines3D line1 = new ScreenSpaceLines3D();
                  ScreenSpaceLines3D line2 = new ScreenSpaceLines3D();
                  ScreenSpaceLines3D line3 = new ScreenSpaceLines3D();
                  ScreenSpaceLines3D line4 = new ScreenSpaceLines3D();

                  Color lineColor = Color.FromRgb(250, 30, 30);
                  line1.Color = lineColor;
                  line1.Points.Add(p0);
                  line1.Points.Add(p1);

                  line2.Color = lineColor;
                  line2.Points.Add(p1);
                  line2.Points.Add(p2);

                  line3.Color = lineColor;
                  line3.Points.Add(p2);
                  line3.Points.Add(p3);

                  line4.Color = lineColor;
                  line4.Points.Add(p3);
                  line4.Points.Add(p0);

                  _trackport.ViewPort.Children.Add(line1);
                  _trackport.ViewPort.Children.Add(line2);
                  _trackport.ViewPort.Children.Add(line3);
                  _trackport.ViewPort.Children.Add(line4);

                  ScreenSpaceLines3D line5 = new ScreenSpaceLines3D();
                  ScreenSpaceLines3D line6 = new ScreenSpaceLines3D();
                  ScreenSpaceLines3D line7 = new ScreenSpaceLines3D();
                  ScreenSpaceLines3D line8 = new ScreenSpaceLines3D();

                  line5.Color = lineColor;
                  line5.Points.Add(p4);
                  line5.Points.Add(p5);

                  line6.Color = lineColor;
                  line6.Points.Add(p5);
                  line6.Points.Add(p6);

                  line7.Color = lineColor;
                  line7.Points.Add(p6);
                  line7.Points.Add(p7);

                  line8.Color = lineColor;
                  line8.Points.Add(p7);
                  line8.Points.Add(p4);

                  _trackport.ViewPort.Children.Add(line5);
                  _trackport.ViewPort.Children.Add(line6);
                  _trackport.ViewPort.Children.Add(line7);
                  _trackport.ViewPort.Children.Add(line8);

                  ScreenSpaceLines3D line09 = new ScreenSpaceLines3D();
                  ScreenSpaceLines3D line10 = new ScreenSpaceLines3D();
                  ScreenSpaceLines3D line11 = new ScreenSpaceLines3D();
                  ScreenSpaceLines3D line12 = new ScreenSpaceLines3D();

                  line09.Color = lineColor;
                  line09.Points.Add(p0);
                  line09.Points.Add(p4);

                  line10.Color = lineColor;
                  line10.Points.Add(p1);
                  line10.Points.Add(p5);

                  line11.Color = lineColor;
                  line11.Points.Add(p2);
                  line11.Points.Add(p6);

                  line12.Color = lineColor;
                  line12.Points.Add(p3);
                  line12.Points.Add(p7);

                  _trackport.ViewPort.Children.Add(line09);
                  _trackport.ViewPort.Children.Add(line10);
                  _trackport.ViewPort.Children.Add(line11);
                  _trackport.ViewPort.Children.Add(line12);
              }
              }

              // Get model centre
              float fTempMax_X;
              float fTempMin_X;
              float fTempMax_Y;
              float fTempMin_Y;
              float fTempMax_Z;
              float fTempMin_Z;

              CalculateModelLimits(cmodel, out fTempMax_X, out fTempMin_X, out fTempMax_Y, out fTempMin_Y, out fTempMax_Z, out fTempMin_Z);

              float fModel_Length_X = fTempMax_X - fTempMin_X;
              float fModel_Length_Y = fTempMax_Y - fTempMin_Y;
              float fModel_Length_Z = fTempMax_Z - fTempMin_Z;

              Point3D pModelGeomCentre = new Point3D(fModel_Length_X / 2.0f, fModel_Length_Y / 2.0f, fModel_Length_Z / 2.0f);

              Point3D cameraPosition = new Point3D(pModelGeomCentre.X, pModelGeomCentre.Y + 300, pModelGeomCentre.Z + 100);

              //SolidColorBrush brush = new SolidColorBrush(Color.FromRgb(255, 255, 0));
              //GeometryModel3D model = getGeometryModel3D(brush, obj_CrSc, new Point3D(10, 10, 10), new Point3D(500, 300, 200));
              //gr.Children.Add(model);

              ////Point3D cameraPosition = ((MeshGeometry3D)model.Geometry).Positions[0];
              ////cameraPosition.Z -= 1000;

              //brush = new SolidColorBrush(Color.FromRgb(0, 255, 0));
              //model = getGeometryModel3D(brush, obj_CrSc, new Point3D(110, 110, 10), new Point3D(600, 400, 200));
              //gr.Children.Add(model);

              //IMPORTANT: this is the best way to do it, but we can't use it because of trackball
              //because camera is set by trackball Transform this.Camera.Transform = _trackball.Transform;
              //and headlite too:  this.Headlight.Transform = _trackball.Transform;

              _trackport.PerspectiveCamera.Position = cameraPosition;
              //_trackport.PerspectiveCamera.LookDirection = new Vector3D(cameraPosition.X, cameraPosition.Y, cameraPosition.Z - 100);

              _trackport.PerspectiveCamera.LookDirection = new Vector3D(0, -1, -0.2);

              _trackport.Model = (Model3D)gr;

              _trackport.SetupScene();
              }
        }
Exemple #14
0
        private void drawAxis(double x, double y, double z)
        {
            ScreenSpaceLines3D x_axis = new ScreenSpaceLines3D();
            ScreenSpaceLines3D y_axis = new ScreenSpaceLines3D();
            ScreenSpaceLines3D z_axis = new ScreenSpaceLines3D();
            x_axis.Color = Colors.Red;
            y_axis.Color = Colors.Green;
            z_axis.Color = Colors.Blue;

            x_axis.Points.Add(new Point3D(x, y, z));
            x_axis.Points.Add(new Point3D(x+20, y, z));

            y_axis.Points.Add(new Point3D(x, y, z));
            y_axis.Points.Add(new Point3D(x, y+20, z));

            z_axis.Points.Add(new Point3D(x, y, z));
            z_axis.Points.Add(new Point3D(x, y, z+20));

            Viewport.Children.Add(x_axis);
            Viewport.Children.Add(y_axis);
            Viewport.Children.Add(z_axis);
        }
        void OnCompositionTargetRendering(object sender, EventArgs e)
        {
            if (ShowLinesVisual3D && lines==null)
            {
                lines = new LinesVisual3D { Color = Colors.Blue };
                view1.Children.Add(lines);
            }
            if (!ShowLinesVisual3D && lines!=null)
            {
                lines.IsRendering = false;
                view1.Children.Remove(lines);
                lines = null;
            }
            if (ShowPointsVisual3D && points == null)
            {
                points = new PointsVisual3D { Color = Colors.Red, Size=6 };
                view1.Children.Add(points);
            }
            if (!ShowPointsVisual3D && points != null)
            {
                points.IsRendering = false;
                view1.Children.Remove(points);
                points = null;
            }
            if (ShowScreenSpaceLines3D && screenSpaceLines == null)
            {
                screenSpaceLines = new ScreenSpaceLines3D { Color = Colors.Green };
                view1.Children.Add(screenSpaceLines);
            }
            if (!ShowScreenSpaceLines3D && screenSpaceLines != null)
            {
                view1.Children.Remove(screenSpaceLines);
                screenSpaceLines = null;
            }
            if (ShowWireLines && wireLines == null)
            {
                wireLines = new WireLines { Color = Colors.Pink };
                view1.Children.Add(wireLines);
            }
            if (!ShowWireLines && wireLines != null)
            {
                view1.Children.Remove(wireLines);
                wireLines = null;
            }

            if (Points==null || Points.Count != N || isAnimating)
            {
                Points = GeneratePoints(N, watch.ElapsedMilliseconds*0.001);
                RaisePropertyChanged("Points");
            }

            if (lines != null)
                lines.Points = Points;
            if (points != null)
                points.Points = Points;
            if (screenSpaceLines != null)
                screenSpaceLines.Points = Points;
            if (wireLines != null)
                wireLines.Lines = Points;
        }
Exemple #16
0
        private Model3DGroup createlines(Point3D pt, Viewport3D viewport)
        {
            Model3DGroup normalGroup = new Model3DGroup();
            Point3D p = pt;
            int length = 1;
            double partx, party;

            #region lines
            ScreenSpaceLines3D normal0Wire = new ScreenSpaceLines3D();
            normal0Wire.Thickness = 5;
            normal0Wire.Color = Colors.Blue;

            if (pt.X > pt.Y)
            {
                partx = 1; party = pt.Y / pt.X;
            }
            else
            {
                partx = pt.X / pt.Y; party = 1;
            }

            normal0Wire.Points.Add(pt);
            for (int i = 0; i < length; i++)
            {
                p = new Point3D(pt.X + ((i + 1) * partx), pt.Y + ((i + 1) * party), pt.Z);
                normal0Wire.Points.Add(p);
                normal0Wire.Points.Add(p);
            }
            normal0Wire.Points.Add(p);
            viewport.Children.Add(normal0Wire);
            #endregion
            #region arrowhead

            MeshGeometry3D triangleMesh = new MeshGeometry3D();
            Point3D point0 = new Point3D(p.X + 0.05, p.Y, p.Z);
            Point3D point1 = new Point3D(p.X, p.Y + 0.05, p.Z);
            Point3D point2 = new Point3D(p.X, p.Y, p.Z + 0.05);
            triangleMesh.Positions.Add(point0);
            triangleMesh.Positions.Add(point1);
            triangleMesh.Positions.Add(point2);
            triangleMesh.TriangleIndices.Add(0);
            triangleMesh.TriangleIndices.Add(1);
            triangleMesh.TriangleIndices.Add(2);
            Vector3D normal = new Vector3D(0, 1, 0);
            triangleMesh.Normals.Add(normal);
            triangleMesh.Normals.Add(normal);
            triangleMesh.Normals.Add(normal);

            Material material = new DiffuseMaterial(
                new SolidColorBrush(Colors.Blue));
            GeometryModel3D triangleModel = new GeometryModel3D(
                triangleMesh, material);
            ModelVisual3D model = new ModelVisual3D();
            model.Content = triangleModel;
            viewport.Children.Add(model);

            #endregion
            return normalGroup;
        }
Exemple #17
0
        private Model3DGroup CreateTriangleModel(Point3D p0, Point3D p1, Point3D p2)
        {
            MeshGeometry3D mesh = new MeshGeometry3D();
            mesh.Positions.Add(p0);
            mesh.Positions.Add(p1);
            mesh.Positions.Add(p2);
            mesh.TriangleIndices.Add(0);
            mesh.TriangleIndices.Add(1);
            mesh.TriangleIndices.Add(2);
            Vector3D normal = CalculateNormal(p0, p1, p2);
            mesh.Normals.Add(normal);
            mesh.Normals.Add(normal);
            mesh.Normals.Add(normal);
            Material material = new DiffuseMaterial(
                new SolidColorBrush(Colors.DarkKhaki));
            GeometryModel3D model = new GeometryModel3D(
                mesh, material);
            Model3DGroup group = new Model3DGroup();
            group.Children.Add(model);

            if (normalsCheckBox.IsChecked == true)
                group.Children.Add(BuildNormals(p0, p1, p2, normal));

            if (wireframeCheckBox.IsChecked == true)
            {
                ScreenSpaceLines3D wireframe = new ScreenSpaceLines3D();
                wireframe.Points.Add(p0);
                wireframe.Points.Add(p1);
                wireframe.Points.Add(p2);
                wireframe.Points.Add(p0);
                wireframe.Color = Colors.LightBlue;
                wireframe.Thickness = 3;

                this.mainViewport.Children.Add(wireframe);
            }

            return group;
        }
Exemple #18
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.perspcam = ((System.Windows.Media.Media3D.PerspectiveCamera)(target));
                return;

            case 2:
                this.ssl3dX = ((_3DTools.ScreenSpaceLines3D)(target));
                return;

            case 3:
                this.ssl3dY = ((_3DTools.ScreenSpaceLines3D)(target));
                return;

            case 4:
                this.ssl3dZ = ((_3DTools.ScreenSpaceLines3D)(target));
                return;

            case 5:
                this.ssl3dconnect = ((_3DTools.ScreenSpaceLines3D)(target));
                return;

            case 6:
                this.vrsta0 = ((System.Windows.Controls.TextBox)(target));
                return;

            case 7:
                this.vrijednost0 = ((System.Windows.Controls.TextBox)(target));

            #line 69 "..\..\MainWindow.xaml"
                this.vrijednost0.PreviewTextInput += new System.Windows.Input.TextCompositionEventHandler(this.PreviewTextInput);

            #line default
            #line hidden
                return;

            case 8:
                this.button1 = ((System.Windows.Controls.Button)(target));

            #line 70 "..\..\MainWindow.xaml"
                this.button1.Click += new System.Windows.RoutedEventHandler(this.button1_Click);

            #line default
            #line hidden
                return;

            case 9:
                this.lvVrijednosti0 = ((System.Windows.Controls.ListView)(target));
                return;

            case 10:
                this.vrsta1 = ((System.Windows.Controls.TextBox)(target));
                return;

            case 11:
                this.vrijednost1 = ((System.Windows.Controls.TextBox)(target));

            #line 90 "..\..\MainWindow.xaml"
                this.vrijednost1.PreviewTextInput += new System.Windows.Input.TextCompositionEventHandler(this.PreviewTextInput);

            #line default
            #line hidden
                return;

            case 12:
                this.button2 = ((System.Windows.Controls.Button)(target));

            #line 91 "..\..\MainWindow.xaml"
                this.button2.Click += new System.Windows.RoutedEventHandler(this.button2_Click);

            #line default
            #line hidden
                return;

            case 13:
                this.lvVrijednosti1 = ((System.Windows.Controls.ListView)(target));
                return;

            case 14:
                this.vrsta2 = ((System.Windows.Controls.TextBox)(target));
                return;

            case 15:
                this.vrijednost2 = ((System.Windows.Controls.TextBox)(target));

            #line 111 "..\..\MainWindow.xaml"
                this.vrijednost2.PreviewTextInput += new System.Windows.Input.TextCompositionEventHandler(this.PreviewTextInput);

            #line default
            #line hidden
                return;

            case 16:
                this.button3 = ((System.Windows.Controls.Button)(target));

            #line 112 "..\..\MainWindow.xaml"
                this.button3.Click += new System.Windows.RoutedEventHandler(this.button3_Click);

            #line default
            #line hidden
                return;

            case 17:
                this.lvVrijednosti2 = ((System.Windows.Controls.ListView)(target));
                return;

            case 18:
                this.buttonPlus = ((System.Windows.Controls.Button)(target));

            #line 122 "..\..\MainWindow.xaml"
                this.buttonPlus.Click += new System.Windows.RoutedEventHandler(this.buttonPlus_Click);

            #line default
            #line hidden
                return;

            case 19:
                this.buttonMinus = ((System.Windows.Controls.Button)(target));

            #line 123 "..\..\MainWindow.xaml"
                this.buttonMinus.Click += new System.Windows.RoutedEventHandler(this.buttonMinus_Click);

            #line default
            #line hidden
                return;

            case 20:
                this.buttonReset = ((System.Windows.Controls.Button)(target));

            #line 124 "..\..\MainWindow.xaml"
                this.buttonReset.Click += new System.Windows.RoutedEventHandler(this.buttonReset_Click);

            #line default
            #line hidden
                return;

            case 21:
                this.slider = ((System.Windows.Controls.Slider)(target));
                return;
            }
            this._contentLoaded = true;
        }
        private void OnCompositionTargetRendering(object sender, EventArgs e)
        {
            if (this.ShowLinesVisual3D && this.linesVisual == null)
            {
                this.linesVisual = new LinesVisual3D { Color = Colors.Blue };
                View1.Children.Add(this.linesVisual);
            }

            if (!this.ShowLinesVisual3D && this.linesVisual != null)
            {
                this.linesVisual.IsRendering = false;
                View1.Children.Remove(this.linesVisual);
                this.linesVisual = null;
            }

            if (this.ShowPointsVisual3D && this.pointsVisual == null)
            {
                this.pointsVisual = new PointsVisual3D { Color = Colors.Red, Size = 6 };
                View1.Children.Add(this.pointsVisual);
            }

            if (!this.ShowPointsVisual3D && this.pointsVisual != null)
            {
                this.pointsVisual.IsRendering = false;
                View1.Children.Remove(this.pointsVisual);
                this.pointsVisual = null;
            }

            if (this.ShowScreenSpaceLines3D && this.screenSpaceLines == null)
            {
                this.screenSpaceLines = new ScreenSpaceLines3D { Color = Colors.Green };
                View1.Children.Add(this.screenSpaceLines);
            }

            if (!this.ShowScreenSpaceLines3D && this.screenSpaceLines != null)
            {
                View1.Children.Remove(this.screenSpaceLines);
                this.screenSpaceLines = null;
            }

            if (this.ShowWireLines && this.wireLines == null)
            {
                this.wireLines = new WireLines { Color = Colors.Pink };
                View1.Children.Add(this.wireLines);
            }

            if (!this.ShowWireLines && this.wireLines != null)
            {
                View1.Children.Remove(this.wireLines);
                this.wireLines = null;
            }

            if (this.Points == null || this.Points.Count != this.NumberOfPoints)
            {
                this.Points = new Point3DCollection(GeneratePoints(this.NumberOfPoints, this.watch.ElapsedMilliseconds * 0.001));
            }

            if (this.linesVisual != null)
            {
                this.linesVisual.Points = this.Points;
            }

            if (this.pointsVisual != null)
            {
                this.pointsVisual.Points = this.Points;
            }

            if (this.screenSpaceLines != null)
            {
                this.screenSpaceLines.Points = this.Points;
            }

            if (this.wireLines != null)
            {
                this.wireLines.Lines = this.Points;
            }
        }