Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        static void Check(Plane P1, TriangleF T, ref int PtCount, xyzf A, xyzf B, ref xyzf Pt1, ref xyzf Pt2)
        {
            double Lam = -1;
            xyz    Pt  = new xyz(0, 0, 0);

            if (P1.Cross(new LineType(A.Toxyz(), (B.Toxyz() - A.Toxyz())), out Lam, out Pt))
            {
                xyz N = A.Toxyz() + (B.Toxyz() - A.Toxyz()) * Lam;

                if ((Lam >= -0.000000001) && (Lam < 1.000000001))
                {
                    if (T.Inside(Pt.toXYZF()))
                    {
                        if (PtCount == 0)
                        {
                            Pt1     = Pt.toXYZF();
                            PtCount = 1;
                        }
                        else
                        if (PtCount == 1)
                        {
                            if (Pt1.dist(Pt.toXYZF()) > 0.0001)
                            {
                                Pt2 = Pt.toXYZF();
                                PtCount++;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
0
        public bool Inside(xyzf _P)
        {
            xyzf N = ((B - A) & (C - A)).normalized();

            return(((((A - _P) & (B - _P)) * N > -0.01) &&
                    (((B - _P) & (C - _P)) * N > -0.01) &&
                    (((C - _P) & (A - _P)) * N > -0.01)
                    )
                   ||
                   ((((A - _P) & (B - _P)) * N < 0.01) &&
                    (((B - _P) & (C - _P)) * N < 0.01) &&
                    (((C - _P) & (A - _P)) * N < 0.01)
                   ))



            ;
        }
Ejemplo n.º 5
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));
        }
Ejemplo n.º 6
0
        bool Inside(LineType L, xyzf A, xyzf B, xyzf C)
        {
            TriangleF T        = new TriangleF(A, B, C);
            Plane     Triangle = new Plane(A, B, C);
            xyzf      N        = Triangle.NormalUnit.toXYZF();
            double    Depth    = -1;
            xyz       pt       = new xyz(0, 0, 0);

            Triangle.Cross(L, out Depth, out pt);
            bool tttt   = T.Inside(pt.toXYZF());
            xyzf _P     = pt.toXYZF();
            bool result = ((((A - _P) & (B - _P)) * N >= -0.00001) &&
                           (((B - _P) & (C - _P)) * N >= -0.00001) &&
                           (((C - _P) & (A - _P)) * N >= -0.00001));

            if (tttt != result)
            {
            }
            return(tttt);
        }
Ejemplo n.º 7
0
        public static bool Cross(TriangleF T1, TriangleF T2, ref xyzf Pt1, ref xyzf Pt2)
        {
            int   PtCount = 0;
            Plane P1      = new Plane(T1.A, T1.B, T1.C);

            Check(P1, T1, ref PtCount, T2.A, T2.B, ref Pt1, ref Pt2);
            if (PtCount == 2)
            {
                return(true);
            }
            Check(P1, T1, ref PtCount, T2.B, T2.C, ref Pt1, ref Pt2);
            if (PtCount == 2)
            {
                return(true);
            }
            Check(P1, T1, ref PtCount, T2.C, T2.A, ref Pt1, ref Pt2);
            if (PtCount == 2)
            {
                return(true);
            }

            Plane P2 = new Plane(T2.A, T2.B, T2.C);

            Check(P2, T2, ref PtCount, T1.A, T1.B, ref Pt1, ref Pt2);
            if (PtCount == 2)
            {
                return(true);
            }
            Check(P2, T2, ref PtCount, T1.B, T1.C, ref Pt1, ref Pt2);
            if (PtCount == 2)
            {
                return(true);
            }
            Check(P2, T2, ref PtCount, T1.C, T1.A, ref Pt1, ref Pt2);
            if (PtCount == 2)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 8
0
        public bool Cross(LineType L, ref xyzf Pt, ref double Lam)
        {
            int   PtCount = 0;
            Plane P1      = new Plane(A, B, C);
            xyz   P       = new xyz(0, 0, 0);

            Lam = -1;
            double Mue = -1;

            if (P1.Cross(L, out Lam, out P))
            {
                xyz PP = L.Value(Lam);
                Pt = new Drawing3d.xyzf((float)P.x, (float)P.y, (float)P.z);
                if (Inside(P.toXYZF()))
                {
                    Pt = P.toXYZF();
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 9
0
        public bool Cross(LineType L, ref xyzf Pt, ref int NearestTriangle)
        {
            xyzf   P   = new xyzf(0, 0, 0);
            bool   Res = false;
            double di  = 1e10;

            NearestTriangle = -1;
            double Lam    = -1;
            double Depth  = 1e10;
            xyzf   Result = new xyzf(0, 0, 0);

            for (int i = 0; i < Indices.Length; i = i + 3)
            {
                xyzf A = Points[Indices[i]];
                xyzf B = Points[Indices[i + 1]];
                xyzf C = Points[Indices[i + 2]];
                //  if (((B - A) & (C - A)) * L.Direction.toXYZF() < 0) continue;
                TriangleF T = new TriangleF(A, B, C);
                if ((T.Cross(L, ref P, ref Lam)) && (Lam < Depth))
                {
                    Res   = true;
                    Depth = Lam;
                    Pt    = P;
                    // return true;
                }
                else
                {
                    xyzf   t = (T.A + T.B + T.C) * (1f / 3f);
                    double d = t.DistQ(P);
                    if (d < di)
                    {
                        NearestTriangle = i;
                        di = d;
                    }
                    //  if ((T.A + T.B + T.C) * (1f / 3f))}
                }
            }
            return(Res);
        }
Ejemplo n.º 10
0
        public List <Line3D> Cross(List <TriangleF> LL1, List <TriangleF> LL2, LineType ViewLine)
        {
            List <Line3D> Lines = new List <Line3D>();

            if ((LL1 != null) && (LL2 != null))
            {
                for (int i = 0; i < LL1.Count; i++)
                {
                    for (int j = 0; j < LL2.Count; j++)
                    {
                        xyzf Pt1 = new xyzf(0, 0, 0);
                        xyzf Pt2 = new xyzf(0, 0, 0);


                        if (TriangleF.Cross(LL1[i], LL2[j], ref Pt1, ref Pt2))
                        {
                            Lines.Add(new Line3D(Pt1.Toxyz(), Pt2.Toxyz()));
                        }
                    }
                }
            }
            return(Lines);
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
 /// <summary>
 /// The constructor initializes the class with the values A, B, C
 /// </summary>
 /// <param name="A">1. point</param>
 /// <param name="B">2. point</param>
 /// <param name="C">3. point</param>
 public TriangleF(xyzf A, xyzf B, xyzf C)
 {
     this.A = A;
     this.B = B;
     this.C = C;
 }