示例#1
0
文件: Object.cs 项目: dzdota/RayTrace
        public static Object operator *(Double[,] Mas, Object obj)
        {
            Object RezultObject = new Object();

            for (int i = 0; i < obj.Poligons.Count; i++)
            {
                Poligon ChangePoligon = Mas * obj.Poligons[i];
                RezultObject.Poligons.Add(ChangePoligon);
            }
            for (int i = 0; i < obj.Lines.Count; i++)
            {
                if (obj.Lines[i].OnlyLine)
                {
                    Line ChangeLine = Mas * obj.Lines[i];
                    RezultObject.Lines.Add(ChangeLine);
                }
            }
            for (int i = 0; i < obj.Points.Count; i++)
            {
                if (obj.Points[i].OnlyPoint)
                {
                    Point3DF ChangePoint = Mas * obj.Points[i];
                    RezultObject.Points.Add(ChangePoint);
                }
            }
            return(RezultObject);
        }
示例#2
0
        static public bool PointHide(Point3DF point, List <Object> World)
        {
            Line LinePoint = new Line(point, new Point3DF(0, 0, 0), true);

            for (int NumObj = 0; NumObj < World.Count; NumObj++)
            {
                for (int NumPoligon = 0; NumPoligon < World[NumObj].Poligons.Count; NumPoligon++)
                {
                    double[] ABCD = Poligon.ABCDFound(World[NumObj].Poligons[NumPoligon], true);
                    double   t    = Line.PeresechPoint(ABCD, LinePoint);
                    if (Math.Round(t, 5) <= 0 || t > 1)
                    {
                        continue;
                    }
                    else
                    {
                        Point3DF PointPeresch = Line.PointF(LinePoint, t);
                        if (Poligon.InArea(World[NumObj].Poligons[NumPoligon], PointPeresch))
                        {
                            return(false);
                        }
                    }
                }
            }
            m1 :;
            return(true);
        }
示例#3
0
文件: Object.cs 项目: dzdota/RayTrace
        public static Object operator -(Object obj, Double[] Mas)
        {
            if (Mas.Length != 3)
            {
                return(null);
            }
            Object RezultObject = new Object();

            for (int i = 0; i < obj.Poligons.Count; i++)
            {
                Poligon ChangePoligon = obj.Poligons[i] - Mas;
                RezultObject.Poligons.Add(ChangePoligon);
            }
            for (int i = 0; i < obj.Lines.Count; i++)
            {
                if (obj.Lines[i].OnlyLine)
                {
                    Line ChangeLine = obj.Lines[i] - Mas;
                    RezultObject.Lines.Add(ChangeLine);
                }
            }
            for (int i = 0; i < obj.Points.Count; i++)
            {
                if (obj.Points[i].OnlyPoint)
                {
                    Point3DF ChangePoint = obj.Points[i] - Mas;
                    RezultObject.Points.Add(ChangePoint);
                }
            }
            return(RezultObject);
        }
示例#4
0
        static public List <double> CuskLine(Line line, Poligon pol)
        {
            List <Point3DF> Point  = new List <Point3DF>();
            List <double>   Lambda = new List <double>();

            double[] ABCD = Poligon.ABCDFound(pol, true);
            double   l1   = Poligon.PointCheck(ABCD, new Point3DF(0, 0, 0));
            double   l2   = Poligon.PointCheck(ABCD, line.StartLine);

            if ((l1 > 0 && l2 > 0) || (l1 < 0 && l2 < 0))
            {
                return(null);
            }
            for (int i = 0; i < 3; i++)
            {
                Poligon poligcam = new Poligon(pol.Points[i % 3], pol.Points[(i + 1) % 3], new Point3DF(0, 0, 0));
                Lambda.Add(Line.PeresechPoint(Poligon.ABCDFound(poligcam, true), line));
            }/*
              * Lambda.Sort(delegate (double d1, double d2)
              * {
              * if (double.IsNaN(d1))
              *     return -1;
              * if (double.IsNaN(d2))
              *     return 1;
              * return d1.CompareTo(d2);
              * });*/
            return(Lambda);
        }
示例#5
0
        public static Poligon operator -(Poligon obj, Double[] Mas)
        {
            if (Mas.Length != 3)
            {
                return(null);
            }
            Poligon ChangePoligon = new Poligon(obj.P1 - Mas, obj.P2 - Mas, obj.P3 - Mas, obj.B1, obj.B2, obj.B3, obj.ColorPoligon, obj.Rozseiv, obj.ForseOtbit);

            return(ChangePoligon);
        }
