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

correction bug transparence, fonction closer

parent a1102ee3
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
2.png

94,4 ko | W: | H:

2.png

118 ko | W: | H:

2.png
2.png
2.png
2.png
  • 2-up
  • Swipe
  • Onion skin
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
/*! /*!
* \file camera.h * \file camera.h
* \brief Representation d'une camera, similaire a un rayon * \brief Représentation d'une camera, similaire à un rayon
*/ */
#include "vector3f.h" #include "vector3f.h"
......
Aucun aperçu pour ce type de fichier
...@@ -145,7 +145,7 @@ int main() ...@@ -145,7 +145,7 @@ int main()
Material green(0, 255, 0, 0); Material green(0, 255, 0, 0);
Material blue(0, 0, 255, 0); Material blue(0, 0, 255, 0);
Material yellow(255, 255, 0, 0); Material yellow(255, 255, 0, 0);
Material magenta(255, 0, 255, 0); Material magenta(255, 0, 255, 0.3);
Material cyan(0, 255, 255, 0); Material cyan(0, 255, 255, 0);
Material white(255, 255, 255, 0); Material white(255, 255, 255, 0);
Material grey(122, 122, 122, 0); Material grey(122, 122, 122, 0);
...@@ -168,7 +168,7 @@ int main() ...@@ -168,7 +168,7 @@ int main()
shapes[2] = new Quad(white, Vector3f(width/2, height, depth/2), width, 0, depth); //plafond 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[3] = new Quad(cyan, Vector3f(0, height/2, depth/2), 0, height, depth); //mur droit
shapes[4] = new Quad(green, Vector3f(width/2, 0, depth/2), width, 0, depth); //sol shapes[4] = new Quad(green, Vector3f(width/2, 0, depth/2), width, 0, depth); //sol
shapes[5] = new Quad(mirror, Vector3f(15, 25, 20), 10, 10, 10); //cube shapes[5] = new Quad(red, Vector3f(22, 15, 20), 10, 10, 10); //cube
shapes[6] = new Sphere(mirror, Vector3f(75, 20, 70), 20); //sphere shapes[6] = new Sphere(mirror, Vector3f(75, 20, 70), 20); //sphere
Camera camera(Vector3f(width/2, height/2, -50), Vector3f(0, 0, 1)); //on met la caméra un peu en recul Camera camera(Vector3f(width/2, height/2, -50), Vector3f(0, 0, 1)); //on met la caméra un peu en recul
......
...@@ -247,20 +247,15 @@ void Scene::render(int width, int height, int nb_pixel_row, int nb_pixel_col, in ...@@ -247,20 +247,15 @@ void Scene::render(int width, int height, int nb_pixel_row, int nb_pixel_col, in
row[3*(nb_pixel_row-1-j) + 1] = 0; row[3*(nb_pixel_row-1-j) + 1] = 0;
row[3*(nb_pixel_row-1-j) + 2] = 0; row[3*(nb_pixel_row-1-j) + 2] = 0;
for(int r=0;r<ref_max-1;r++) for(int r=0;r<ref_max-1;r++)
{ {
min_dist = 1000; int k = closer(nb_shapes, *ray[r]);
for (int k=0; k<nb_shapes; k++)
{
if (shapes_[k]->is_hit(*ray[r]))
{
Ray3f reflected(shapes_[k]->reflect(*ray[r]));
hit_dist = dist(reflected.origin() , ray[r]->origin());
if ( hit_dist < min_dist ) //on regarde l'objet le plus proche de la caméra if (k != -1)
{ {
min_dist = hit_dist; Ray3f reflected(shapes_[k]->reflect(*ray[r]));
bool shadow = false; bool shadow = false;
Ray3f reflect_to_source(reflected.origin(), source_.origin()-reflected.origin()); Ray3f reflect_to_source(reflected.origin(), source_.origin()-reflected.origin());
...@@ -314,8 +309,6 @@ void Scene::render(int width, int height, int nb_pixel_row, int nb_pixel_col, in ...@@ -314,8 +309,6 @@ void Scene::render(int width, int height, int nb_pixel_row, int nb_pixel_col, in
} }
} }
} }
}
}
png_write_row(png_ptr, row); png_write_row(png_ptr, row);
} }
...@@ -330,23 +323,55 @@ void Scene::render(int width, int height, int nb_pixel_row, int nb_pixel_col, in ...@@ -330,23 +323,55 @@ void Scene::render(int width, int height, int nb_pixel_row, int nb_pixel_col, in
} }
/*
arg : le nombre d'objets
le rayon pour lequel on veut savoir quel objet il va rencontrer
ret : -1 si le rayon ne rencontre rien
l'indice de la shape la plus proche (celle où il faudra faire les calculs)
*/
int Scene::closer(int nb_shapes, Ray3f start)
{
float min_dist = 1000;
float hit_dist;
int res = -1;
for (int k=0; k<nb_shapes; k++)
if (shapes_[k]->is_hit(start))
{
Ray3f reflected(shapes_[k]->reflect(start));
hit_dist = dist(reflected.origin() , start.origin());
if ( hit_dist < min_dist )
{
min_dist = hit_dist;
res = k;
}
}
return res;
}
/*modifie ray et shine, ray est de taille (ref_max) et shine de taille (ref_max-1) à la fin /*modifie ray et shine, ray est de taille (ref_max) et shine de taille (ref_max-1) à la fin
ray doit contenir le rayon camera Pij initiallement ray doit contenir le rayon camera Pij initialement
à la fin on rajoute à ray toutes les reflexions et à shines à la fin on rajoute à ray toutes les reflexions et à shines
les coeff des couleurs càd les coeff des couleurs càd
shine={(1-a1) , a1*(1-a2) , a1*a2*(1-a3) ...}*/ coef={(1-a1) , a1*(1-a2) , a1*a2*(1-a3) ...}*/
int Scene::nb_reflected(Ray3f **ray, int nb_shapes, int ref_max, float* shine){ int Scene::nb_reflected(Ray3f **ray, int nb_shapes, int ref_max, float* shine)
{
bool vide=false; bool vide=false;
float min_dist; float min_dist;
float hit_dist; float hit_dist;
for(int r=0;r<(ref_max-1);r++) /*for(int r=0;r<(ref_max-1);r++)
{ {
shine[r]=0.0; shine[r]=0.0;
} }*/
for(int r=0;r<(ref_max-1);r++) for(int r=0;r<(ref_max-1);r++)
......
...@@ -33,6 +33,7 @@ class Scene ...@@ -33,6 +33,7 @@ class Scene
Ray3f source() const; Ray3f source() const;
void render(int width, int height, int nb_pixel_row, int nb_pixel_col, int nb_shapes, char* filename); void render(int width, int height, int nb_pixel_row, int nb_pixel_col, int nb_shapes, char* filename);
int closer(int nb_shapes, Ray3f start);
int nb_reflected(Ray3f **ray, int nb_shapes, int ref_max, float* shine); int nb_reflected(Ray3f **ray, int nb_shapes, int ref_max, float* shine);
void coeff(float* shine, float* coef, int ref_max); void coeff(float* shine, float* coef, int ref_max);
}; };
......
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