diff --git a/camera.cpp b/camera.cpp index 4bb44d4063182a82b84cff6663faa42dd0add1b7..c8b721004ad12d968f0400b6c17c777a301b81a5 100644 --- a/camera.cpp +++ b/camera.cpp @@ -46,7 +46,7 @@ Camera & Camera::operator=(const Camera & r) std::ostream & operator<<(std::ostream & st, const Camera & c) { st << "position : " << c.position() << std::endl; - st << "direction : " << c.direction(); //<< std::endl; + st << "direction : " << c.direction(); return st; } \ No newline at end of file diff --git a/main.cpp b/main.cpp index 6778c740d28d09de77e8a321e2371d61173dff7e..16bab26d883a51d7c36895376547be11cc132166 100644 --- a/main.cpp +++ b/main.cpp @@ -119,8 +119,6 @@ void test_Scene() Scene scene(c, tab, source); - //std::cout << "scene" << std::endl << scene << std::endl; - std::cout << std::endl << std::endl; } @@ -175,17 +173,6 @@ int main() Ray3f source(Vector3f(width/2, height-1, depth/3), Vector3f(0, -1, 0)); //lumière au plafond Scene scene(camera, shapes, source); - /* reflexion et hit test */ - - /*Ray3f light(Vector3f(71,70,70),Vector3f(-1,-1,-1)); - - std::cout<<"is hit "<<shapes[0]->is_hit(light)<<std::endl; - - if(shapes[0]->is_hit(light)) - { - std::cout<<"origin "<<shapes[0]->reflect(light).origin()<<std::endl; - std::cout<<"direction "<<shapes[0]->reflect(light).direction()<<std::endl; - }*/ //----------CALCUL ET SAUVEGARDE DE L'IMAGE---------- std::cout << "Création de l'image..." << std::endl; diff --git a/material.cpp b/material.cpp index 6457ab7a4267df1197ea362b3b8d39995876da4d..c1fc4cfd11363dc60df00e29c56479a836be20b1 100644 --- a/material.cpp +++ b/material.cpp @@ -25,10 +25,6 @@ Material::Material(const Material & m) shiness_ = m.shiness(); } -/*Material::~Material() -{ - -}*/ float Material::r() const diff --git a/quad.cpp b/quad.cpp index da4f417532ebbe3fcad7552414c9be696bf2ea63..78673ea36687ca8bcb6b4f16d557a3577c2a022b 100644 --- a/quad.cpp +++ b/quad.cpp @@ -1,7 +1,5 @@ #include "quad.h" -//#include <iostream> - Quad::Quad(Material matter, Vector3f origin, float width, float height, float depth) : Shape(matter) @@ -33,7 +31,6 @@ bool Quad::is_hit(const Ray3f ray) float Z = ray.origin().z(); - //Calculs des coordonnées d'intersection avec les faces et vérification float t, x, y, z; @@ -140,7 +137,6 @@ Ray3f Quad::reflect(const Ray3f ray) const Vector3f I = ray.direction(); - //Face 1 if(a!=0 && Vector3f(1,0,0)*ray.direction()<0) { diff --git a/scene.cpp b/scene.cpp index 3263b09af1bf94567cc5e987981318259c59ade2..5ea9a9e5f32d09b2d5a6715753a2bd96641f0c7d 100644 --- a/scene.cpp +++ b/scene.cpp @@ -8,29 +8,16 @@ Scene::Scene(Camera camera, Shape* *shapes, Ray3f source) : camera_(camera), shapes_(shapes), source_(source) { - /*int nb_shapes = sizeof(shapes)/sizeof(Shape); - shapes_ = new Shape[nb_shapes]; - for (int i=0; i<nb_shapes; i++) - shapes_[i] = shapes[i];*/ } Scene::Scene(const Scene & s) : camera_(s.camera()), shapes_(s.shapes()), source_(s.source()) { - /*int nb_shapes = sizeof(s.shapes())/sizeof(Shape); - shapes_ = new Shape[nb_shapes]; - for(int i=0; i<nb_shapes; i++) - shapes_[i] = s.shapes()[i];*/ } -/*Scene::~Scene() -{ - delete [] shapes_; -}*/ - Camera Scene::camera() const { @@ -49,135 +36,6 @@ Ray3f Scene::source() const return source_; } -/* -void Scene::render(int width, int height, int nb_pixel_row, int nb_pixel_col, int nb_shapes, char* filename) -{ - /*--------------------------------Copié de la doc de libpng-------------------------------------*//* - FILE *f = fopen(filename, "wb"); - if (!f) throw "Echec de la création du fichier"; - - png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - if (!png_ptr) - { - fclose(f); - throw "Echec allocation png_ptr"; - } - - png_infop info_ptr = png_create_info_struct(png_ptr); - if (!info_ptr) - { - fclose(f); - png_destroy_write_struct(&png_ptr, (png_infopp) NULL); - throw "Echec allocation info_ptr"; - } - - png_init_io(png_ptr, f); - /*----------------------------------------------------------------------------------------------*//* - - - //Set header - png_set_IHDR(png_ptr, info_ptr, nb_pixel_row, nb_pixel_col, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); - - //Set text - png_text title_text; - title_text.compression = PNG_TEXT_COMPRESSION_NONE; - title_text.text = filename; - png_set_text(png_ptr, info_ptr, &title_text, 0); - - png_write_info(png_ptr, info_ptr); - - - //Mémoire allouée pour une ligne de pixels (rgb => 3 bytes par pixel) - png_bytep row = (png_bytep) png_malloc(png_ptr, 3*nb_pixel_row*sizeof(png_byte)); - - - float pw = (float) width / (float) nb_pixel_col; //largeur d'un pixel - float ph = (float) height / (float) nb_pixel_row; //hauteur d'un pixel - float min_dist; - float hit_dist; - - for (int i=nb_pixel_col-1; i>=0; i--) //on remplit l'image par le bas à droite - { - for (int j=0; j<nb_pixel_row; j++) - { - min_dist = 1000; - Vector3f Pij(j*pw, i*ph, 0); //point de la grille par laquelle on regarde - Ray3f camera_to_grid(camera_.position(), Pij-camera_.position()); - - row[3*(nb_pixel_row-1-j)] = 0; - row[3*(nb_pixel_row-1-j) + 1] = 0; - row[3*(nb_pixel_row-1-j) + 2] = 0; - - for (int k=0; k<nb_shapes; k++) - { - if (shapes_[k]->is_hit(camera_to_grid)) - { - Ray3f reflected(shapes_[k]->reflect(camera_to_grid)); - hit_dist = dist(reflected.origin() , camera_.position()); - - if ( hit_dist < min_dist ) //on regarde l'objet le plus proche de la caméra - { - min_dist = hit_dist; - - bool shadow = false; - Ray3f reflect_to_source(reflected.origin(), source_.origin()-reflected.origin()); - - - for (int l=0; l<nb_shapes; l++) - { - if (l != k) //pour éviter que l'objet se cache lui-même - if (shapes_[l]->is_hit(reflect_to_source)) - if ( dist(reflected.origin() , shapes_[l]->reflect(reflect_to_source).origin()) - < dist(reflected.origin() , source_.origin()) ) - { - shadow = true; - break; - } - } - - //intensité pour harmoniser les ombres selon la distance - float intensity = dist(reflected.origin(), source_.origin()); - intensity = 5000/(intensity*intensity); - - if (shadow) - { - row[3*(nb_pixel_row-1-j)] = fmin(50, 50*intensity); - row[3*(nb_pixel_row-1-j) + 1] = fmin(50, 50*intensity); - row[3*(nb_pixel_row-1-j) + 2] = fmin(50, 50*intensity); - } - - else - { - Ray3f source_to_reflect(source_.origin(), reflected.origin()-source_.origin()); - - //self_shadow - //au lieu de diviser par une constante (2.) diviser par l'angle ? - if ( dist(reflect_to_source.origin() , shapes_[k]->reflect(source_to_reflect).origin()) > 0.05 ) - { - row[3*(nb_pixel_row-1-j)] = fmin(shapes_[k]->matter().r()/2. * intensity, shapes_[k]->matter().r()/2.); - row[3*(nb_pixel_row-1-j) + 1] = fmin(shapes_[k]->matter().g()/2. * intensity, shapes_[k]->matter().g()/2.); - row[3*(nb_pixel_row-1-j) + 2] = fmin(shapes_[k]->matter().b()/2. * intensity, shapes_[k]->matter().b()/2.); - } - - else //il faut rajouter la réflexion et l'angle - { - row[3*(nb_pixel_row-1-j)] = fmin(shapes_[k]->matter().r() * intensity, 255.); - row[3*(nb_pixel_row-1-j) + 1] = fmin(shapes_[k]->matter().g() * intensity, 255.); - row[3*(nb_pixel_row-1-j) + 2] = fmin(shapes_[k]->matter().b() * intensity, 255.); - } - } - } - } - } - } - - png_write_row(png_ptr, row); - } - - png_write_end(png_ptr, NULL); - - fclose(f); -}*/ void Scene::render(int width, int height, int nb_pixel_row, int nb_pixel_col, int nb_shapes, char* filename) @@ -367,12 +225,6 @@ void Scene::reflected_rays(Ray3f **ray, int nb_shapes, int ref_max, float* shin float min_dist; float hit_dist; - /*for(int r=0;r<(ref_max-1);r++) - { - shine[r]=0.0; - }*/ - - for(int r=0;r<(ref_max-1);r++) { min_dist=1000; @@ -412,22 +264,4 @@ void Scene::coeff(float* shine, float* coef, int ref_max) } coef[r]=coef[r]*(1-shine[r]); } -} - - - -/*std::ostream & operator<<(std::ostream & st, const Scene & s) -{ - st << "camera" << std::endl << s.camera() << std::endl; - st << "source" << std::endl << s.source() << std::endl; - - st << "shapes" << std::endl; - Shape* *tab = s.shapes(); - int n = sizeof(tab)/sizeof(Shape*); - st << "size of shapes : " << n << std::endl; - st << sizeof(tab) << " " << sizeof(*tab) << " " << sizeof(**tab) << std::endl; - for (int i=0; i<n; i++) - st << " " << tab[i]->matter() << std::endl; - - return st; -}*/ \ No newline at end of file +} \ No newline at end of file diff --git a/sphere.cpp b/sphere.cpp index c55fda5e97a5929d18672bc1f0a73781cf30735d..f1d417203381fd7b00eb04ef6af386e96a1cfbb3 100644 --- a/sphere.cpp +++ b/sphere.cpp @@ -44,16 +44,10 @@ Ray3f Sphere::reflect(const Ray3f ray) const float delta = b*b - 4*a*c; - if(delta<0) - { - /*std::cout << "ray" << std::endl << ray << std::endl; - std::cout << "a : " << a << std::endl; - std::cout << "b : " << b << std::endl; - std::cout << "c : " << c << std::endl; - std::cout << "delta : " << delta << std::endl;*/ - delta = -delta; - //throw "object is not hit"; - } + //Si delta<0, l'objet n'est pas rencontré + //Or cette condition est vérifiée avant par is_hit + //delta<0 si il ya des erreurs d'arrondis seulement + if(delta<0) delta = -delta; float k = (-b-sqrt(delta)) / (2*a);