From d34ad6a60b031da5527a44fbebf91a1c5829e1ba Mon Sep 17 00:00:00 2001 From: NADAL Jean-Baptiste Date: Tue, 19 Mar 2024 10:32:03 +0100 Subject: [PATCH] [FEAT] Add skeleton for final image of chap13 --- apps/chapter_13.cpp | 132 +++++++++++++++++++++++++++++++++- raytracing/src/core/color.cpp | 23 +++++- raytracing/src/core/color.h | 6 +- 3 files changed, 158 insertions(+), 3 deletions(-) diff --git a/apps/chapter_13.cpp b/apps/chapter_13.cpp index 7f0afa4..c6ec9d9 100644 --- a/apps/chapter_13.cpp +++ b/apps/chapter_13.cpp @@ -47,7 +47,9 @@ int main(void) Camera the_camera; Canvas the_canvas; Plane *the_floor; - Cylinder *the_cylinder; + Cylinder *the_cylinder, *the_glass_cylinder; + Cylinder *the_concentric_cylinder1, *the_concentric_cylinder2, *the_concentric_cylinder3, *the_concentric_cylinder4; + Cylinder *the_decorative_cylinder1, *the_decorative_cylinder2, *the_decorative_cylinder3, *the_decorative_cylinder4; chrono::time_point the_start, the_end; printf("Chapter 13 example.\n"); @@ -77,6 +79,134 @@ int main(void) the_cylinder_material.set_reflective(0.9); the_world.add_object(the_cylinder); + // Concentric Cylinder 1 + the_concentric_cylinder1 = new Cylinder(); + the_concentric_cylinder1->set_minimum(0); + the_concentric_cylinder1->set_maximum(0.2); + the_concentric_cylinder1->set_transform(Matrix::translation(1, 0, 0) * + Matrix::scaling(0.8, 1, 0.8)); + Material &the_concentric_cylinder1_material = the_concentric_cylinder1->material(); + the_concentric_cylinder1_material.set_color(Color(1, 1, 0.3)); + the_concentric_cylinder1_material.set_ambient(0.1); + the_concentric_cylinder1_material.set_diffuse(0.8); + the_concentric_cylinder1_material.set_specular(0.9); + the_concentric_cylinder1_material.set_shininess(300); + the_world.add_object(the_concentric_cylinder1); + + // Concentric Cylinder 2 + the_concentric_cylinder2 = new Cylinder(); + the_concentric_cylinder2->set_minimum(0); + the_concentric_cylinder2->set_maximum(0.3); + the_concentric_cylinder2->set_transform(Matrix::translation(1, 0, 0) * + Matrix::scaling(0.6, 1, 0.6)); + Material &the_concentric_cylinder2_material = the_concentric_cylinder2->material(); + the_concentric_cylinder2_material.set_color(Color(1, 0.9, 0.4)); + the_concentric_cylinder2_material.set_ambient(0.1); + the_concentric_cylinder2_material.set_diffuse(0.8); + the_concentric_cylinder2_material.set_specular(0.9); + the_concentric_cylinder2_material.set_shininess(300); + the_world.add_object(the_concentric_cylinder2); + + // Concentric Cylinder 3 + the_concentric_cylinder3 = new Cylinder(); + the_concentric_cylinder3->set_minimum(0); + the_concentric_cylinder3->set_maximum(0.4); + the_concentric_cylinder3->set_transform(Matrix::translation(1, 0, 0) * + Matrix::scaling(0.4, 1, 0.4)); + Material &the_concentric_cylinder3_material = the_concentric_cylinder3->material(); + the_concentric_cylinder3_material.set_color(Color(1, 0.8, 0.5)); + the_concentric_cylinder3_material.set_ambient(0.1); + the_concentric_cylinder3_material.set_diffuse(0.8); + the_concentric_cylinder3_material.set_specular(0.9); + the_concentric_cylinder3_material.set_shininess(300); + the_world.add_object(the_concentric_cylinder3); + + // Concentric Cylinder 4 + the_concentric_cylinder4 = new Cylinder(); + the_concentric_cylinder4->set_minimum(0); + the_concentric_cylinder4->set_maximum(0.5); + the_concentric_cylinder4->set_transform(Matrix::translation(1, 0, 0) * + Matrix::scaling(0.2, 1, 0.2)); + Material &the_concentric_cylinder4_material = the_concentric_cylinder4->material(); + the_concentric_cylinder4_material.set_color(Color(1, 0.7, 0.6)); + the_concentric_cylinder4_material.set_ambient(0.1); + the_concentric_cylinder4_material.set_diffuse(0.8); + the_concentric_cylinder4_material.set_specular(0.9); + the_concentric_cylinder4_material.set_shininess(300); + the_world.add_object(the_concentric_cylinder4); + + // Decorative Cylinder 1 + the_decorative_cylinder1 = new Cylinder(); + the_decorative_cylinder1->set_minimum(0); + the_decorative_cylinder1->set_maximum(0.3); + the_decorative_cylinder1->set_transform(Matrix::translation(0, 0, -0.75) * + Matrix::scaling(0.05, 1, 0.05)); + Material &the_decorative_cylinder1_material = the_decorative_cylinder1->material(); + the_decorative_cylinder1_material.set_color(Color::Red()); + the_decorative_cylinder1_material.set_ambient(0.1); + the_decorative_cylinder1_material.set_diffuse(0.9); + the_decorative_cylinder1_material.set_specular(0.9); + the_decorative_cylinder1_material.set_shininess(300); + the_world.add_object(the_decorative_cylinder1); + + // Decorative Cylinder 2 + the_decorative_cylinder2 = new Cylinder(); + the_decorative_cylinder2->set_minimum(0); + the_decorative_cylinder2->set_maximum(0.3); + the_decorative_cylinder2->set_transform(Matrix::translation(0, 0, -2.25) * Matrix::rotation_y(-0.15) * + Matrix::translation(0, 0, 1.5) * Matrix::scaling(0.05, 1, 0.05)); + Material &the_decorative_cylinder2_material = the_decorative_cylinder2->material(); + the_decorative_cylinder2_material.set_color(Color::Yellow()); + the_decorative_cylinder2_material.set_ambient(0.1); + the_decorative_cylinder2_material.set_diffuse(0.9); + the_decorative_cylinder2_material.set_specular(0.9); + the_decorative_cylinder2_material.set_shininess(300); + the_world.add_object(the_decorative_cylinder2); + + // Decorative Cylinder 3 + the_decorative_cylinder3 = new Cylinder(); + the_decorative_cylinder3->set_minimum(0); + the_decorative_cylinder3->set_maximum(0.3); + the_decorative_cylinder3->set_transform(Matrix::translation(0, 0, -2.25) * Matrix::rotation_y(-0.3) * + Matrix::translation(0, 0, 1.5) * Matrix::scaling(0.05, 1, 0.05)); + Material &the_decorative_cylinder3_material = the_decorative_cylinder3->material(); + the_decorative_cylinder3_material.set_color(Color::Green()); + the_decorative_cylinder3_material.set_ambient(0.1); + the_decorative_cylinder3_material.set_diffuse(0.9); + the_decorative_cylinder3_material.set_specular(0.9); + the_decorative_cylinder3_material.set_shininess(300); + the_world.add_object(the_decorative_cylinder3); + + // Decorative Cylinder 4 + the_decorative_cylinder4 = new Cylinder(); + the_decorative_cylinder4->set_minimum(0); + the_decorative_cylinder4->set_maximum(0.3); + the_decorative_cylinder4->set_transform(Matrix::translation(0, 0, -2.25) * Matrix::rotation_y(-0.45) * + Matrix::translation(0, 0, 1.5) * Matrix::scaling(0.05, 1, 0.05)); + Material &the_decorative_cylinder4_material = the_decorative_cylinder4->material(); + the_decorative_cylinder4_material.set_color(Color::Cyan()); + the_decorative_cylinder4_material.set_ambient(0.1); + the_decorative_cylinder4_material.set_diffuse(0.9); + the_decorative_cylinder4_material.set_specular(0.9); + the_decorative_cylinder4_material.set_shininess(300); + the_world.add_object(the_decorative_cylinder4); + + // Glass Cylinder + the_glass_cylinder = new Cylinder(); + the_glass_cylinder->set_minimum(0.0001); + the_glass_cylinder->set_maximum(0.5); + the_glass_cylinder->set_transform(Matrix::translation(0, 0, -1.5) * + Matrix::scaling(0.33, 1, 0.33)); + Material &the_glass_cylinder_material = the_glass_cylinder->material(); + the_glass_cylinder_material.set_color(Color(0.25, 0, 0)); + the_glass_cylinder_material.set_ambient(0.1); + the_glass_cylinder_material.set_specular(0.9); + the_glass_cylinder_material.set_shininess(300); + the_glass_cylinder_material.set_reflective(0.9); + the_glass_cylinder_material.set_transparency(0.9); + the_glass_cylinder_material.set_refractive_index(1.5); + the_world.add_object(the_glass_cylinder); + // The Light source is white, shining from above and to the left the_world.set_light(PointLight(Tuple::Point(1, 6.9, -4.9), Color(1, 1, 1))); diff --git a/raytracing/src/core/color.cpp b/raytracing/src/core/color.cpp index 7e0908b..697ea6d 100644 --- a/raytracing/src/core/color.cpp +++ b/raytracing/src/core/color.cpp @@ -258,7 +258,28 @@ Color Color::Green(void) /* ------------------------------------------------------------------------- */ -Color blue(void) +Color Color::Blue(void) { return Color(0, 0, 1); } + +/* ------------------------------------------------------------------------- */ + +Color Color::Yellow(void) +{ + return Color(1, 1, 0); +} + +/* ------------------------------------------------------------------------- */ + +Color Color::Magenta(void) +{ + return Color(1, 0, 1); +} + +/* ------------------------------------------------------------------------- */ + +Color Color::Cyan(void) +{ + return Color(0, 1, 1); +} diff --git a/raytracing/src/core/color.h b/raytracing/src/core/color.h index 2479b29..bb6bed4 100644 --- a/raytracing/src/core/color.h +++ b/raytracing/src/core/color.h @@ -68,9 +68,13 @@ namespace Raytracer static Color Red(void); static Color Green(void); static Color Blue(void); + static Color Yellow(void); + static Color Magenta(void); + static Color Cyan(void); private: - uint8_t color_to_integer(double a_color) const; + uint8_t + color_to_integer(double a_color) const; private: double m_red;