示例#6
0
        public static Poligon operator +(Double[] Mas, Poligon obj)
        {
            if (Mas.Length != 3)
            {
                return(null);
            }
            Poligon ChangePoligon = new Poligon(Mas + obj.P1, Mas + obj.P2, Mas + obj.P3, obj.B1, obj.B2, obj.B3, obj.ColorPoligon, obj.Rozseiv, obj.ForseOtbit);

            return(ChangePoligon);
        }
示例#7
0
        static public List <Object> CorectObj(List <Object> World)
        {
            List <Object> CorectWorld = new List <Object>();

            for (int NumObj = 0; NumObj < World.Count; NumObj++)
            {
                CorectWorld.Add(new Object());
                for (int NumPol = 0; NumPol < World[NumObj].Poligons.Count; NumPol++)
                {
                    for (int NumObj2 = 0; NumObj2 < World.Count; NumObj2++)
                    {
                        for (int NumPol2 = 0; NumPol2 < World[NumObj2].Poligons.Count; NumPol2++)
                        {
                            if (NumObj == NumObj2 && NumPol == NumPol2)
                            {
                                continue;
                            }
                            else
                            {
                                double[] ABCD1      = Poligon.ABCDFound(World[NumObj].Poligons[NumPol], true);
                                double[] ABCD2      = Poligon.ABCDFound(World[NumObj2].Poligons[NumPol2], true);
                                Line     linepersch = Line.LinePeresechPlosk(ABCD1, ABCD2);
                            }
                            CorectWorld[NumObj].Poligons.Add(World[NumObj2].Poligons[NumPol2]);
                        }
                    }
                }
            }/*
              * for (int NumObj = 0; NumObj < World.Count; NumObj++)
              * {
              * CorectWorld.Add(new Object());
              * for (int NumLine = 0; NumLine < World[NumObj].Lines.Count; NumLine++)
              * {
              *
              *     for (int NumObj2 = 0; NumObj2 < World.Count; NumObj2++)
              *     {
              *         for (int NumPol2 = 0; NumPol2 < World.Count; NumPol2++)
              *         {
              *
              *             if (NumObj == NumObj2 && NumPol == NumPol2)
              *                 //    break;
              *                 CorectWorld[NumObj].Poligons.Add(CorectWorld[NumObj2].Poligons[NumPol2]);
              *
              *         }
              *     }
              * }
              * }*/
            return(CorectWorld);
        }
示例#8
0
        public static bool InArea(Poligon pol, Point3DF point)
        {
            bool rez = true;

            Line[]   Perpend = new Line[pol.Lines.Count];
            double[] D       = new double[pol.Lines.Count];
            for (int i = 0; i < pol.Lines.Count; i++)
            {
                Perpend[i] = (PerpendicFound(pol.Lines[i], pol.Points[i]));
                Point3DF vector = Line.Vector(Perpend[i]);
                D[i] = -(vector.X * Perpend[i].StartLine.X +
                         vector.Y * Perpend[i].StartLine.Y +
                         vector.Z * Perpend[i].StartLine.Z);
                rez = rez && (vector.X * point.X + vector.Y * point.Y + vector.Z * point.Z + D[i] >= 0);
            }

            return(rez);
        }
示例#9
0
        public static double[] ABCDFound(Poligon pol, bool Right)
        {
            double[] ABCD = new double[4];
            Point3DF A    = Line.Vector(new Line(pol.P1, pol.P2, true));
            Point3DF B    = Line.Vector(new Line(pol.P2, pol.P3, true));
            //Point3DF L3 = Line.Vector(new Line(pol.P1, pol.P3, true));
            Point3DF vectPer = Line.VectorPerpend2Vector(A, B, Right);

            ABCD[0] = vectPer.X;
            ABCD[1] = vectPer.Y;
            ABCD[2] = vectPer.Z;
            if (!Right)
            {
                ABCD[0] *= -1;
                ABCD[1] *= -1;
                ABCD[2] *= -1;
            }
            ABCD[3] = -(ABCD[0] * pol.P1.X + ABCD[1] * pol.P1.Y + ABCD[2] * pol.P1.Z);
            return(ABCD);
        }
