diff --git a/quad.cpp b/quad.cpp index 1a208082128c95072e4f43b2ae2a104ce741c35c..39874e4a1efedd522625e9e3ab9329646c9ea1f4 100644 --- a/quad.cpp +++ b/quad.cpp @@ -141,49 +141,33 @@ 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; - //Face 1 et 4 - if(a!=0) + //Face 1 + if(a!=0 && Vector3f(1,0,0)*ray.direction()<0) { - std::cout << "a!=0 face 1 ou 4" << std::endl; t = (x1 - X) / a ; - //x = x1; - y = Y + b*t; - z = Z + c*t; - - t = (x4 - X) / a ; - //x = x4; - y = Y + b*t; + //x = X; + y = y + b*t; z = Z + c*t; - - - if (y5<=y && y<= y2 && z6<=z && z<=z3) + if (y5<=y && y<=y2 && z6<=z && z<=z3) { Vector3f hit = ray.origin() + t*ray.direction(); - Vector3f N = Vector3f(-1,0,0); + Vector3f N = Vector3f(0,1,0); N.normalize(); return Ray3f(hit, I-(I*N)*N); } - } - - //Face 2 - if(b!=0) + if(b!=0 && Vector3f(0,1,0)*ray.direction()<0) { - std::cout << "b!=0 face 2" << std::endl; - t = (y2 - Y) / b ; x = X + a*t; //y = y2; z = Z + c*t; - if (t>0 && x4<=x && x<=x1 && z6<=z && z<=z3) + if (x4<=x && x<=x1 && z6<=z && z<=z3) { Vector3f hit = ray.origin() + t*ray.direction(); Vector3f N = Vector3f(0,1,0); @@ -191,20 +175,17 @@ Ray3f Quad::reflect(const Ray3f ray) const return Ray3f(hit, I-(I*N)*N); } - - } //Face 3 - if(c!=0) + if(c!=0 && Vector3f(0,0,1)*ray.direction()<0) { - std::cout << "c!=0 face 3" << std::endl; t = (z3 - Z) / c ; x = X + a*t; y = Y + b*t; //z = z3; - if (t>0 && x4<=x && x<=x1 && y5<=y && y<=y2) + if (x4<=x && x<=x1 && y5<=y && y<=y2) { Vector3f hit = ray.origin() + t*ray.direction(); Vector3f N = Vector3f(0,0,1); @@ -214,19 +195,33 @@ Ray3f Quad::reflect(const Ray3f ray) const } + //Face 4 + if(a!=0 && Vector3f(-1,0,0)*ray.direction()<0) + { + t = (x4 - X) / a ; + //x = X; + y = y + b*t; + z = Z + c*t; + if (y5<=y && y<=y2 && z6<=z && z<=z3) + { + Vector3f hit = ray.origin() + t*ray.direction(); + Vector3f N = Vector3f(0,1,0); + N.normalize(); + return Ray3f(hit, I-(I*N)*N); + } + } //Face 5 - if(b!=0) + if(b!=0 && Vector3f(0,-1,0)*ray.direction()<0) { - std::cout << "b!=0 face 5" << std::endl; t = (y5 - Y) / b ; x = X + a*t; //y = y5; z = Z + c*t; - if (t>0 && x4<=x && x<=x1 && z6<=z && z<=z3) + if (x4<=x && x<=x1 && z6<=z && z<=z3) { Vector3f hit = ray.origin() + t*ray.direction(); Vector3f N = Vector3f(0,-1,0); @@ -237,14 +232,13 @@ Ray3f Quad::reflect(const Ray3f ray) const //Face 6 - if(c!=0) + if(c!=0 && Vector3f(0,0,-1)*ray.direction()<0) { - std::cout << "c!=0 face 6" << std::endl; t = (z6 - Z) / c ; x = X + a*t; y = Y + b*t; //z = z6; - if (t>0 && x4<=x && x<=x1 && y5<=y && y<=y2) + if (x4<=x && x<=x1 && y5<=y && y<=y2) { Vector3f hit = ray.origin() + t*ray.direction(); Vector3f N = Vector3f(0,0,-1);