Beispiel #1
0
 /// <summary>
 /// Создание легенды.
 /// </summary>
 /// <param name="value">Значение, которое надо отображать.</param>
 /// <param name="X">Положение текстуры от левого края.</param>
 /// <param name="X">Положение текстуры от верхнего края.</param>
 /// <param name="legend">Легенда с подписью значения.</param>
 /// <param name="ColorsForeground">Цвет заполнения.</param>
 /// <param name="ColorBackground">Цвет фона.</param>
 /// <param name="checkSet">Проверка записи в легенду.</param>
 /// <param name="toString">Правила преобразования хранимой характеристики.</param>
 public CharacteristicInterface(T value, int X, int Y, string legend, ConsoleColor ColorsForeground, ConsoleColor ColorBackground, Func <T, bool> checkSet = null, Func <T, string> toString = null)
 {
     base.texture        = new DynamicTexture(legend, ColorsForeground, ColorBackground);
     this.colorContainer = new ScreenPixel()
     {
         ForegroundColor = ColorsForeground,
         BackgroundColor = ColorBackground
     };
     if (checkSet == null)
     {
         this.checkSet = (T t) => true;
     }
     else
     {
         this.checkSet = checkSet;
     }
     if (toString == null)
     {
         this.toString = (T t) => t.ToString();
     }
     else
     {
         this.toString = toString;
     }
     this.legend = legend;
     this.Value  = value;
     base.position.Set(X, Y);
 }
Beispiel #2
0
        public virtual void Raytrace()
        {
            //	First, we need the matricies and viewport.
            double[] modelview = new double[16];
            double[] projection = new double[16];
            int[] viewport = new int[4];
            gl.GetDouble(SharpGL.OpenGL.MODELVIEW_MATRIX, modelview);
            gl.GetDouble(SharpGL.OpenGL.PROJECTION_MATRIX, projection);
            gl.GetInteger(SharpGL.OpenGL.VIEWPORT, viewport);
            int screenwidth = viewport[2];
            int screenheight = viewport[3];

            //	From frustum data, we make a screen origin, and s/t vectors.
            Vertex s = new Vertex(0, 0.03f, 0);
            Vertex t = new Vertex(0, 0, 0.05f);
            Vertex vScreenOrigin = new Vertex(0, 0, 5);

            //	Go through every pixel we have, and convert it into a screen pixel.
            ScreenPixel[] pixels = new ScreenPixel[viewport[2] * viewport[3]];

            for(int y = 0; y < screenheight; y++)
            {
                for(int x = 0; x < screenwidth; x++)
                {
                    //	Get plane coordinates first of all.
                    int planeX = x - (screenwidth / 2);
                    int planeY = y - (screenwidth / 2);

                    float worldX = vScreenOrigin.X + (planeX * t.X) + (planeY * s.X);
                    float worldY = vScreenOrigin.Y + (planeX * t.Y) + (planeY * s.Y);
                    float worldZ = vScreenOrigin.Z + (planeX * t.Z) + (planeY * s.Z);

                    //	Finally, pack all that data into a ScreenPixel.
                    ScreenPixel pixel = new ScreenPixel();
                    pixel.x = x;
                    pixel.y = y;
                    pixel.worldpos = new Vertex(worldX, worldY, worldZ);
                    pixel.ray.origin = currentCamera.Translate;
                    pixel.ray.direction = pixel.worldpos - currentCamera.Translate;

                    pixels[(y * viewport[2]) + x] = pixel;
                }
            }

            /*	for(int y = 0; y < viewport[3]; y++)
                {
                    for(int x = 0; x < viewport[2]; x++)
                    {
                        //	Create a screenpixel.
                        ScreenPixel pixel =new ScreenPixel();
                        pixel = new ScreenPixel();
                        pixel.x = x;
                        pixel.y = y;

                        //	Get the world coordinate.
                        double[] wx = new Double[1];
                        double[] wy = new Double[1];
                        double[] wz = new Double[1];
                        gl.UnProject(x, y, 0, modelview, projection, viewport,
                            wx, wy, wz);
                        pixel.worldpos.Set((float)wx[0], (float)wy[0], (float)wz[0]);

                        //	Set the ray.
                        pixel.ray.origin = currentCamera.Translate;
                        pixel.ray.direction = pixel.worldpos - currentCamera.Translate;

                        pixels[(y * viewport[2]) + x] = pixel;
                    }
                }*/

            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(viewport[2], viewport[3]);

            //	Now go through every ray and test for intersections.
            int pixelcounter = 0;
            int pixelcount = viewport[2] * viewport[3];
            foreach(ScreenPixel pix in pixels)
            {
                //	Raytrace the polygons.
                Intersection closest = new Intersection();
                foreach(Polygon poly in Polygons)
                {
                    Intersection i = poly.Raytrace(pix.ray, this);
                    if(i.intersected && (closest.intersected == false || i.closeness < closest.closeness))
                        closest = i;
                }

                if(closest.intersected == true)
                {
                    System.Console.WriteLine("i = {0}, only {1} left!\n",
                        closest.closeness, pixelcount - pixelcounter);
                }
                bmp.SetPixel(pix.x, pix.y, pix.ray.light);
                pixelcounter++;

            }
            bmp.Save("C:\\raytraced.bmp");
        }
