Exemplo n.º 1
0
int main() {
   const int height = 2000;
   const int width = 2000;
        
   ofstream image;
   image.open("out.ppm");
   image << "P3" << '\n' << width << ' ' << height << '\n' << 255 << '\n';
        
   Point camera(0,0,0);
        
   Light lights [3] = { Light(Point(1200,0,800), Colour(255,0,0)),
                        Light(Point(1200,800,0), Colour(0,255,0)),
                        Light(Point(1200,-800,0), Colour(0,0,255)) };
        
   Colour background;

   Sphere sphere(Point(2000,0,0),700);

   Point plane_point;
   Point surface_point;
        
   //std::cout << illuminate(Point(0,0,0),Vector(2,2,2),Light(Point(4,4,4),Colour(2,2,2))).convertToString() << std::endl;
        
   //std::cout << Line(Point(0,0,0),Vector(1,0,0)).intersect(Sphere(Point(10,0,0),2)) << std::endl;
        
   Line ray;
   Vector direction;
   Colour point_colour;
   for (int z = 1000; z > -1000; z-=1) {
      for (int y = -1000; y < 1000; y+=1) {
         plane_point = Point(1000,y,z);
         direction = plane_point - camera;

         ray = Line(camera, direction);

         if (ray.intersect(sphere)) {
            surface_point = ray.point_intersect(sphere);
            point_colour = illuminate(surface_point, surface_point - sphere.center(), lights);
            point_colour = boundColour(point_colour, 0, 255);
            image << point_colour.convertToString() << ' ';
            //image << "255 255 255 ";
         } else {
            image << background.convertToString() << ' ';
         }
      }
      image << '\n';
   }

   image.close();

   return 0;
}