示例#1
0
        public TriangleInfo TransformAnimator(Matrix Matrix)
        {
            TriangleInfo Result = new TriangleInfo();

            Result.Indices = Indices;
            Result.Points  = new xyzf[Points.Length];
            Result.Normals = new xyzf[Normals.Length];
            Result.Texture = new xyf[Texture.Length];
            for (int i = 0; i < Points.Length; i++)
            {
                Points[i] = Matrix * Points[i];
            }
            xyzf Affin = Matrix * new xyzf(0, 0, 0);

            for (int i = 0; i < Points.Length; i++)
            {
                Normals[i] = Matrix * Points[i] - Affin;
            }
            for (int i = 0; i < Texture.Length; i++)
            {
                xyz A = Matrix * new xyz(Texture[i].x, Texture[i].y, 0);
                Texture[i] = new xyf((float)A.x, (float)A.y);
            }
            return(Result);
        }
示例#2
0
        internal virtual protected xyz Cross(LineType ViewLine)
        {
            xyz pt = new xyz(0, 0, 0);

            if ((Device.Selector.IntersectionUsed) && (TriangleInfo != null))
            //  if (TriangleInfo != null)
            {
                Plane Triangle = new Plane(TriangleInfo.Points[TriangleInfo.Indices[PrimId * 3]], TriangleInfo.Points[TriangleInfo.Indices[PrimId * 3 + 1]], TriangleInfo.Points[TriangleInfo.Indices[PrimId * 3 + 2]]);


                if (Inside(ViewLine, TriangleInfo.Points[TriangleInfo.Indices[PrimId * 3]], TriangleInfo.Points[TriangleInfo.Indices[PrimId * 3 + 1]], TriangleInfo.Points[TriangleInfo.Indices[PrimId * 3 + 2]]))
                {
                    Triangle.Cross(ViewLine, out Depth, out pt);
                }
                else
                {
                    pt = Nearest(ViewLine, TriangleInfo.Points[TriangleInfo.Indices[PrimId * 3]], TriangleInfo.Points[TriangleInfo.Indices[PrimId * 3 + 1]], TriangleInfo.Points[TriangleInfo.Indices[PrimId * 3 + 2]]);
                }

                return(pt);
            }
            else
            {
                int  N  = -1;
                xyzf Pk = new xyzf(0, 0, 0);
                if (TriangleInfo.Cross(ViewLine, ref Pk, ref N))
                {
                    return(Pk.Toxyz());
                }
                else
                {
                    return(Nearest(ViewLine, TriangleInfo.Points[TriangleInfo.Indices[N]], TriangleInfo.Points[TriangleInfo.Indices[N + 1]], TriangleInfo.Points[TriangleInfo.Indices[N + 2]]));

                    //Plane P =  new Plane(new xyz(0, 0, 0), new xyz(0, 0, 1));
                    //double Lam = 0;
                    //xyz R = new xyz(0, 0, 0);
                    //P.Cross(ViewLine, out Lam, out R);
                    //return R;
                }
            }
            return(new xyz(0, 0, 0));
        }
示例#3
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);
        }