Beispiel #3
0
        public virtual void Raytrace()
        {
            //	First, we need the matricies and viewport.
            double[] modelview  = new double[16];
            double[] projection = new double[16];
            int[]    viewport   = new int[4];
            gl.GetDouble(SharpGL.OpenGL.MODELVIEW_MATRIX, modelview);
            gl.GetDouble(SharpGL.OpenGL.PROJECTION_MATRIX, projection);
            gl.GetInteger(SharpGL.OpenGL.VIEWPORT, viewport);
            int screenwidth  = viewport[2];
            int screenheight = viewport[3];

            //	From frustum data, we make a screen origin, and s/t vectors.
            Vertex s             = new Vertex(0, 0.03f, 0);
            Vertex t             = new Vertex(0, 0, 0.05f);
            Vertex vScreenOrigin = new Vertex(0, 0, 5);

            //	Go through every pixel we have, and convert it into a screen pixel.
            ScreenPixel[] pixels = new ScreenPixel[viewport[2] * viewport[3]];


            for (int y = 0; y < screenheight; y++)
            {
                for (int x = 0; x < screenwidth; x++)
                {
                    //	Get plane coordinates first of all.
                    int planeX = x - (screenwidth / 2);
                    int planeY = y - (screenwidth / 2);

                    float worldX = vScreenOrigin.X + (planeX * t.X) + (planeY * s.X);
                    float worldY = vScreenOrigin.Y + (planeX * t.Y) + (planeY * s.Y);
                    float worldZ = vScreenOrigin.Z + (planeX * t.Z) + (planeY * s.Z);

                    //	Finally, pack all that data into a ScreenPixel.
                    ScreenPixel pixel = new ScreenPixel();
                    pixel.x             = x;
                    pixel.y             = y;
                    pixel.worldpos      = new Vertex(worldX, worldY, worldZ);
                    pixel.ray.origin    = currentCamera.Translate;
                    pixel.ray.direction = pixel.worldpos - currentCamera.Translate;

                    pixels[(y * viewport[2]) + x] = pixel;
                }
            }

            /*	for(int y = 0; y < viewport[3]; y++)
             *      {
             *              for(int x = 0; x < viewport[2]; x++)
             *              {
             *                      //	Create a screenpixel.
             *                      ScreenPixel pixel =new ScreenPixel();
             *                      pixel = new ScreenPixel();
             *                      pixel.x = x;
             *                      pixel.y = y;
             *
             *                      //	Get the world coordinate.
             *                      double[] wx = new Double[1];
             *                      double[] wy = new Double[1];
             *                      double[] wz = new Double[1];
             *                      gl.UnProject(x, y, 0, modelview, projection, viewport,
             *                              wx, wy, wz);
             *                      pixel.worldpos.Set((float)wx[0], (float)wy[0], (float)wz[0]);
             *
             *                      //	Set the ray.
             *                      pixel.ray.origin = currentCamera.Translate;
             *                      pixel.ray.direction = pixel.worldpos - currentCamera.Translate;
             *
             *                      pixels[(y * viewport[2]) + x] = pixel;
             *              }
             *      }*/

            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(viewport[2], viewport[3]);


            //	Now go through every ray and test for intersections.
            int pixelcounter = 0;
            int pixelcount   = viewport[2] * viewport[3];

            foreach (ScreenPixel pix in pixels)
            {
                //	Raytrace the polygons.
                Intersection closest = new Intersection();
                foreach (Polygon poly in Polygons)
                {
                    Intersection i = poly.Raytrace(pix.ray, this);
                    if (i.intersected && (closest.intersected == false || i.closeness < closest.closeness))
                    {
                        closest = i;
                    }
                }

                if (closest.intersected == true)
                {
                    System.Console.WriteLine("i = {0}, only {1} left!\n",
                                             closest.closeness, pixelcount - pixelcounter);
                }
                bmp.SetPixel(pix.x, pix.y, pix.ray.light);
                pixelcounter++;
            }
            bmp.Save("C:\\raytraced.bmp");
        }