Skip to content
Extraits de code Groupes Projets
Valider 22135f25 rédigé par Lénaïc DURAND's avatar Lénaïc DURAND
Parcourir les fichiers

Merge branch 'master' of git.iiens.net:acherouf2018/pap_ray_tracing

parents 027aa69c 4ed3602c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -167,7 +167,7 @@ int main()
shapes[2] = new Quad(white, Vector3f(width/2, height, depth/2), width, 0, depth); //plafond
shapes[3] = new Quad(cyan, Vector3f(0, height/2, depth/2), 0, height, depth); //mur droit
shapes[4] = new Quad(grey, Vector3f(width/2, 0, depth/2), width, 0, depth); //sol
shapes[5] = new Quad(red, Vector3f(width/4, 20, depth-20), 40, 40, 40); //cube
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
......
#include "quad.h"
#include <iostream>
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)
//x = x1;
y = Y + b*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;
}
......@@ -53,7 +55,7 @@ bool Quad::is_hit(const Ray3f ray)
x = X + a*t;
//y = y2;
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;
}
......@@ -65,7 +67,7 @@ bool Quad::is_hit(const Ray3f ray)
x = X + a*t;
y = Y + b*t;
//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;
}
......@@ -77,7 +79,7 @@ bool Quad::is_hit(const Ray3f ray)
//x = x4;
y = Y + b*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;
}
......@@ -89,7 +91,7 @@ bool Quad::is_hit(const Ray3f ray)
x = X + a*t;
//y = y5;
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;
}
......@@ -101,7 +103,7 @@ bool Quad::is_hit(const Ray3f ray)
x = X + a*t;
y = Y + b*t;
//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;
}
......@@ -131,7 +133,7 @@ Ray3f Quad::reflect(const Ray3f ray) const
//Calculs des coordonnées d'intersection avec les faces et vérification
float t, x, y, z;
float t, x, y ,z;
Vector3f hit;
......@@ -139,40 +141,65 @@ Ray3f Quad::reflect(const Ray3f ray) const
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)
{
std::cout << "a!=0 face 1 ou 4" << std::endl;
t = (x1 - X) / a ;
//x = x1;
y = Y + b*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 N = hit-origin_;
Vector3f N = Vector3f(-1,0,0);
N.normalize();
return Ray3f(hit, I-(I*N)*N);
}
}
//Face 2
if(b!=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 && z3<=z)
if (t>0 && x4<=x && x<=x1 && z6<=z && z<=z3)
{
Vector3f hit = ray.origin() + t*ray.direction();
Vector3f N = hit-origin_;
Vector3f N = Vector3f(0,1,0);
N.normalize();
return Ray3f(hit, I-(I*N)*N);
}
}
//Face 3
if(c!=0)
{
std::cout << "c!=0 face 3" << std::endl;
t = (z3 - Z) / c ;
x = X + a*t;
y = Y + b*t;
......@@ -180,40 +207,31 @@ Ray3f Quad::reflect(const Ray3f ray) const
if (t>0 && x4<=x && x<=x1 && y5<=y && y<=y2)
{
Vector3f hit = ray.origin() + t*ray.direction();
Vector3f N = hit-origin_;
Vector3f N = Vector3f(0,0,1);
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 = hit-origin_;
N.normalize();
}
}
//Face 5
if(b!=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 && z3<=z)
if (t>0 && x4<=x && x<=x1 && z6<=z && z<=z3)
{
Vector3f hit = ray.origin() + t*ray.direction();
Vector3f N = hit-origin_;
Vector3f N = Vector3f(0,-1,0);
N.normalize();
return Ray3f(hit, I-(I*N)*N);
}
}
......@@ -221,6 +239,7 @@ Ray3f Quad::reflect(const Ray3f ray) const
//Face 6
if(c!=0)
{
std::cout << "c!=0 face 6" << std::endl;
t = (z6 - Z) / c ;
x = X + a*t;
y = Y + b*t;
......@@ -228,12 +247,13 @@ Ray3f Quad::reflect(const Ray3f ray) const
if (t>0 && x4<=x && x<=x1 && y5<=y && y<=y2)
{
Vector3f hit = ray.origin() + t*ray.direction();
Vector3f N = hit-origin_;
Vector3f N = Vector3f(0,0,-1);
N.normalize();
return Ray3f(hit, I-(I*N)*N);
}
}
return Ray3f(hit, I-(I*N)*N);
}
......
......@@ -6,6 +6,7 @@ Ray3f::Ray3f(const Vector3f & ori, const Vector3f & dir)
{
origin_ = ori;
direction_ = dir;
direction_.normalize();
}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter