Skip to content
Extraits de code Groupes Projets
Valider 4ed3602c rédigé par DBA_3's avatar DBA_3
Parcourir les fichiers

is_hit

parent 902290eb
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
#include "quad.h" #include "quad.h"
#include <iostream>
Quad::Quad(Material matter, Vector3f origin, float width, float height, float depth) : Shape(matter) Quad::Quad(Material matter, Vector3f origin, float width, float height, float depth) : Shape(matter)
...@@ -42,7 +44,7 @@ bool Quad::is_hit(const Ray3f ray) ...@@ -42,7 +44,7 @@ bool Quad::is_hit(const Ray3f ray)
//x = x1; //x = x1;
y = Y + b*t; y = Y + b*t;
z = Z + c*t; z = Z + c*t;
if (t>0 && y5<=y && y<=y2 && z6<=z && z3<=z) if (Vector3f(1,0,0)*ray.direction()<0 && t>0 && y5<=y && y<=y2 && z6<=z && z<=z3)
return true; return true;
} }
...@@ -53,7 +55,7 @@ bool Quad::is_hit(const Ray3f ray) ...@@ -53,7 +55,7 @@ bool Quad::is_hit(const Ray3f ray)
x = X + a*t; x = X + a*t;
//y = y2; //y = y2;
z = Z + c*t; z = Z + c*t;
if (t>0 && x4<=x && x<=x1 && z6<=z && z3<=z) if (Vector3f(0,1,0)*ray.direction()<0 && t>0 && x4<=x && x<=x1 && z6<=z && z<=z3)
return true; return true;
} }
...@@ -65,7 +67,7 @@ bool Quad::is_hit(const Ray3f ray) ...@@ -65,7 +67,7 @@ bool Quad::is_hit(const Ray3f ray)
x = X + a*t; x = X + a*t;
y = Y + b*t; y = Y + b*t;
//z = z3; //z = z3;
if (t>0 && x4<=x && x<=x1 && y5<=y && y<=y2) if (Vector3f(0,0,1)*ray.direction()<0 && t>0 && x4<=x && x<=x1 && y5<=y && y<=y2)
return true; return true;
} }
...@@ -77,7 +79,7 @@ bool Quad::is_hit(const Ray3f ray) ...@@ -77,7 +79,7 @@ bool Quad::is_hit(const Ray3f ray)
//x = x4; //x = x4;
y = Y + b*t; y = Y + b*t;
z = Z + c*t; z = Z + c*t;
if (t>0 && y5<=y && y<= y2 && z6<=z && z3<=z) if (Vector3f(-1,0,0)*ray.direction()<0 && t>0 && y5<=y && y<= y2 && z6<=z && z<=z3)
return true; return true;
} }
...@@ -89,7 +91,7 @@ bool Quad::is_hit(const Ray3f ray) ...@@ -89,7 +91,7 @@ bool Quad::is_hit(const Ray3f ray)
x = X + a*t; x = X + a*t;
//y = y5; //y = y5;
z = Z + c*t; z = Z + c*t;
if (t>0 && x4<=x && x<=x1 && z6<=z && z3<=z) if (Vector3f(0,-1,0)*ray.direction()<0 && t>0 && x4<=x && x<=x1 && z6<=z && z<=z3)
return true; return true;
} }
...@@ -101,7 +103,7 @@ bool Quad::is_hit(const Ray3f ray) ...@@ -101,7 +103,7 @@ bool Quad::is_hit(const Ray3f ray)
x = X + a*t; x = X + a*t;
y = Y + b*t; y = Y + b*t;
//z = z6; //z = z6;
if (t>0 && x4<=x && x<=x1 && y5<=y && y<=y2) if (Vector3f(0,0,-1)*ray.direction()<0 && t>0 && x4<=x && x<=x1 && y5<=y && y<=y2)
return true; return true;
} }
...@@ -139,40 +141,65 @@ Ray3f Quad::reflect(const Ray3f ray) const ...@@ -139,40 +141,65 @@ Ray3f Quad::reflect(const Ray3f ray) const
Vector3f I = ray.direction(); Vector3f I = ray.direction();
//Face 1 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) if(a!=0)
{ {
std::cout << "a!=0 face 1 ou 4" << std::endl;
t = (x1 - X) / a ; t = (x1 - X) / a ;
//x = x1; //x = x1;
y = Y + b*t; y = Y + b*t;
z = Z + c*t; z = Z + c*t;
if (t>0 && y5<=y && y<=y2 && z6<=z && z3<=z)
t = (x4 - X) / a ;
//x = x4;
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 hit = ray.origin() + t*ray.direction();
Vector3f N = Vector3f(1,0,0); Vector3f N = Vector3f(-1,0,0);
N.normalize(); N.normalize();
return Ray3f(hit, I-(I*N)*N);
} }
} }
//Face 2 //Face 2
if(b!=0) if(b!=0)
{ {
std::cout << "b!=0 face 2" << std::endl;
t = (y2 - Y) / b ; t = (y2 - Y) / b ;
x = X + a*t; x = X + a*t;
//y = y2; //y = y2;
z = Z + c*t; z = Z + c*t;
if (t>0 && x4<=x && x<=x1 && z6<=z && z3<=z) if (t>0 && x4<=x && x<=x1 && z6<=z && z<=z3)
{ {
Vector3f hit = ray.origin() + t*ray.direction(); Vector3f hit = ray.origin() + t*ray.direction();
Vector3f N = Vector3f(0,1,0); Vector3f N = Vector3f(0,1,0);
N.normalize(); N.normalize();
return Ray3f(hit, I-(I*N)*N);
} }
} }
//Face 3 //Face 3
if(c!=0) if(c!=0)
{ {
std::cout << "c!=0 face 3" << std::endl;
t = (z3 - Z) / c ; t = (z3 - Z) / c ;
x = X + a*t; x = X + a*t;
y = Y + b*t; y = Y + b*t;
...@@ -182,38 +209,29 @@ Ray3f Quad::reflect(const Ray3f ray) const ...@@ -182,38 +209,29 @@ Ray3f Quad::reflect(const Ray3f ray) const
Vector3f hit = ray.origin() + t*ray.direction(); Vector3f hit = ray.origin() + t*ray.direction();
Vector3f N = Vector3f(0,0,1); Vector3f N = Vector3f(0,0,1);
N.normalize(); N.normalize();
return Ray3f(hit, I-(I*N)*N);
} }
} }
//Face 4
if(a!=0)
{
t = (x4 - X) / a ;
//x = x4;
y = Y + b*t;
z = Z + c*t;
if (t>0 && y5<=y && y<= y2 && z6<=z && z3<=z)
{
Vector3f hit = ray.origin() + t*ray.direction();
Vector3f N = Vector3f(-1,0,0);
N.normalize();
}
}
//Face 5 //Face 5
if(b!=0) if(b!=0)
{ {
std::cout << "b!=0 face 5" << std::endl;
t = (y5 - Y) / b ; t = (y5 - Y) / b ;
x = X + a*t; x = X + a*t;
//y = y5; //y = y5;
z = Z + c*t; z = Z + c*t;
if (t>0 && x4<=x && x<=x1 && z6<=z && z3<=z) if (t>0 && x4<=x && x<=x1 && z6<=z && z<=z3)
{ {
Vector3f hit = ray.origin() + t*ray.direction(); Vector3f hit = ray.origin() + t*ray.direction();
Vector3f N = Vector3f(0,-1,0); Vector3f N = Vector3f(0,-1,0);
N.normalize(); N.normalize();
return Ray3f(hit, I-(I*N)*N);
} }
} }
...@@ -221,6 +239,7 @@ Ray3f Quad::reflect(const Ray3f ray) const ...@@ -221,6 +239,7 @@ Ray3f Quad::reflect(const Ray3f ray) const
//Face 6 //Face 6
if(c!=0) if(c!=0)
{ {
std::cout << "c!=0 face 6" << std::endl;
t = (z6 - Z) / c ; t = (z6 - Z) / c ;
x = X + a*t; x = X + a*t;
y = Y + b*t; y = Y + b*t;
...@@ -230,10 +249,11 @@ Ray3f Quad::reflect(const Ray3f ray) const ...@@ -230,10 +249,11 @@ Ray3f Quad::reflect(const Ray3f ray) const
Vector3f hit = ray.origin() + t*ray.direction(); Vector3f hit = ray.origin() + t*ray.direction();
Vector3f N = Vector3f(0,0,-1); Vector3f N = Vector3f(0,0,-1);
N.normalize(); N.normalize();
return Ray3f(hit, I-(I*N)*N);
} }
} }
return Ray3f(hit, I-(I*N)*N);
} }
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter