#include "Object.h" #include "Ray.h" #include "Camera.h" #include "Sphere.h" #include "Plane.h" #include "read_json.h" #include "viewing_ray.h" #include "first_hit.h" #include #include #include #include #include #include // stb is a library commonly used when one wants to save an image in C++, // since only one or two headers need to be included. #define STB_IMAGE_WRITE_IMPLEMENTATION #include "stb_image_write.h" int main(int argc, char * argv[]) { // parse command line arguments std::string path_to_json; if (argc == 2) { std::string args = argv[1]; // check if ends with .json if (args.size() > 5 && args.substr(args.size() - 4, 4) == "json") { path_to_json = args; } } if (argc != 2 || path_to_json.empty()) { printf( "Error: received unexpected command line arguments. \n" "Correct usage: \n" " Linux: ./raycasting \n" " Windows: raycasting.exe \n" "For example: \n" " Linux: ./raycasting ../data/sphere-and-plane.json \n" " Windows: raycasting.exe ../../../data/sphere-and-plane.json \n" ); return -1; } // list of colors used for per-object id coloring const std::vector color_map = { 228,26,28, 55,126,184, 77,175,74, 152,78,163, 255,127,0, 255,255,51, 166,86,40, 247,129,191, 153,153,153 }; Camera camera; std::vector< std::shared_ptr > objects; // Read a camera and scene description from given .json file read_json(path_to_json,camera,objects); int width = 640; int height = 360; std::vector id_image(3*width*height); std::vector normal_image(3*width*height); std::vector depth_image(1*width*height); // print a loading bar for (int i = 0; i < 36; i++) printf("%c", 176); printf("\r"); // For each pixel (i,j) for(int i=0; i