Ejemplo n.º 1
0
        /* Prints the pixel of point P on the screen:
         *
         *  receives the color of the pixel without the lights
         *  and the normal vector.
         *
         *  if P is set outside of the screen bounds, doesn't print anything
         *
         *  compare its position on the Z_Buffer
         *
         *  draws the pixel with its final color (adding the lights effects)
         */
        public int printPixel(V3 P, Couleur color)
        {
            int x, y, z;

            x = (int)P.x;
            y = (int)P.y;
            z = (int)P.z;


            if (x < 0 || x >= BitmapEcran.GetWidth() || z < 0 || z >= BitmapEcran.GetHeight())
            {
                return(-1);
            }
            if (Elements.raycasting) // using ray casting
            {
                BitmapEcran.DrawPixel(x, z, color);
            }
            else
            { //using Z-Buffer
                if (y < Elements.Z_Buffer[x, z])
                {
                    Elements.Z_Buffer[x, z] = y;
                    BitmapEcran.DrawPixel(x, z, color);
                }
            }

            return(0);
        }
Ejemplo n.º 2
0
        public static void Go()
        {
            int screen_w = BitmapEcran.GetWidth(), screen_h = BitmapEcran.GetHeight();
            V3  camera_position = new V3(screen_w / 2, -400, screen_h / 2);


            /* Lights */

            // Light sources
            V3      key_light_dir   = new V3(-1, 1, -1);
            Couleur key_light_color = new Couleur(0.8f, 0.8f, 0.8f);
            //Lights.add_light(key_light_dir, key_light_color);

            V3      fill_light_dir   = new V3(1, 1, -1);
            Couleur fill_light_color = new Couleur(0.5f, 0.5f, 0.5f);
            //Lights.add_light(fill_light_dir, fill_light_color);

            V3      point_light_position = new V3(screen_w * 0.5f, Scene.max_y_position / 2, screen_h - 43);
            Couleur point_light_color    = new Couleur(1f, 1f, 1f);

            Lights.add_light(point_light_position, point_light_color, true);

            /* Objects */
            // list of all objects appearing on screen
            List <Object> objects_on_screen = new List <Object>();

            Scene.Room(ref objects_on_screen);
            Scene.Boxes(ref objects_on_screen);
            Scene.Mirror(ref objects_on_screen);
            Scene.Bed(ref objects_on_screen);
            Scene.Ball(ref objects_on_screen);
            Scene.Shelf(ref objects_on_screen);

            // Creates and initialize Z_buffer/ray casting activate + determines the camera position
            Elements.inicialize_Elements(camera_position, true, objects_on_screen);

            // Plot all objects on the screen with the ray casting method

            /*for (int i = 0; i < screen_w; i++)
             * {
             *  for(int j = 0; j < screen_h; j++)
             *  {
             *      Elements.RayCasting(new V3(i, 0, j), objects_on_screen);
             *  }
             * }*/

            V3      ray_direction;
            Couleur c;

            for (int i = 0; i < screen_w; i++)
            {
                for (int j = 0; j < screen_h; j++)
                {
                    ray_direction = new V3(i, 0, j) - Elements.camera_position;
                    ray_direction.Normalize();
                    c = Elements.RayTracer(Elements.camera_position, ray_direction, 0);
                    BitmapEcran.DrawPixel(i, j, c);
                }
            }
        }
Ejemplo n.º 3
0
        public void Draw(double x, double y, Couleur couleur)
        {
            int x_sceem  = (int)((x / (20.0 * this.ration)) * this.resolution_X + this.resolution_X / 2);
            int y_screem = (int)((y / 20.0) * this.resolution_Y + this.resolution_Y / 2);

            //Console.WriteLine("x:"+x_sceem+" y:"+y_screem);
            BitmapEcran.DrawPixel(x_sceem, y_screem, couleur);
        }
Ejemplo n.º 4
0
 //dessine tous les objets de la scène
 public void DrawScene()
 {
     for (int x_ecran = 0; x_ecran <= BitmapEcran.GetWidth(); x_ecran++)
     {
         for (int y_ecran = 0; y_ecran <= BitmapEcran.GetHeight(); y_ecran++)
         {
             V3 PosPixScene = new V3(x_ecran, 0, y_ecran);
             V3 DirRayon    = PosPixScene - PosCamera;
             DirRayon.Normalize();
             Couleur C = RayCast(PosCamera, DirRayon, Objets);
             BitmapEcran.DrawPixel(x_ecran, y_ecran, C);
         }
     }
 }
Ejemplo n.º 5
0
        public void DessineRaycast()
        {
            V3 camera = new V3((float)BitmapEcran.GetWidth() / 2, (float)BitmapEcran.GetWidth() * -1.5f, (float)BitmapEcran.GetHeight() / 2);

            int xmax = BitmapEcran.GetWidth();
            int ymax = BitmapEcran.GetHeight();

            Couleur[,] colorbuffer = new Couleur[xmax, ymax];
            for (int x_ecran = 0; x_ecran < BitmapEcran.GetWidth(); x_ecran++)
            {
                for (int y_ecran = 0; y_ecran < BitmapEcran.GetHeight(); y_ecran++)
                {
                    V3 pixel = new V3((float)x_ecran, 0, (float)y_ecran);
                    V3 rayon = pixel - camera;
                    rayon.Normalize();
                    colorbuffer[x_ecran, y_ecran] = Raycast(camera, rayon);

                    BitmapEcran.DrawPixel(x_ecran, y_ecran, colorbuffer[x_ecran, y_ecran]);
                }
            }
        }