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

début render

parent 22135f25
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
0.png

9,66 ko | W: | H:

0.png

8 ko | W: | H:

0.png
0.png
0.png
0.png
  • 2-up
  • Swipe
  • Onion skin
Aucun aperçu pour ce type de fichier
......@@ -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);
......
#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;
......
......@@ -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,12 +106,18 @@ void Scene::render(int width, int height, int nb_pixel_row, int nb_pixel_col, in
{
if (shapes_[k]->is_hit(camera_to_grid))
{
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();
}
}
}
}
png_write_row(png_ptr, row);
}
......
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