示例#10
0
        static public object[] LuchPointF(Line luch, List <Object> World)
        {
            double Lambda  = -1;
            bool   First   = true;
            int    numobjr = 0;
            int    numpolr = 0;

            for (int numobj = 0; numobj < World.Count; numobj++)
            {
                for (int numpol = 0; numpol < World[numobj].Poligons.Count; numpol++)
                {
                    double[] ABCD = Poligon.ABCDFound(World[numobj].Poligons[numpol], true);
                    double   L    = Line.PeresechPoint(ABCD, luch);
                    if (L > 0 && Poligon.InArea(World[numobj].Poligons[numpol], Line.PointF(luch, L)))
                    {
                        if (First)
                        {
                            First   = false;
                            numobjr = numobj;
                            numpolr = numpol;
                            Lambda  = L;
                        }
                        else if (L > 0)
                        {
                            if (Lambda >= L)
                            {
                                numobjr = numobj;
                                numpolr = numpol;
                            }
                            Lambda = Math.Min(Lambda, L);
                        }
                    }
                }
            }
            return(new object[3] {
                Lambda, numobjr, numpolr
            });
        }
示例#11
0
        public Color Luch(int wid, int heig)
        {
            Color  rez   = new Color();
            double wid1  = (wid - width / 2) / mash;
            double heig1 = -(heig - height / 2) / mash;
            Line   luch  = new Line(new Point3DF(0, 0, 0), new Point3DF(focus, wid1, heig1), true);

            object[] re     = LuchPointF(luch, World);
            double   Lambda = (double)re[0];
            int      numobj = (int)re[1];
            int      numpol = (int)re[2];

            if (Lambda < 0)
            {
                return(Color.White);
            }
            else
            {
                Line luch2 = new Line(Line.PointF(luch, Lambda - 0.01), Sun, true);
                luch = new Line(new Point3DF(0, 0, 0), Line.PointF(luch, Lambda), true);
                if (!((double)LuchPointF(luch2, World)[0] < 0))
                {
                    return(Color.Black);
                }
                else
                {
                    double  len2    = Line.Len(luch2);
                    double  len     = Line.Len(luch);
                    Color   colsunr = RozseivSrast(ColorSun, len);
                    Poligon pol     = World[numobj].Poligons[numpol];


                    double[] ABCD   = Poligon.ABCDFound(pol, true);
                    Point3DF Normal = Point3DF.NormirVector(new Point3DF(ABCD[0], ABCD[1], ABCD[2]));
                    Point3DF InSun  = Point3DF.NormirVector(Line.Vector(luch2));
                    if (InSun.X * Normal.X + InSun.Y * Normal.Y + InSun.Z * Normal.Z < 0)
                    {
                        Normal = new Point3DF(-Normal.X, -Normal.Y, -Normal.Z);
                    }
                    Point3DF InCam = Point3DF.NormirVector(Line.Vector(Line.LineObr(luch)));

                    Point3DF Perpend = Line.VectorPerpend2Vector(InSun, Normal, true);
                    Point3DF p1      = new Point3DF(Perpend.X, Perpend.Y, 0);
                    if (!(p1.X == 0 && p1.Y == 0))
                    {
                        double AngleZ = Line.AngleFound(
                            new Line(new Point3DF(0, 0, 0), new Point3DF(1, 0, 0), true),
                            new Line(new Point3DF(0, 0, 0), p1, true));

                        double[,] RotateZ = new double[3, 3]
                        {
                            { Math.Cos(AngleZ), Math.Sin(-AngleZ), 0 },
                            { Math.Sin(AngleZ), Math.Cos(AngleZ), 0 },
                            { 0, 0, 1 }
                        };
                        Point3DF test = RotateZ * p1;
                        if (!(Math.Round(test.Y, 5) == 0 && test.X > 0))
                        {
                            AngleZ *= -1;
                        }
                        RotateZ = new double[3, 3]
                        {
                            { Math.Cos(AngleZ), Math.Sin(-AngleZ), 0 },
                            { Math.Sin(AngleZ), Math.Cos(AngleZ), 0 },
                            { 0, 0, 1 }
                        };
                        test    = RotateZ * p1;
                        Normal  = RotateZ * Normal;
                        InSun   = RotateZ * InSun;
                        InCam   = RotateZ * InCam;
                        Perpend = RotateZ * Perpend;
                    }
                    double AngleY = Line.AngleFound(
                        new Line(new Point3DF(0, 0, 0), new Point3DF(10, 0, 0), true),
                        new Line(new Point3DF(0, 0, 0), Perpend, true));
                    double[,] RotateY = new double[3, 3]
                    {
                        { Math.Cos(AngleY), 0, Math.Sin(-AngleY) },
                        { 0, 1, 0 },
                        { Math.Sin(AngleY), 0, Math.Cos(AngleY) }
                    };
                    Point3DF p = RotateY * Perpend;
                    if (!(Math.Round(p.Z, 4) == 0 && p.X > 0))
                    {
                        AngleY *= -1;
                    }
                    RotateY = new double[3, 3]
                    {
                        { Math.Cos(AngleY), 0, Math.Sin(-AngleY) },
                        { 0, 1, 0 },
                        { Math.Sin(AngleY), 0, Math.Cos(AngleY) }
                    };
                    p = RotateY * Perpend;

                    Normal  = RotateY * Normal;
                    InSun   = RotateY * InSun;
                    InCam   = RotateY * InCam;
                    Perpend = RotateY * Perpend;

                    double AngleNS = -(InSun.X * Normal.X + InSun.Y * Normal.Y + InSun.Z * Normal.Z);
                    double[,] RotateX = new double[3, 3]
                    {
                        { 1, 0, 0 },
                        { 0, AngleNS, -Math.Sqrt(1 - Math.Pow(AngleNS, 2)) },
                        { 0, Math.Sqrt(1 - Math.Pow(AngleNS, 2)), AngleNS }
                    };
                    Point3DF OtragL      = RotateX * Normal;//new Point3DF(InSun.X, InSun.Y, InSun.Z);
                    double   CosAngleNS2 = InSun.X * OtragL.X + InSun.Y * OtragL.Y + InSun.Z * OtragL.Z;
                    if (Math.Abs(Math.Round(CosAngleNS2, 4)) == 1)
                    {
                        RotateX = new double[3, 3]
                        {
                            { 1, 0, 0 },
                            { 0, AngleNS, Math.Sqrt(1 - Math.Pow(AngleNS, 2)) },
                            { 0, -Math.Sqrt(1 - Math.Pow(AngleNS, 2)), AngleNS }
                        };
                        OtragL = RotateX * Normal;
                    }
                    double CosAngleNS = Math.Abs(InSun.X * Normal.X + InSun.Y * Normal.Y + InSun.Z * Normal.Z);
                    CosAngleNS2 = InSun.X * OtragL.X + InSun.Y * OtragL.Y + InSun.Z * OtragL.Z;
                    double CosAngleOC = Math.Max(0, -InCam.X * OtragL.X - InCam.Y * OtragL.Y - InCam.Z * OtragL.Z);

                    /*if (AngleOC < 0)
                     *  return Color.Black;*/
                    double[] K = new double[3] {
                        (double)pol.ColorPoligon.R / 255, (double)pol.ColorPoligon.G / 255, (double)pol.ColorPoligon.B / 255
                    };

                    double[] Ks = new double[3] {
                        (double)((255 - pol.ColorPoligon.R) * 1 + pol.ColorPoligon.R) / 255,
                        (double)((255 - pol.ColorPoligon.G) * 1 + pol.ColorPoligon.G) / 255,
                        (double)((255 - pol.ColorPoligon.B) * 1 + pol.ColorPoligon.B) / 255
                    };

                    double[] Ia = new double[3] {
                        K[0] * colsunr.R, K[1] * colsunr.G, K[2] * colsunr.B
                    };
                    double[] Id = new double[3] {
                        K[0] * CosAngleNS * colsunr.R, K[1] * CosAngleNS * colsunr.G, K[2] * CosAngleNS * colsunr.B
                    };
                    double[] Is = new double[3] {
                        Ks[0] * Math.Pow(CosAngleOC, 5) * colsunr.R,
                        Ks[1] * Math.Pow(CosAngleOC, 5) * colsunr.G,
                        Ks[2] * Math.Pow(CosAngleOC, 5) * colsunr.B
                    };
                    return(RozseivSrast(Color.FromArgb(
                                            (int)((Ia[0] + Id[0] + Is[0])) / (3),
                                            (int)((Ia[1] + Id[1] + Is[1])) / (3),
                                            (int)((Ia[2] + Id[2] + Is[2])) / (3))
                                        , len2));
                }
            }
            return(rez);
        }
示例#12
0
        public static Poligon operator *(Double[,] Mas, Poligon obj)
        {
            Poligon ChangePoligon = new Poligon(Mas * obj.P1, Mas * obj.P2, Mas * obj.P3, obj.B1, obj.B2, obj.B3, obj.ColorPoligon, obj.Rozseiv, obj.ForseOtbit);

            return(ChangePoligon);
        }