Beispiel #1
0
        public bool Cross(List <TriangleF> Triangles, xyzArray Poly, ref double Lam, ref xyz Pt)
        {
            for (int j = 0; j < Triangles.Count; j++)
            {
                Plane P = new Plane(Triangles[j].A.Toxyz(), (Triangles[j].B - Triangles[j].A).Toxyz() & (Triangles[j].C - Triangles[j].A).Toxyz());
                for (int i = 0; i < Poly.Count - 1; i++)
                {
                    Lam = -1;
                    xyz Pkt = new xyz(0, 0, 0);

                    if (P.Cross(new LineType(Poly[i], (Poly[i + 1] - Poly[i])), out Lam, out Pkt))
                    {
                        if ((-0.000001 <= Lam) && (Lam <= 1.00000001))
                        {
                            if (Triangles[j].Inside(Pkt.toXYZF()))
                            {
                                Pt   = Pkt;
                                Lam += i;
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }
Beispiel #2
0
        protected internal override xyz Cross(LineType ViewLine)
        {
            double vz = ViewLine.Direction.z;

            if (ViewLine.Direction.z == 0)
            {
                return(new xyz(0, 0, 0));
            }
            xyzArray A = Curve.ToxyzArray();

            double LineLam = -1;
            double di      = A.Distance(ViewLine, 2 * Snapdist, out Lam, out LineLam);

            if (di <= 2 * Snapdist)
            {
                Lam /= Curve.Resolution;
                return(Curve.Value(Lam));
            }
            else
            {
                Lam = -1;
            }
            xyz Result = new xyz(0, 0, 0);

            new Plane(new xyz(0, 0, 0), new xyz(0, 0, 1)).Cross(ViewLine, out LineLam, out Result);
            return(Result);
        }
Beispiel #3
0
        public override xyzArray getxyzArray()
        {
            xyzArray M = new xyzArray(2);

            M[0] = A;
            M[1] = B;
            return(this.ModelMatrix * M);
        }
Beispiel #4
0
        bool intersectPlaneWithLine(SnapItem Plane, SnapItem Line, xyzArray LineArray, ref double Lam, ref xyz Result)
        {
            TriangleF T = Plane.GetTriangle();

            if (T == null)
            {
                return(false);
            }
            xyz N1 = ((T.B - T.A) & (T.C - T.A)).Toxyz();

            if (LineArray == null)
            {
            }
            xyz N2 = LineArray.cross();

            if ((N1 & N2).length() < 0.00001)   // Parallel
            {
                xyzArray A = Plane.getxyzArray();
                if (A != null)
                {
                    xyzArray         B = LineArray;
                    List <CrossTag1> L = CrossTag1.GetCrossList(A, B);

                    for (int i = 0; i < L.Count; i++)
                    {
                        if (A.Value(L[i].Lam1).dist(Plane.Point) <= SnapItem.Snapdist)
                        {
                            Lam = L[i].Lam1;

                            Result = A.Value(L[i].Lam1);
                            return(true);
                        }
                    }
                }
            }

            int Object = StoredSnapItems.IndexOf(Plane);
            int siz    = SnapDistance * 2 + 1;

            //  int siz = SnapDistance;
            Drawing3d.PrimIdObj[,] P = SubArray(Device.MousePos.X - siz / 2, (int)Device.ViewPort.Height - Device.MousePos.Y - siz / 2, siz, siz);
            List <TriangleF> LT = GetTriangles(P, Object);

            Lam = -1;



            bool R = Cross(LT, LineArray, ref Lam, ref Result);

            return(R);
        }
Beispiel #5
0
        xyz Nearest(LineType L, xyzf A, xyzf B, xyzf C)
        {
            xyzArray M = new xyzArray(4);

            M[0] = A.Toxyz();
            M[1] = B.Toxyz();
            M[2] = C.Toxyz();
            M[3] = A.Toxyz();
            double Param   = -1;
            double LineLam = -1;
            double n       = M.Distance(L, 1e10, out Param, out LineLam);

            return(M.Value(Param));
        }
Beispiel #6
0
        public override Base GetBase()
        {
            xyzArray A = ModelMatrix * CurveArray.getxyArray().ToxyzArray();

            Base B = ModelMatrix.toBase();

            B.BaseO = Point;
            if (Lam >= 0)
            {
                xyz D = ModelMatrix * CurveArray.Direction(Lam).toXYZ() - ModelMatrix * new xyz(0, 0, 0);
                B = Base.DoComplete(Point, D, new xyz(0, 0, 1) & D);
            }
            return(B);
        }
Beispiel #7
0
        bool IntersectLines(xyzArray A, xyzArray B, xyz NearPoint, ref xyz CrossPoint)
        {
            List <CrossTag1> L = CrossTag1.GetCrossList(A, B);

            for (int i = 0; i < L.Count; i++)
            {
                if (A.Value(L[i].Lam1).dist(NearPoint) <= SnapItem.Snapdist)
                {
                    CrossPoint = A.Value(L[i].Lam1);

                    return(true);
                }
            }
            return(false);
        }
Beispiel #8
0
        public override xyzArray getxyzArray()
        {
            xyzArray Result = new xyzArray();
            int      id     = 0;
            int      ct     = 2 * (Surface.UResolution + 1) + 2 * (Surface.VResolution + 1);

            Result.data = new xyz[ct];
            int k = Result.Count;

            for (int i = 0; i <= Surface.UResolution; i++)
            {
                double u = (double)i / (double)Surface.UResolution;
                double v = 0;
                Result.data[id] = Surface.Value(u, v);
                id++;
            }


            for (int i = 0; i <= Surface.VResolution; i++)
            {
                double v = (double)i / (double)Surface.VResolution;
                double u = 1;
                Result.data[id] = Surface.Value(u, v);
                id++;
            }

            for (int i = Surface.UResolution; i >= 0; i--)
            {
                double u = (double)i / (double)Surface.UResolution;
                double v = 1;
                Result.data[id] = Surface.Value(u, v);
                id++;
            }
            for (int i = Surface.VResolution; i >= 0; i--)
            {
                double v = (double)i / (double)Surface.VResolution;
                double u = 0;
                xyz    U = Surface.Value(u, v);
                Result.data[id] = U;
                id++;
                xyz II = Result.data[i];
            }
            Result.data[Surface.UResolution] = Surface.Value(1, 0);



            return(Result);
        }
Beispiel #9
0
        bool IntersectLineWithLine(SnapItem Line1, SnapItem Line2, LineType ViewLine)
        {
            xyzArray A  = Line1.getxyzArray();
            int      h  = A.Count;
            xyzArray B  = Line2.getxyzArray();
            double   d1 = 1e10;
            int      i1 = -1;
            double   d2 = 1e10;
            int      i2 = -1;

            for (int i = 0; i < A.Count; i++)
            {
                double d = Line1.Point.dist(A[i]);
                if (d < d1)
                {
                    d1 = d;
                    i1 = i;
                }
            }
            for (int i = 0; i < B.Count; i++)
            {
                double d = Line1.Point.dist(B[i]);
                if (d < d2)
                {
                    d2 = d;
                    i2 = i;
                }
            }
            if ((A == null) || (B == null))
            {
                return(false);
            }
            xyz CrossPoint = new xyz(0, 0, 0);

            if (IntersectLines(A, B, Line1.Point, ref CrossPoint))
            {
                Line1.Point   = CrossPoint;
                Line2.Point   = CrossPoint;
                Line1.Crossed = true;
                Line2.Crossed = true;
                return(true);
            }

            return(false);
        }
Beispiel #10
0
        void IntersectLines(List <xyzArray> Arrays, List <SnapItem> Snap)
        {
            xyzArray         A = Arrays[0];
            xyzArray         B = Arrays[1];
            List <CrossTag1> L = CrossTag1.GetCrossList(A, B);

            for (int i = 0; i < L.Count; i++)
            {
                if (A.Value(L[i].Lam1).dist(Snap[0].Point) <= SnapItem.Snapdist)
                {
                    Snap[0].Point   = A.Value(L[i].Lam1);
                    Snap[1].Point   = Snap[0].Point;
                    Snap[0].Crossed = true;
                    Snap[1].Crossed = true;
                    break;
                }
            }
        }
Beispiel #11
0
        internal static List <CrossTag1> GetCrossList1(xyzArray A, xyzArray B)
        {
            List <CrossTag1> Result = new List <CrossTag1>();

            for (int i = 0; i < A.Count - 1; i++)
            {
                LineType L1 = new LineType(A[i], A[i + 1] - A[i]);
                for (int j = 0; j < B.Count - 1; j++)
                {
                    LineType L2   = new LineType(B[j], B[j + 1] - B[j]);
                    double   Lam1 = -1;
                    double   Lam2 = -1;
                    if (Cross(L1, L2, ref Lam1, ref Lam2))
                    {
                        Result.Add(new CrossTag1(i + Lam1, j + Lam2));
                    }
                }
            }
            return(Result);
        }
Beispiel #12
0
        protected internal override xyz Cross(LineType ViewLine)
        {
            xyzArray A = Curve.ToXYArray().ToxyzArray();

            double LineLam = -1;
            double di      = A.Distance(ViewLine, 2 * Snapdist, out Lam, out LineLam);

            if (di <= 2 * Snapdist)
            {
                doExchange = true;
                Lam        = Lam / Curve.Resolution;
                return(Curve.Value(Lam).toXYZ());
            }
            else
            {
                Lam = -1;
            }
            xyz Result = new xyz(0, 0, 0);

            new Plane(new xyz(0, 0, 0), new xyz(0, 0, 1)).Cross(ViewLine, out LineLam, out Result);
            return(Result);
        }
Beispiel #13
0
        public static bool Cross(TriangleF t1, TriangleF t2, out double Lam, out double Mue, out xyz P, out xyz Q)
        {
            xyzArray A = new xyzArray();
            xyzArray B = new xyzArray();

            A.data = new xyz[] { t1.A.Toxyz(), t1.B.Toxyz(), t1.C.Toxyz() };
            B.data = new xyz[] { t2.A.Toxyz(), t2.B.Toxyz(), t2.C.Toxyz() };
            Lam    = -1;
            Mue    = -1;
            P      = new Drawing3d.xyz(0, 0, 0);
            Q      = new Drawing3d.xyz(0, 0, 0);

            double d = (A.Distance(B, 1e10, out Lam, out Mue));

            if (d < 2)
            {
                P = A.Value(Lam);
                Q = B.Value(Mue);
                return(true);
            }
            return(false);
        }
Beispiel #14
0
        public override Base GetBase()
        {
            Base B = ModelMatrix.toBase();;

            B.BaseO = Point;
            int id = -1;

            for (int i = 0; i < PolyPoly.Count; i++)
            {
                xyArray  A        = PolyPoly[i];
                LineType ViewLine = Device.FromScr(Device.MousePos);
                double   Dummy    = -1;
                double   di       = A.Distance(ViewLine, 2 * Snapdist, out Lam, out Dummy);
                if (di <= 2 * Snapdist)
                {
                    id = i;
                    break;
                }
            }
            if (id >= 0)
            {
                xyzArray A = ModelMatrix * PolyPoly[id].ToxyzArray();
                if (Lam >= 0)
                {
                    xyz D = ModelMatrix * PolyPoly[id].Direction(Lam).toXYZ() - ModelMatrix * new xyz(0, 0, 0);
                    B = Base.DoComplete(Point, D, new xyz(0, 0, 1) & D);
                }
            }
            else
            {
                xyzArray A = ModelMatrix * PolyPoly[0].ToxyzArray();
                xyz      D = A.cross();
                B = Base.DoComplete(Point, D, new xyz(0, 0, 1) & D);
            }
            return(B);
        }
Beispiel #15
0
 public PolyLineSnapItem3D(xyzArray Poly)
 {
     this.Poly = Poly;
 }
Beispiel #16
0
        public void SetEntityKind(Entitykind Kind)
        {
            Entities = Kind;

            if (Entities != Entitykind.CtrlRectangle)
            {
                if (CRect != null)
                {
                    CRect.Device = null;
                }
            }
            switch (Entities)

            {
            case Entitykind.Boxentity:
            {
                Box = new BoxEntity(new xyz(0, 0, 0), new xyz(4, 5, 6));

                break;
            }

            case Entitykind.PolyCurveExtruder:
            {
                PolyCurveEx = new PolyCurveExtruder();
                Loca       _Loca   = new Loca();
                CurveArray Curves0 = new CurveArray();
                Curves0.Count = 4;
                Curves0[0]    = new Line(new xy(-3, -3), new xy(-3, 4));
                Curves0[1]    = new Line(new xy(-3, 4), new xy(4, 4));
                Curves0[2]    = new Line(new xy(4, 4), new xy(4, -3));
                Curves0[3]    = new Line(new xy(4, -3), new xy(-3, -3));

                _Loca.Add(Curves0);
                OpenGlDevice.CheckError();
                CurveArray Curves1 = new CurveArray();
                Curves1.Count = 4;
                Curves1[0]    = new Line(new xy(0, 0), new xy(1, 0));
                Curves1[1]    = new Line(new xy(1, 0), new xy(1, 1));
                Curves1[2]    = new Line(new xy(1, 1), new xy(0, 1));
                Curves1[3]    = new Line(new xy(0, 1), new xy(0, 0));
                _Loca.Add(Curves1);

                PolyCurveEx.DownPlane     = new Plane(new xyz(0, 0, 0), new xyz(0, 0, 1));
                PolyCurveEx.UpPlane       = new Plane(new xyz(0, 0, 4), new xyz(0, 0.5, 1));
                PolyCurveEx.Loca          = _Loca;
                PolyCurveEx.ShowUpPlane   = true;
                PolyCurveEx.ShowDownPlane = true;
                PolyCurveEx.Height        = -1;
                PolyCurveEx.Direction     = new xyz(0, 1, 1);
                break;
            }

            case Entitykind.CoordinateAxis:
            {
                Axis                   = new CoordinateAxis();
                Axis.FullSize          = true;
                Axis.ShowText          = true;
                Axis.TextHeight        = 1;
                Axis.Color             = Color.Black;
                Axis.Size              = new xyz(10, 20, 30);
                Axis.Devider           = new xyz(4, 4, 4);
                Axis.DeviderLineLength = 0.3;
                Axis.LeftAndRight      = true;
                Axis.Dim3d             = true;
                Axis.ShowDevider       = true;
                break;
            }

            case Entitykind.TextEntity:
            {
                Text      = new TextEntity();
                Text.Text = "Drawing3d";

                Text.Size     = 4;
                Text.Italic   = true;
                Text.Position = new xyz(-5, 0, 0);
                break;
            }

            case Entitykind.Interpolator:

            {
                Interpolator        = new Interpolator3D();
                Interpolator.Points = new xyz[, ]
                {
                    { new xyz(-3, -3, 0), new xyz(-3, 0, 2), new xyz(-3, 3, 0), new xyz(-3, 6, -2) },
                    { new xyz(0, -3, 2), new xyz(0, 0, 3), new xyz(0, 3, 2), new xyz(0, 6, -2) },
                    { new xyz(3, -3, 3), new xyz(3, 0, 2), new xyz(3, 3, 1), new xyz(3, 6, -2) },
                    { new xyz(6, -3, 2), new xyz(6, 0, 0), new xyz(6, 3, 0), new xyz(6, 6, -2) }
                };

                break;
            };



            case Entitykind.Zoom:

            {
                Zoom        = new RectCtrlZoom(this);
                Zoom.Device = this;
                Zoom.Color  = Color.White;
                break;
            }

            case Entitykind.CtrlRectangle:

            {
                CRect               = new CtrlRectangle(this);
                CRect.Color         = Color.Black;
                CRect.MarkerColor   = Color.Red;
                CRect.Creating      = false;
                CRect.Rectangle     = new RectangleF(-1, -1, 6, 5);
                CRect.CompileEnable = false;
                Triangle            = new xyArray();
                Triangle.data       = new xy[] { new xy(0, 0), new xy(2, 2), new xy(4, 0), new xy(0, 0) };
                CRect.TransformItems.Add(Triangle);

                // S = new SphereEntity(new xyz(0, 0, 0), 2);
                //S = new BoxEntity(new xyz(0, 0, 0), new xyz(4, 4, 4));
                //S.CompileEnable = false;
                // CRect.TransformItems.Add(S);
                // CRect.LiveTransform = true;
                break;
            }

            case Entitykind.Profiler:

            {
                xyzArray A = new xyzArray();
                A.data = new xyz[] { new xyz(-3, 0, 0), new xyz(-3, -4, 0), new xyz(3, -4, 0), new xyz(3, 0, 0) };
                Loca       _Loca   = new Loca();
                CurveArray Curves0 = new CurveArray();
                Curves0.Count = 4;
                Curves0[0]    = new Line(new xy(-1, -1), new xy(-1, 2));
                Curves0[1]    = new Line(new xy(-1, 2), new xy(2, 2));
                Curves0[2]    = new Line(new xy(2, 2), new xy(2, -1));
                Curves0[3]    = new Line(new xy(2, -1), new xy(-1, -1));
                _Loca.Add(Curves0);
                OpenGlDevice.CheckError();
                CurveArray Curves1 = new CurveArray();
                Curves1.Count = 4;
                Curves1[0]    = new Line(new xy(0, 0), new xy(1, 0));
                Curves1[1]    = new Line(new xy(1, 0), new xy(1, 1));
                Curves1[2]    = new Line(new xy(1, 1), new xy(0, 1));
                Curves1[3]    = new Line(new xy(0, 1), new xy(0, 0));
                _Loca.Add(Curves1);
                Profil = new Profiler();
                Profil.CompileEnable = false;
                Profil.Trace         = A;
                Profil.Transverse    = _Loca;
                Profil.CloseFirst    = true;
                Profil.CloseLast     = true;
                break;
            }

            case Entitykind.ActiveCursor:
            {
                //  ActiveC.CrossColor = Color.Red;
                break;
            }

            case Entitykind.SphereEntity:
            {
                Sphere = new SphereEntity(new xyz(3, 2, 1), 4);
                //  Sphere.CompileEnable = false;
                //  Sphere = new SphereEntity(new xyz(0, 0, 0), 4);
                break;
            }

            case Entitykind.Cone:
            {
                Cone = new Cone(3, 5);
                break;
            }

            case Entitykind.Arrow:
            {
                Arrow = new Arrow();
                Arrow.Transformation = Matrix.Translation(new xyz(5, 0, 0));
                Arrow.SetShaftAndTop(new xyz(-10, 0, 0), new xyz(0, 0, 0));
                Arrow.Size = 8;
                drawSphere(new xyz(0, 0, 0), 0.5);
                break;
            }
            }


            Selector.RefreshSnapBuffer();
        }
Beispiel #17
0
        public bool IntersectPlaneWithPlane(SnapItem Plane1, SnapItem Plane2, LineType ViewLine)
        {
            int Object1 = StoredSnapItems.IndexOf(Plane1);
            int Object2 = StoredSnapItems.IndexOf(Plane2);
            int siz     = 2 * SnapDistance + 1;

            PrimIdObj[,] P   = SubArray(Device.MousePos.X - siz / 2, (int)Device.ViewPort.Height - Device.MousePos.Y - siz / 2, siz, siz);
            ListOfTriangles1 = GetTriangles(P, Object1);
            ListOfTriangles1.Clear();
            Matrix M = Plane1.ModelMatrix;

            for (int i = 0; i < Plane1.TriangleInfo.Indices.Length; i++)
            {
                TriangleInfo TI = Plane1.TriangleInfo;
                TriangleF    T  = new TriangleF(M * TI.Points[TI.Indices[i]], M * TI.Points[TI.Indices[i + 1]], M * TI.Points[TI.Indices[i + 2]]);
                i = i + 2;
                //   if (T.Inside(ViewLine.P.toXYZF()))
                ListOfTriangles1.Add(T);
            }
            for (int i = 0; i < ListOfTriangles1.Count; i++)
            {
                if (ListOfTriangles1[i].Inside(ViewLine.P.toXYZF()))
                {
                    TriangleF F = ListOfTriangles1[i];
                    ListOfTriangles1.RemoveAt(i);
                    ListOfTriangles1.Insert(0, F);
                }
            }
            ListOfTriangles2 = GetTriangles(P, Object2);
            ListOfTriangles2.Clear();
            M = Plane2.ModelMatrix;
            for (int i = 0; i < Plane2.TriangleInfo.Indices.Length; i++)
            {
                TriangleInfo TI = Plane2.TriangleInfo;
                TriangleF    T  = new TriangleF(M * TI.Points[TI.Indices[i]], M * TI.Points[TI.Indices[i + 1]], M * TI.Points[TI.Indices[i + 2]]);
                i = i + 2;
                //  if (T.Inside(ViewLine.P.toXYZF()))
                ListOfTriangles2.Add(T);
            }
            for (int i = 0; i < ListOfTriangles2.Count; i++)
            {
                if (ListOfTriangles2[i].Inside(ViewLine.P.toXYZF()))
                {
                    TriangleF F = ListOfTriangles2[i];
                    ListOfTriangles2.RemoveAt(i);
                    ListOfTriangles2.Insert(0, F);
                }
            }
            List <Line3D> Lines = Cross(ListOfTriangles1, ListOfTriangles2, ViewLine);
            xyz           P1    = new xyz(0, 0, 0);
            xyz           P2    = new xyz(0, 0, 0);

            if (Lines.Count < 2)
            {
                double           Lam = -1;
                double           Mue = -1;
                List <TriangleF> L1  = new List <TriangleF>();
                List <TriangleF> L2  = new List <TriangleF>();
                for (int i = 0; i < ListOfTriangles1.Count; i++)
                {
                    if (ListOfTriangles1[i].Inside(ViewLine.P.toXYZF()))
                    {
                        L1.Add(ListOfTriangles1[i]);
                    }
                }
                for (int i = 0; i < ListOfTriangles2.Count; i++)
                {
                    if (ListOfTriangles2[i].Inside(ViewLine.P.toXYZF()))
                    {
                        L2.Add(ListOfTriangles2[i]);
                    }
                }
                L1 = ListOfTriangles1;
                L2 = ListOfTriangles2;
                for (int i = 0; i < L1.Count; i++)
                {
                    for (int j = 0; j < L2.Count; j++)
                    {
                        if (TriangleF.Cross(L1[i], L2[j], out Lam, out Mue, out P1, out P2))
                        {
                            int _lam = (int)Lam;
                            switch (_lam)
                            {
                            case 0:
                                Lines.Add(new Line3D(L1[i].A.Toxyz(), L1[i].B.Toxyz()));
                                break;

                            case 1:
                                Lines.Add(new Line3D(L1[i].B.Toxyz(), L1[i].C.Toxyz()));
                                break;

                            case 2:
                                Lines.Add(new Line3D(L1[i].C.Toxyz(), L1[i].A.Toxyz()));
                                break;

                            default:
                                break;
                            }
                            int _mue = (int)Mue;
                            switch (_mue)
                            {
                            case 0:
                                Lines.Add(new Line3D(L2[j].A.Toxyz(), L2[j].B.Toxyz()));
                                break;

                            case 1:
                                Lines.Add(new Line3D(L2[j].B.Toxyz(), L2[j].C.Toxyz()));
                                break;

                            case 2:
                                Lines.Add(new Line3D(L2[j].C.Toxyz(), L2[j].A.Toxyz()));
                                break;

                            default:
                                break;
                            }
                        }
                        break;
                    }
                }
                //if (TriangleF.Cross(ListOfTriangles1[0], ListOfTriangles2[0], out Lam, out Mue, out P1, out P2))
                //{
                //    int _lam = (int)Lam;
                //    switch (_lam)
                //    {case  0: Lines.Add(new Line3D(ListOfTriangles1[0].A.Toxyz(),ListOfTriangles1[0].B.Toxyz()));
                //           break;
                //        case 1: Lines.Add(new Line3D(ListOfTriangles1[0].B.Toxyz(), ListOfTriangles1[0].C.Toxyz()));
                //            break;
                //        case 2: Lines.Add(new Line3D(ListOfTriangles1[0].C.Toxyz(), ListOfTriangles1[0].A.Toxyz()));
                //            break;
                //        default:
                //            break;
                //    }
                //    int _mue = (int)Mue;
                //    switch (_mue)
                //    {
                //        case 0:
                //            Lines.Add(new Line3D(ListOfTriangles2[0].A.Toxyz(), ListOfTriangles2[0].B.Toxyz()));
                //            break;
                //        case 1: Lines.Add(new Line3D(ListOfTriangles2[0].B.Toxyz(), ListOfTriangles2[0].C.Toxyz()));
                //            break;
                //        case 2: Lines.Add(new Line3D(ListOfTriangles2[0].C.Toxyz(), ListOfTriangles2[0].A.Toxyz()));
                //            break;
                //        default:
                //            break;
                //    }
                //}
            }

            double di  = 1e10;
            xyz    Pos = new xyz(0, 0, 0);
            int    Id  = -1;

            for (int i = 0; i < Lines.Count; i++)
            {
                LineType L   = new LineType(Lines[i].A, Lines[i].B - Lines[i].A);
                double   Lam = -1;

                double d       = ViewLine.Distance(L, SnapItem.Snapdist, false, false, out Lam);
                xyz    Nearest = L.Value(Lam);
                if ((Lam >= -0.00001) && (Lam <= 1.00001))
                {
                    if (d < di)
                    {
                        Pos = Nearest;
                        di  = d;
                        Id  = i;
                    }
                }
            }
            if ((di < 1e10) && (di <= SnapItem.Snapdist))
            {
                Plane1.Crossed = true;
                Plane1.Point   = Pos;
                Plane2.Crossed = true;
                Plane2.Point   = Pos;
                return(true);
            }

            xyzArray A = Plane1.getxyzArray();
            xyzArray B = Plane2.getxyzArray();

            if ((A != null) && (B != null))
            {
                return(IntersectLineWithLine(Plane1, Plane2, ViewLine));
            }



            return(false);
        }
Beispiel #18
0
        public override void OnPaint()
        {
            BackColor = Color.White;

            switch (ActiveSnapKind)
            {
            case Snapkind.SurfaceSnapItem:     // Problem Ränder
                //if (SnappItems.Count >0)
                //{
                //    Emission = Color.Red;
                //    SnappItems[0].DrawTriangleInfo();
                //    Emission = Color.Black;
                //    return;
                //}
                CurveExtruder CurveEx = new CurveExtruder();
                CurveEx.Direction = new xyz(0, 1, 1);
                CurveEx.Height    = -1;
                CurveEx.Curve     = new Bezier(new xy(9, 0), new xy(6, 3), new xy(3, 3), new xy(0, 0));
                CurveEx.DownPlane = new Plane(new xyz(0, 0, 0), new xyz(0, 0, 1));
                CurveEx.UpPlane   = new Plane(new xyz(0, 0, 0) + CurveEx.Direction * 7, CurveEx.Direction);

                CurveEx.Paint(this);
                break;

            case Snapkind.LineSnapItem:

                drawCurve(new Line(new xy(0, 0), new xy(10, 0)));
                break;

            case Snapkind.PointSnapItem:
                drawPoint(new xyz(4, 3, 0), 0.2);

                break;

            case Snapkind.CurveSnapItem:
                Curve C = new Bezier(new xy(9, 0), new xy(6, 3), new xy(3, 3), new xy(0, 0));
                PolygonMode = PolygonMode.Line;
                Emission    = Color.Black;
                PenWidth    = 3;
                drawCurve(C);
                PolygonMode = PolygonMode.Fill;
                break;

            case Snapkind.PolyCurveSnapItem:

                Lights[0].Position = new xyzwf(-10, -10, 10, 1);
                CurveArray _Curves0 = new CurveArray();
                PolygonMode    = PolygonMode.Line;
                _Curves0.Count = 4;
                _Curves0[0]    = new Line(new xy(-3, -3), new xy(-3, 4));
                _Curves0[1]    = new Line(new xy(-3, 4), new xy(4, 4));
                _Curves0[2]    = new Line(new xy(4, 4), new xy(4, -3));
                _Curves0[3]    = new Bezier(new xy(4, -3), new xy(3, -3.5), new xy(1, -3.5), new xy(-3, -3));

                drawPolyCurve(_Curves0);

                PolygonMode = PolygonMode.Fill;
                break;

            case Snapkind.PolyPolyCurveSnapItem:
                Loca       _Loca   = new Loca();
                CurveArray Curves0 = new CurveArray();
                Curves0.Count = 4;
                Curves0[0]    = new Line(new xy(-3, -3), new xy(-3, 4));
                Curves0[1]    = new Line(new xy(-3, 4), new xy(4, 4));
                Curves0[2]    = new Line(new xy(4, 4), new xy(4, -3));
                Curves0[3]    = new Bezier(new xy(4, -3), new xy(3, -3.5), new xy(1, -3.5), new xy(-3, -3));
                _Loca.Add(Curves0);
                OpenGlDevice.CheckError();
                CurveArray Curves1 = new CurveArray();
                Curves1.Count = 4;
                Curves1[0]    = new Line(new xy(0, 0), new xy(1, 0));
                Curves1[1]    = new Line(new xy(1, 0), new xy(1, 1));
                Curves1[2]    = new Line(new xy(1, 1), new xy(0, 1));
                Curves1[3]    = new Line(new xy(0, 1), new xy(0, 0));
                _Loca.Add(Curves1);

                PolygonMode = PolygonMode.Fill;
                drawPolyPolyCurve(_Loca);

                break;

            case Snapkind.TextSnapItem:


                Font.FontSize = 4;
                xy Pos = getEnvText(Font, "Drawing 3D");
                drawText(Font, new xyz(-Pos.X / 2, 0, 0), "Drawing 3D", 2);

                break;

            case Snapkind.MeshSnapItem:

                int[]  Indices  = new int[] { 0, 1, 2 };
                xyzf[] Position = new xyzf[] { new xyzf(0, 0, 0), new xyzf(3, 5, 0), new xyzf(6, 0, 0) };
                xyzf[] Normal   = new xyzf[] { new xyzf(0, 0, 1), new xyzf(0, 0, 1), new xyzf(0, 0, 1) };
                xyf[]  Texture  = new xyf[] { new xyf(0, 0), new xyf(3, 5), new xyf(6, 0) };
                xyzf[] Colors   = new xyzf[] { new xyzf(1, 0, 0), new xyzf(0, 1, 0), new xyzf(0, 0, 1) };

                drawMesh(Indices, Position, Normal, null, Colors);
                break;

            case Snapkind.PolyLineSnapItem:

                xyArray Poly = new xyArray();

                Poly.data   = new xy[] { new xy(1, 1), new xy(3, 4), new xy(5, 4), new xy(6, 2), new xy(1, 1) };
                PolygonMode = PolygonMode.Fill;
                PenWidth    = 3;

                drawPolyLine(Poly);
                PolygonMode = PolygonMode.Fill;


                break;

            case Snapkind.CurveSnapItem3D:

                Bezier3D Bezier = new Bezier3D(new xyz(1, 2, 1), new xyz(3, -2, 3), new xyz(5, 3, 2), new xyz(7, 1, 1));

                drawCurve(Bezier);


                break;

            case Snapkind.PolyLineSnapItem3D:
                xyzArray Poly3d = new xyzArray();
                Poly3d.data = new xyz[] { new xyz(0, 0, 1), new xyz(0, 3, 1), new xyz(3, 3, 1), new xyz(4, 0, 1), new xyz(0, 0, 1) };
                drawPolyLine(Poly3d);
                break;

            case Snapkind.PolyPolyLineSnapItem3D:

                xyzArray AA = new xyzArray();
                AA.Add(new xyz(1, 1, 1));
                AA.Add(new xyz(0, 1, 1));
                AA.Add(new xyz(0, 0, 1));
                AA.Add(new xyz(1, 0, 1));
                AA.Add(new xyz(1, 1, 1));
                xyzArray BB = new xyzArray();

                BB.Add(new xyz(3, 3, 1));
                BB.Add(new xyz(3, -2, 1));
                BB.Add(new xyz(-1, -2, 1));
                BB.Add(new xyz(-1, 3, 1));
                BB.Add(new xyz(3, 3, 1));



                Loxyz L = new Loxyz();
                L.Add(AA);
                L.Add(BB);


                drawPolyPolyLine(L);

                break;

            case Snapkind.PolyPolyLineSnapItem:

                xyArray _AA = new xyArray();
                _AA.Add(new xy(2, 0.5));
                _AA.Add(new xy(0, 0.5));
                _AA.Add(new xy(0, 0));
                _AA.Add(new xy(2, 0));
                _AA.Add(new xy(2, 0.5));
                xyArray _BB = new xyArray();

                _BB.Add(new xy(4, 4));
                _BB.Add(new xy(4, -2));
                _BB.Add(new xy(-1, -2));
                _BB.Add(new xy(-1, 4));

                _BB.Add(new xy(4, 4));
                Loxy _L = new Loxy();
                _L.Add(_AA);
                _L.Add(_BB);


                drawPolyPolyLine(_L);

                break;

            case Snapkind.SphereSnapItem:
                drawSphere(new xyz(2, 1, 1), 3);


                break;

            case Snapkind.BoxSnapItem:

                drawBox(new xyz(0, 0, 0), new xyz(4, 3, 4));
                break;

            default:
                break;
            }
            ACursor.Paint(this);
        }
Beispiel #19
0
        protected internal override xyz Cross(LineType ViewLine)
        {
            if (this.PolygonMode == PolygonMode.Line)
            {
                Polygon = Primitives3d.GetBoxPoints(Position, Size);
                double Param    = -1;
                double LineLam1 = -1;
                if (Polygon.Distance(ViewLine, 1e10, out Param, out LineLam1) < 1)
                {
                    return(Polygon.Value(Param));
                }
                return(new xyz(0, 0, 0));
            }
            xyz[] Result   = new xyz[5];
            Plane Triangle = new Plane(TriangleInfo.Points[TriangleInfo.Indices[PrimId * 3]], TriangleInfo.Points[TriangleInfo.Indices[PrimId * 3 + 1]], TriangleInfo.Points[TriangleInfo.Indices[PrimId * 3 + 2]]);

            //Test
            switch (PrimId)
            {// Oben
            case 0:
                //Polygon.data = new xyz[] {TriangleInfo.Points[0].Toxyz(),
                //                TriangleInfo.Points[2].Toxyz(),
                //                TriangleInfo.Points[1].Toxyz(),
                //                TriangleInfo.Points[3].Toxyz(),
                //                TriangleInfo.Points[0].Toxyz()};
                //Point = Position;
                //Result[0] = new xyz(Point.x, Point.y, Point.z + Size.z);
                //Result[1] = new xyz(Point.x, Point.y + Size.y, Point.z + Size.z);
                //Result[2] = new xyz(Point.x, Point.y + Size.y, Point.z);
                //Result[3] = new xyz(Point.x, Point.y, Point.z);
                //Result[4] = Result[0];
                Result[0] = new xyz(Position.x, Position.y, Position.z + Size.Z);
                Result[1] = new xyz(Position.x + Size.x, Position.y, Position.z + Size.Z);
                Result[2] = new xyz(Position.x + Size.x, Position.y + Size.y, Position.z + Size.Z);
                Result[3] = new xyz(Position.x, Position.y + Size.y, Position.z + Size.Z);
                Result[4] = Result[0];
                break;

            case 1:
                //Polygon.data = new xyz[] {TriangleInfo.Points[0].Toxyz(),
                //                TriangleInfo.Points[2].Toxyz(),
                //                TriangleInfo.Points[1].Toxyz(),
                //                TriangleInfo.Points[3].Toxyz(),
                //                 TriangleInfo.Points[0].Toxyz()
                //};
                Result[0] = new xyz(Position.x, Position.y, Position.z + Size.Z);
                Result[1] = new xyz(Position.x + Size.x, Position.y, Position.z + Size.Z);
                Result[2] = new xyz(Position.x + Size.x, Position.y + Size.y, Position.z + Size.Z);
                Result[3] = new xyz(Position.x, Position.y + Size.y, Position.z + Size.Z);
                Result[4] = Result[0];
                break;

            case 2:    // unten
                //Polygon.data = new xyz[] {TriangleInfo.Points[4].Toxyz(),
                //                TriangleInfo.Points[6].Toxyz(),
                //                TriangleInfo.Points[5].Toxyz(),
                //                TriangleInfo.Points[7].Toxyz(),
                //                TriangleInfo.Points[4].Toxyz()
                //};
                Result[0] = new xyz(Position.x, Position.y, Position.z);
                Result[2] = new xyz(Position.x + Size.x, Position.y, Position.z);
                Result[1] = new xyz(Position.x + Size.x, Position.y + Size.y, Position.z);
                Result[3] = new xyz(Position.x, Position.y + Size.y, Position.z);
                Result[4] = Result[0];
                break;

            case 3:
                //Polygon.data = new xyz[] {TriangleInfo.Points[4].Toxyz(),
                //                TriangleInfo.Points[6].Toxyz(),
                //                TriangleInfo.Points[5].Toxyz(),
                //                TriangleInfo.Points[7].Toxyz(),
                //                TriangleInfo.Points[4].Toxyz()
                //};
                Result[0] = new xyz(Position.x, Position.y, Position.z);
                Result[2] = new xyz(Position.x + Size.x, Position.y, Position.z);
                Result[1] = new xyz(Position.x + Size.x, Position.y + Size.y, Position.z);
                Result[3] = new xyz(Position.x, Position.y + Size.y, Position.z);
                Result[4] = Result[0];
                break;

            case 4:
                //Polygon.data = new xyz[] {TriangleInfo.Points[8].Toxyz(),
                //                TriangleInfo.Points[10].Toxyz(),
                //                TriangleInfo.Points[9].Toxyz(),
                //                TriangleInfo.Points[11].Toxyz(),
                //                TriangleInfo.Points[8].Toxyz()
                //};
                Result[0] = new xyz(Position.x, Position.y, Position.z);
                Result[1] = new xyz(Position.x + Size.x, Position.y, Position.z);
                Result[2] = new xyz(Position.x + Size.x, Position.y, Position.z + Size.Z);
                Result[3] = new xyz(Position.x, Position.y, Position.z + Size.Z);
                Result[4] = Result[0];
                break;

            case 5:
                //Polygon.data = new xyz[] {TriangleInfo.Points[8].Toxyz(),
                //                TriangleInfo.Points[10].Toxyz(),
                //                TriangleInfo.Points[9].Toxyz(),
                //                TriangleInfo.Points[11].Toxyz(),
                //                TriangleInfo.Points[8].Toxyz()
                //};
                Result[0] = new xyz(Position.x, Position.y, Position.z);
                Result[1] = new xyz(Position.x + Size.x, Position.y, Position.z);
                Result[2] = new xyz(Position.x + Size.x, Position.y, Position.z + Size.Z);
                Result[3] = new xyz(Position.x, Position.y, Position.z + Size.Z);
                Result[4] = Result[0];

                break;

            case 6:    // Hinten
                //Polygon.data = new xyz[] {TriangleInfo.Points[12].Toxyz(),
                //                TriangleInfo.Points[14].Toxyz(),
                //                TriangleInfo.Points[13].Toxyz(),
                //                TriangleInfo.Points[15].Toxyz(),
                //                TriangleInfo.Points[12].Toxyz()
                //};
                Result[0] = new xyz(Position.x + Size.x, Position.y + Size.Y, Position.z);
                Result[1] = new xyz(Position.x, Position.y + Size.Y, Position.z);
                Result[2] = new xyz(Position.x, Position.y + Size.y, Position.z + Size.Z);
                Result[3] = new xyz(Position.x + Size.x, Position.y + Size.y, Position.z + Size.Z);
                Result[4] = Result[0];
                break;

            case 7:    // Hinten
                //Polygon.data = new xyz[] {TriangleInfo.Points[12].Toxyz(),
                //                TriangleInfo.Points[14].Toxyz(),
                //                TriangleInfo.Points[13].Toxyz(),
                //                TriangleInfo.Points[15].Toxyz(),
                //                TriangleInfo.Points[12].Toxyz()
                //};
                Result[0] = new xyz(Position.x + Size.x, Position.y + Size.Y, Position.z);
                Result[1] = new xyz(Position.x, Position.y + Size.Y, Position.z);
                Result[2] = new xyz(Position.x, Position.y + Size.y, Position.z + Size.Z);
                Result[3] = new xyz(Position.x + Size.x, Position.y + Size.y, Position.z + Size.Z);
                Result[4] = Result[0];
                break;

            case 8:     // Links))
                //Polygon.data = new xyz[] {TriangleInfo.Points[16].Toxyz(),
                //                TriangleInfo.Points[18].Toxyz(),
                //                TriangleInfo.Points[17].Toxyz(),
                //                TriangleInfo.Points[19].Toxyz(),
                //                TriangleInfo.Points[16].Toxyz()
                //};
                Result[0] = new xyz(Position.x, Position.y + Size.Y, Position.z);
                Result[1] = new xyz(Position.x, Position.y, Position.z);
                Result[2] = new xyz(Position.x, Position.y, Position.z + Size.Z);
                Result[3] = new xyz(Position.x, Position.y + Size.Y, Position.z + Size.Z);
                Result[4] = Result[0];
                break;

            case 9:
                //Polygon.data = new xyz[] {TriangleInfo.Points[16].Toxyz(),
                //                TriangleInfo.Points[18].Toxyz(),
                //                TriangleInfo.Points[17].Toxyz(),
                //                TriangleInfo.Points[19].Toxyz(),
                //                TriangleInfo.Points[16].Toxyz()

                //                  };
                Result[0] = new xyz(Position.x, Position.y + Size.Y, Position.z);
                Result[1] = new xyz(Position.x, Position.y, Position.z);
                Result[2] = new xyz(Position.x, Position.y, Position.z + Size.Z);
                Result[3] = new xyz(Position.x, Position.y + Size.Y, Position.z + Size.Z);
                Result[4] = Result[0];
                break;

            case 10:    //Rechts
                //Polygon.data = new xyz[] {TriangleInfo.Points[20].Toxyz(),
                //                TriangleInfo.Points[22].Toxyz(),
                //                TriangleInfo.Points[21].Toxyz(),
                //                TriangleInfo.Points[23].Toxyz(),
                //                TriangleInfo.Points[20].Toxyz()
                //                   };
                Result[0] = new xyz(Position.x + Size.X, Position.y, Position.z);
                Result[1] = new xyz(Position.x + Size.x, Position.y + Size.Y, Position.z);
                Result[2] = new xyz(Position.x + Size.x, Position.y + Size.y, Position.z + Size.Z);
                Result[3] = new xyz(Position.x + Size.x, Position.y, Position.z + Size.z);
                Result[4] = Result[0];
                break;

            case 11:    //Rechts
                //Polygon.data = new xyz[] {TriangleInfo.Points[20].Toxyz(),
                //                TriangleInfo.Points[22].Toxyz(),
                //                TriangleInfo.Points[21].Toxyz(),
                //                TriangleInfo.Points[23].Toxyz(),
                //                TriangleInfo.Points[20].Toxyz()
                //                 };
                Result[0] = new xyz(Position.x + Size.X, Position.y, Position.z);
                Result[1] = new xyz(Position.x + Size.x, Position.y + Size.Y, Position.z);
                Result[2] = new xyz(Position.x + Size.x, Position.y + Size.y, Position.z + Size.Z);
                Result[3] = new xyz(Position.x + Size.x, Position.y, Position.z + Size.z);
                Result[4] = Result[0];
                break;

            default:
                break;
            }
            Polygon.data = Result;
            double Lam     = -1;
            double LineLam = -1;
            double di      = Polygon.Distance(ViewLine, Snapdist, out Lam, out LineLam);

            if (di <= Snapdist)
            {
                xyz P = Polygon.Value(Lam);
                doExchange = true;

                //xyz W = ViewLine.Value(LineLam);
                //double mm = P.dist(W);
                return(P);
            }
            return(base.Cross(ViewLine));
        }