diff --git a/0.png b/0.png index 26fd209a570fcbced0554a97d7aec26ec4372ca4..56eda737ae64a7c9219dec76659d45b15ba6cde0 100644 Binary files a/0.png and b/0.png differ diff --git a/main b/main index fb5cbdad93febbdd58074c5002cc95defe2432a6..293b261914ab8be42dd2ff0ca370f0460e7fb840 100644 Binary files a/main and b/main differ diff --git a/main.cpp b/main.cpp index e0fa32a09c17e8354d717f69445b86531f920be3..0737401b3cc7019063baf8112c273749499dd2d8 100644 --- a/main.cpp +++ b/main.cpp @@ -170,7 +170,7 @@ int main() shapes[5] = new Quad(red, Vector3f(50, 50, 50), 5, 5, 5); //cube shapes[6] = new Sphere(blue, Vector3f(3/4*width, 20, depth/2), 40); //sphere - Camera camera(Vector3f(width/2, height/2, -1), Vector3f(0, 0, 1)); //on met la caméra un peu en recul + Camera camera(Vector3f(width/2, height/2, -30), Vector3f(0, 0, 1)); //on met la caméra un peu en recul Ray3f source(Vector3f(width/2, height, depth/2), Vector3f(0, -1, 0)); //lumière au plafonc Scene scene(camera, shapes, source); diff --git a/quad.cpp b/quad.cpp index 1a208082128c95072e4f43b2ae2a104ce741c35c..13402244eff244693768c55f7032b6b21aeb805f 100644 --- a/quad.cpp +++ b/quad.cpp @@ -1,6 +1,6 @@ #include "quad.h" -#include <iostream> +//#include <iostream> @@ -131,7 +131,6 @@ Ray3f Quad::reflect(const Ray3f ray) const float Z = ray.origin().z(); - //Calculs des coordonnées d'intersection avec les faces et vérification float t, x, y ,z; @@ -141,14 +140,14 @@ Ray3f Quad::reflect(const Ray3f ray) const Vector3f I = ray.direction(); - std::cout << "a=" <<a << std::endl; - std::cout << "b=" <<a << std::endl; - std::cout << "c=" <<a << std::endl; + //std::cout << "a=" <<a << std::endl; + //std::cout << "b=" <<a << std::endl; + //std::cout << "c=" <<a << std::endl; //Face 1 et 4 if(a!=0) { - std::cout << "a!=0 face 1 ou 4" << std::endl; + //std::cout << "a!=0 face 1 ou 4" << std::endl; t = (x1 - X) / a ; //x = x1; y = Y + b*t; @@ -177,7 +176,7 @@ Ray3f Quad::reflect(const Ray3f ray) const //Face 2 if(b!=0) { - std::cout << "b!=0 face 2" << std::endl; + //std::cout << "b!=0 face 2" << std::endl; t = (y2 - Y) / b ; x = X + a*t; @@ -199,7 +198,7 @@ Ray3f Quad::reflect(const Ray3f ray) const //Face 3 if(c!=0) { - std::cout << "c!=0 face 3" << std::endl; + //std::cout << "c!=0 face 3" << std::endl; t = (z3 - Z) / c ; x = X + a*t; y = Y + b*t; @@ -221,7 +220,7 @@ Ray3f Quad::reflect(const Ray3f ray) const //Face 5 if(b!=0) { - std::cout << "b!=0 face 5" << std::endl; + //std::cout << "b!=0 face 5" << std::endl; t = (y5 - Y) / b ; x = X + a*t; //y = y5; @@ -239,7 +238,7 @@ Ray3f Quad::reflect(const Ray3f ray) const //Face 6 if(c!=0) { - std::cout << "c!=0 face 6" << std::endl; + //std::cout << "c!=0 face 6" << std::endl; t = (z6 - Z) / c ; x = X + a*t; y = Y + b*t; diff --git a/scene.cpp b/scene.cpp index f541ab7dbe867e761b401b4ce246de80906e0d10..25e5e63e97e4a489a890403fdd345c78761597ba 100644 --- a/scene.cpp +++ b/scene.cpp @@ -87,10 +87,14 @@ void Scene::render(int width, int height, int nb_pixel_row, int nb_pixel_col, in float pw = width / nb_pixel_row; float ph = height / nb_pixel_col; + float min_dist; + float hit_dist; + for (int i=0; i<nb_pixel_row; i++) { for (int j=0; j<nb_pixel_col; j++) { + min_dist = 1000; Vector3f Pij(i*pw, j*ph, 0); //point de la grille par laquelle on regarde Ray3f camera_to_grid(camera_.position(), Pij-camera_.position()); @@ -102,9 +106,15 @@ void Scene::render(int width, int height, int nb_pixel_row, int nb_pixel_col, in { if (shapes_[k]->is_hit(camera_to_grid)) { - row[3*i] = shapes_[k]->matter().r(); - row[3*i + 1] = shapes_[k]->matter().g(); - row[3*i + 2] = shapes_[k]->matter().b(); + hit_dist = dist(shapes_[k]->reflect(camera_to_grid).origin() , camera_.position()); + //printf("hit_dist : %f\n", hit_dist); + if ( hit_dist < min_dist ) + { + min_dist = hit_dist; + row[3*i] = shapes_[k]->matter().r(); + row[3*i + 1] = shapes_[k]->matter().g(); + row[3*i + 2] = shapes_[k]->matter().b(); + } } } }