diff --git a/.vscode/settings.json b/.vscode/settings.json index 905b136..14b2b14 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -105,7 +105,8 @@ "/home/jbnadal/sources/jb/raytracer_challenge/build/apps/CMakeFiles/chapter_07.dir", "/home/jbnadal/sources/jb/raytracer_challenge/build/apps/CMakeFiles/chapter_09.dir", "/home/jbnadal/sources/jb/raytracer_challenge/build/apps/CMakeFiles/chapter_10.dir", - "/home/jbnadal/sources/jb/raytracer_challenge/build/apps/CMakeFiles/chapter_11.dir", + "/home/jbnadal/sources/jb/raytracer_challenge/build/apps/CMakeFiles/chapter_11_p1.dir", + "/home/jbnadal/sources/jb/raytracer_challenge/build/apps/CMakeFiles/chapter_11_p2.dir", "/home/jbnadal/sources/jb/raytracer_challenge/build/tests/CMakeFiles/raytracing_test.dir" ] } \ No newline at end of file diff --git a/README.md b/README.md index 7ca9601..597ef3f 100644 --- a/README.md +++ b/README.md @@ -29,4 +29,4 @@ The Web Site of the book: http://raytracerchallenge.com/ | Chapiter 10 | Chapiter 11 partie 01 | Chapiter 11 partie 02 | |:------------------------: | :---------------------------: | :----------------------------: | -|![10](data/chapter_10.png) | ![11](data/chapter_11_p1.png) | | +|![10](data/chapter_10.png) | ![11](data/chapter_11_p1.png) | ![11](data/chapter_11_p2.png) | diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index 41e7620..b81f54e 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -26,4 +26,4 @@ add_executable(chapter_11_p1 chapter_11_p1.cpp) target_link_libraries(chapter_11_p1 PRIVATE raytracing gcov OpenMP::OpenMP_CXX) add_executable(chapter_11_p2 chapter_11_p2.cpp) -target_link_libraries(chapter_11_p2 PRIVATE raytracing gcov OpenMP::OpenMP_CXX) +target_link_libraries(chapter_11_p2 PRIVATE raytracing OpenMP::OpenMP_CXX) diff --git a/apps/chapter_11_p2.cpp b/apps/chapter_11_p2.cpp index 451d7bf..722d79e 100644 --- a/apps/chapter_11_p2.cpp +++ b/apps/chapter_11_p2.cpp @@ -43,70 +43,158 @@ int main(void) World the_world; Camera the_camera; Canvas the_canvas; - Plane *the_floor, *the_left_wall, *the_right_wall; - Sphere *the_middle, *the_right, *the_left; + Plane *the_floor, *the_ceiling, *the_left_wall, *the_right_wall, *the_front_wall, *the_back_wall; + Sphere *the_back_sphere1, *the_back_sphere2, *the_back_sphere3, *the_back_sphere4; + Sphere *the_red_sphere, *the_green_sphere, *the_blue_sphere; chrono::time_point the_start, the_end; printf("Chapter 11 part2 example.\n"); - // Floor is an extremely flattened sphere with a matte texture. + // Wall Material + Material the_wall_material; + the_wall_material.set_pattern(new StripePattern(Color(0.45, 0.45, 0.45), Color(0.35, 0.35, 0.35))); + the_wall_material.pattern()->set_transform(Matrix::rotation_y(std::numbers::pi / 2) * + Matrix::scaling(0.25, 0.25, 0.25)); + the_wall_material.set_ambient(0.0); + the_wall_material.set_diffuse(0.4); + the_wall_material.set_specular(0.0); + the_wall_material.set_reflective(0.3); + + // Floor the_floor = new Plane(); Material &the_floor_material = the_floor->material(); + the_floor_material.set_pattern(new CheckersPattern(Color(0.35, 0.35, 0.35), Color(0.65, 0.65, 0.65))); the_floor_material.set_specular(0.0); the_floor_material.set_reflective(0.4); - the_floor_material.set_pattern(new CheckersPattern(Color(0.35, 0.35, 0.35), Color(0.65, 0.65, 0.65))); + the_floor->set_transform(Matrix::rotation_y(-std::numbers::pi / 10)); the_world.add_object(the_floor); + // Ceiling + the_ceiling = new Plane(); + Material &the_ceiling_material = the_ceiling->material(); + the_ceiling_material.set_color(Color(0.8, 0.8, 0.8)); + the_ceiling_material.set_ambient(0.3); + the_ceiling_material.set_specular(0.0); + the_ceiling->set_transform(Matrix::translation(0, 5, 0)); + the_world.add_object(the_ceiling); + // Left Wall the_left_wall = new Plane(); - the_left_wall->set_transform(Matrix::translation(0, 0, 10) * - Matrix::rotation_y(-std::numbers::pi / 4) * - Matrix::rotation_x(std::numbers::pi / 2)); - Material &the_left_wall_material = the_left_wall->material(); - the_left_wall_material.set_specular(0); - the_left_wall_material.set_pattern(new StripePattern(Color(0.52, 0.52, 0.52), Color::Black())); - the_left_wall_material.pattern()->set_transform(Matrix::rotation_y(std::numbers::pi / 2)); + the_left_wall->set_transform(Matrix::translation(-5, 0, 0) * + Matrix::rotation_z(-std::numbers::pi / 2) * + Matrix::rotation_y(std::numbers::pi / 2)); + the_left_wall->set_material(the_wall_material); the_world.add_object(the_left_wall); // Right Wall the_right_wall = new Plane(); - the_right_wall->set_transform(Matrix::translation(0, 5, 10) * - Matrix::rotation_y(std::numbers::pi / 4) * - Matrix::rotation_x(std::numbers::pi / 2)); - Material &the_right_wall_material = the_right_wall->material(); - the_right_wall_material.set_specular(0); - the_right_wall_material.set_pattern(new StripePattern(Color(0.52, 0.52, 0.52), Color::Black())); - the_right_wall_material.pattern()->set_transform(Matrix::rotation_y(std::numbers::pi / 2)); + the_right_wall->set_transform(Matrix::translation(5, 0, 0) * + Matrix::rotation_z(-std::numbers::pi / 2) * + Matrix::rotation_y(std::numbers::pi / 2)); + the_right_wall->set_material(the_wall_material); the_world.add_object(the_right_wall); - // The large sphere in the middle is a unit sphere, translated upward slightly and colored green. - the_middle = new Sphere(); - the_middle->set_transform(Matrix::translation(-0.25, 1, 1.5) * - Matrix::rotation_y(-std::numbers::pi / 1.5) * - Matrix::rotation_z(-std::numbers::pi / 6)); + // Front Wall + the_front_wall = new Plane(); + the_front_wall->set_transform(Matrix::translation(0, 0, 5) * + Matrix::rotation_x(-std::numbers::pi / 2)); + the_front_wall->set_material(the_wall_material); + the_world.add_object(the_front_wall); - Material &the_middle_material = the_middle->material(); - the_middle_material.set_color(Color(0, 0.2, 0.)); - the_middle_material.set_ambient(0.0); - the_middle_material.set_diffuse(0.4); - the_middle_material.set_specular(0.9); - the_middle_material.set_shininess(300); - the_middle_material.set_transparency(0.9); - the_middle_material.set_reflective(0.9); - the_middle_material.set_refractive_index(1.5); - the_world.add_object(the_middle); + // Back Wall + the_back_wall = new Plane(); + the_back_wall->set_transform(Matrix::translation(0, 0, -5) * + Matrix::rotation_x(-std::numbers::pi / 2)); + the_back_wall->set_material(the_wall_material); + the_world.add_object(the_back_wall); + + // Back Sphere 1 + the_back_sphere1 = new Sphere(); + the_back_sphere1->set_transform(Matrix::translation(4.6, 0.4, 1.0) * + Matrix::scaling(0.4, 0.4, 0.4)); + Material &the_back_sphere1_material = the_back_sphere1->material(); + the_back_sphere1_material.set_color(Color(0.8, 0.5, 0.3)); + the_back_sphere1_material.set_shininess(50.0); + the_world.add_object(the_back_sphere1); + + // Back Sphere 2 + the_back_sphere2 = new Sphere(); + the_back_sphere2->set_transform(Matrix::translation(4.7, 0.3, 0.4) * + Matrix::scaling(0.3, 0.3, 0.3)); + Material &the_back_sphere2_material = the_back_sphere2->material(); + the_back_sphere2_material.set_color(Color(0.9, 0.4, 0.5)); + the_back_sphere2_material.set_shininess(50.0); + the_world.add_object(the_back_sphere2); + + // Back Sphere 3 + the_back_sphere3 = new Sphere(); + the_back_sphere3->set_transform(Matrix::translation(-1, 0.5, 4.5) * + Matrix::scaling(0.5, 0.5, 0.5)); + Material &the_back_sphere3_material = the_back_sphere3->material(); + the_back_sphere3_material.set_color(Color(0.4, 0.9, 0.6)); + the_back_sphere3_material.set_shininess(50.0); + the_world.add_object(the_back_sphere3); + + // Back Sphere 4 + the_back_sphere4 = new Sphere(); + the_back_sphere4->set_transform(Matrix::translation(-1.7, 0.3, 4.7) * + Matrix::scaling(0.3, 0.3, 0.3)); + Material &the_back_sphere4_material = the_back_sphere4->material(); + the_back_sphere4_material.set_color(Color(0.4, 0.6, 0.9)); + the_back_sphere4_material.set_shininess(50.0); + the_world.add_object(the_back_sphere4); + + // Red Sphere + the_red_sphere = new Sphere(); + the_red_sphere->set_transform(Matrix::translation(-0.6, 1, 0.6)); + Material &the_red_sphere_material = the_red_sphere->material(); + the_red_sphere_material.set_color(Color(1, 0.3, 0.2)); + the_red_sphere_material.set_specular(0.4); + the_red_sphere_material.set_shininess(5.0); + the_world.add_object(the_red_sphere); + + // Green Sphere + the_green_sphere = new Sphere(); + the_green_sphere->set_transform(Matrix::translation(-0.7, 0.5, -0.8) * + Matrix::scaling(0.5, 0.5, 0.5)); + Material &the_green_sphere_material = the_green_sphere->material(); + the_green_sphere_material.set_color(Color(0, 0.2, 0)); + the_green_sphere_material.set_ambient(0.0); + the_green_sphere_material.set_diffuse(0.4); + the_green_sphere_material.set_specular(0.9); + the_green_sphere_material.set_shininess(300.0); + the_green_sphere_material.set_reflective(0.9); + the_green_sphere_material.set_transparency(0.9); + the_green_sphere_material.set_refractive_index(1.5); + the_world.add_object(the_green_sphere); + + // Blue Sphere + the_blue_sphere = new Sphere(); + the_blue_sphere->set_transform(Matrix::translation(0.6, 0.7, -0.6) * + Matrix::scaling(0.7, 0.7, 0.7)); + Material &the_blue_sphere_material = the_blue_sphere->material(); + the_blue_sphere_material.set_color(Color(0, 0., 0.2)); + the_blue_sphere_material.set_ambient(0.0); + the_blue_sphere_material.set_diffuse(0.4); + the_blue_sphere_material.set_specular(0.9); + the_blue_sphere_material.set_shininess(300.0); + the_blue_sphere_material.set_reflective(0.9); + the_blue_sphere_material.set_transparency(0.9); + the_blue_sphere_material.set_refractive_index(1.5); + the_world.add_object(the_blue_sphere); // The Light source is white, shining from above and to the left - the_world.set_light(PointLight(Tuple::Point(-10, 10, -10), Color(1, 1, 1))); + the_world.set_light(PointLight(Tuple::Point(-4.9, 4.9, -1), Color(1, 1, 1))); // Configure the camera. - the_camera = Camera(100, 50, std::numbers::pi / 3); - // the_camera = Camera(320, 200, std::numbers::pi / 3); - // the_camera = Camera(640, 480, std::numbers::pi / 3); + // the_camera = Camera(100, 50, 1.152); + // the_camera = Camera(320, 200, 1.152); + the_camera = Camera(640, 480, 1.152); the_camera.set_transform( - Matrix::view_transform(Tuple::Point(0, 1.5, -5), Tuple::Point(0, 1, 0), Tuple::Vector(0, 1, 0))); + Matrix::view_transform(Tuple::Point(-2.6, 1.5, -3.9), Tuple::Point(-0.6, 1, -0.8), Tuple::Vector(0, 1, 0))); the_start = chrono::high_resolution_clock::now(); + the_camera.show_progress_bar(); the_canvas = the_camera.render(the_world); the_end = chrono::high_resolution_clock::now(); diff --git a/data/chapter_11_p2.png b/data/chapter_11_p2.png new file mode 100644 index 0000000..17a318e Binary files /dev/null and b/data/chapter_11_p2.png differ diff --git a/raytracing/CMakeLists.txt b/raytracing/CMakeLists.txt index b332817..641936f 100644 --- a/raytracing/CMakeLists.txt +++ b/raytracing/CMakeLists.txt @@ -5,7 +5,7 @@ project(raytracing) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) -add_definitions(--coverage) +# add_definitions(--coverage) add_definitions(-fopenmp) include_directories (src) diff --git a/raytracing/include/external/ProgressBar.hpp b/raytracing/include/external/ProgressBar.hpp new file mode 100644 index 0000000..115e59e --- /dev/null +++ b/raytracing/include/external/ProgressBar.hpp @@ -0,0 +1,327 @@ +#pragma once +#ifndef PROGRESSBAR_HPP__ +#define PROGRESSBAR_HPP__ +/***************************************************************************** +ProgressBar.hpp: CUI Progress bar + +****************************************************************************** +ProgressBar.hpp is under MIT license +---------------------------------- +Copyright (c) 2023 Kitanokitsune + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include /* causes errors to BCC 5.5 */ +#include +#include +#include + + +#ifdef _WIN32 +# include +# ifndef COMMON_LVB_GRID_HORIZONTAL +# define COMMON_LVB_GRID_HORIZONTAL 0x0400 +# endif +# ifndef COMMON_LVB_UNDERSCORE +# define COMMON_LVB_UNDERSCORE 0x8000 +# endif +#else +# include +# include +#endif + +#define MAX_BAR_LENGTH 256 +#define DEFAULT_CONSOLE_WIDTH 80 + +#define pbar_max(a,b) ((a)>(b) ? (a) : (b)) + +#define pbar_round(x) static_cast(x + 0.5) /* NOTE: x >= 0.0 */ +#define pbar_floor(x) static_cast(x) /* NOTE: x >= 0.0 */ + +#define MAXDIGITS(x) ((int)((sizeof(x)*CHAR_BIT*1233UL)>>12)+1) /* NOTE: 680 >= sizeof(x)*CHAR_BIT */ +#define MAXDIGITS_ULONG MAXDIGITS(unsigned long) + + +class ProgressBar { + private: + double percent; + double step; + double tick; + double checkpoint; + unsigned long total; + unsigned long state; + int consolewidth; + char charBarOn; + char charBarOff; + char charBarArrow; + char charBracketLeft; + char charBracketRight; + std::string bartitle; + std::string strtotal; + bool unknown_console; + bool num_style_is_percent; +#ifdef _WIN32 + CONSOLE_CURSOR_INFO cursor_info; + HANDLE hStdoutHandle; + DWORD consoleattribute; +#endif + + + private: + +#ifdef _WIN32 + inline void invert_attribute(void) { + SetConsoleTextAttribute(hStdoutHandle, + // COMMON_LVB_UNDERSCORE | + COMMON_LVB_GRID_HORIZONTAL | + ((consoleattribute>>4) & 0x0fU) | + ((consoleattribute<<4) & 0xf0U)); + }; + + inline void restore_attribute(void) { + SetConsoleTextAttribute(hStdoutHandle, consoleattribute); + }; + + int get_consolewidth(void) { + BOOL bRet; + CONSOLE_SCREEN_BUFFER_INFO info; + bRet = GetConsoleScreenBufferInfo( + hStdoutHandle, + &info); + if (bRet) { + return (1 + info.srWindow.Right); + } + return DEFAULT_CONSOLE_WIDTH; + }; +#else + int get_consolewidth(void) { + struct winsize ws; + if( ioctl( STDERR_FILENO, TIOCGWINSZ, &ws ) != -1 ) { + if( 0 < ws.ws_col && ws.ws_col == (size_t)ws.ws_col ) { + return ws.ws_col; + } + } + return DEFAULT_CONSOLE_WIDTH; + }; +#endif + + void redraw(void) { + int bar_len; + double f; + char *ptr; + int i; + int count; + char buf[MAX_BAR_LENGTH + 1]; /* bar length + NUL('\0') */ + char str[1 + MAXDIGITS_ULONG + 1]; /* sign + digits + NUL */ + char fmt[1 + MAXDIGITS_ULONG + 1]; + + /* calculate bar length */ + bar_len = consolewidth - bartitle.size(); + if (num_style_is_percent) { + bar_len -= 8; + } else { + bar_len -= (5 + 2*strtotal.size()); + } + + if (bar_len < 1) { + bar_len = 1; + } else if (bar_len > MAX_BAR_LENGTH) { + bar_len = MAX_BAR_LENGTH; + } + + /* print progress bar */ + f = percent * 0.01 * static_cast(bar_len); + count = pbar_round(f); + fprintf(stderr, "\r%s%c", bartitle.c_str(), charBracketLeft); + + ptr = buf; + if (unknown_console) { + for (i=0; i(strtotal.size())); + sprintf(str, fmt, state); + fprintf(stderr, "%s%c %s/%s", buf, charBracketRight, str, strtotal.c_str()); + } + }; + + void init_(void) { +#ifdef _WIN32 + CONSOLE_SCREEN_BUFFER_INFO info; + hStdoutHandle = GetStdHandle(STD_ERROR_HANDLE); + if (GetConsoleScreenBufferInfo(hStdoutHandle, &info)) { + consoleattribute = info.wAttributes; + GetConsoleCursorInfo(hStdoutHandle, &cursor_info); + unknown_console = false; + } else { + unknown_console = true; + } +#else + struct winsize ws; + unknown_console = true; + if( ioctl( STDERR_FILENO, TIOCGWINSZ, &ws ) != -1 ) { + if( 0 < ws.ws_col && ws.ws_col == (size_t)ws.ws_col ) { + unknown_console = false; + } + } +#endif + }; + + + public: + ProgressBar(unsigned long t=1) { + init_(); + set_total(t); + set_barstyle(); + set_width(); + set_title(""); + set_bracketstyle(); + use_percentstyle(); + }; + + ProgressBar(unsigned long t, std::string str, char fgch='\0', char arrch='.', char bgch='.', int wid=-1) { + init_(); + set_total(t); + set_barstyle(fgch, arrch, bgch); + set_width(wid); + set_title(str); + set_bracketstyle(); + use_percentstyle(); + }; + + void set_barstyle(char fg='\0', char arrw='.', char bg='.') { + charBarOn = fg; + charBarArrow = arrw; + charBarOff = bg; + }; + + void set_total(unsigned long t) { + char str[1 + MAXDIGITS_ULONG + 1]; + + total = pbar_max(t, 1); + sprintf(str, "%lu", total); + strtotal = str; + step = 100.0/static_cast(total); + tick = pbar_max(1.0, step); + checkpoint = tick; + percent = 0.0; + }; + + void set_width(int width = -1) { + if (width > 0) { + consolewidth = width; + } else { + consolewidth = get_consolewidth(); + } + }; + + void set_title(std::string str) { + bartitle = str; + }; + + void set_bracketstyle(char lbra='|', char rbra='|') { + charBracketLeft = lbra; + charBracketRight = rbra; + }; + + void use_percentstyle(void) { + num_style_is_percent = true; + }; + + void use_ratiostyle(void) { + num_style_is_percent = false; + }; + + void reset(void) { + percent = 0.0; + state = 0; + checkpoint = tick; + }; + + void start(void) { + reset(); + set_cursor_visible(false); + redraw(); + }; + + void set_cursor_visible(bool onoff) { +#ifdef _WIN32 + cursor_info.bVisible = onoff; + SetConsoleCursorInfo(hStdoutHandle, &cursor_info); +#else + if (onoff) { + fprintf(stderr, "\e[?25h"); + } else { + fprintf(stderr, "\e[?25l"); + } +#endif + }; + + void update(void) { + if (state >= total) return; + + ++state; + percent += step; + if (state >= total) { + percent = 100.03125; + redraw(); + fprintf(stderr, "\n"); + set_cursor_visible(true); + fflush(stderr); + } else if (percent >= checkpoint) { + redraw(); + checkpoint = percent + tick; + } + }; + + inline void operator ++() { + update(); + }; + + inline void operator ++(int n) { + update(); + }; + +}; + +#endif /* PROGRESSBAR_HPP__ */ \ No newline at end of file diff --git a/tests/catch.hpp b/raytracing/include/external/catch.hpp similarity index 100% rename from tests/catch.hpp rename to raytracing/include/external/catch.hpp diff --git a/raytracing/src/renderer/camera.cpp b/raytracing/src/renderer/camera.cpp index 7015db4..074dc85 100644 --- a/raytracing/src/renderer/camera.cpp +++ b/raytracing/src/renderer/camera.cpp @@ -31,6 +31,8 @@ #include #include +#include + #include "camera.h" using namespace Raytracer; @@ -43,7 +45,8 @@ Camera::Camera(void) : m_field_of_view(0), m_half_width(0), m_half_height(0), - m_pixel_size(0) + m_pixel_size(0), + m_show_progress_bar(false) { } @@ -56,7 +59,8 @@ Camera::Camera(uint16_t a_h_size, uint16_t a_v_size, double a_field_of_view) : m_transform(Matrix::identity()), m_half_width(0), m_half_height(0), - m_pixel_size(0) + m_pixel_size(0), + m_show_progress_bar(false) { double the_half_view = tan(m_field_of_view / 2); @@ -87,6 +91,7 @@ Camera::Camera(const Camera &an_other) m_half_width = an_other.m_half_width; m_half_height = an_other.m_half_height; m_pixel_size = an_other.m_pixel_size; + m_show_progress_bar = an_other.m_show_progress_bar; } /* ------------------------------------------------------------------------- */ @@ -105,6 +110,7 @@ const Camera &Camera::operator=(const Camera &an_other) m_half_width = an_other.m_half_width; m_half_height = an_other.m_half_height; m_pixel_size = an_other.m_pixel_size; + m_show_progress_bar = an_other.m_show_progress_bar; return *this; } @@ -183,19 +189,42 @@ Ray Camera::ray_for_pixel(double an_x, double an_y) const Canvas Camera::render(const World &a_world) { + int8_t the_percent = -1; + uint32_t the_cpt = 0; + uint32_t the_loop_size = m_h_size * m_v_size; Canvas the_image(m_h_size, m_v_size); + ProgressBar the_progress_bar(100, "[=>]"); -#pragma omp parallel for num_threads(8) shared(the_image) for (int y = 0; y < m_v_size - 1; y++) { +#pragma omp parallel for shared(the_image) for (int x = 0; x < m_h_size - 1; x++) { // printf("ray_for_pixel (process: %d)\n", omp_get_thread_num()); Ray the_ray = ray_for_pixel(x, y); Color the_color = a_world.color_at(the_ray); the_image.write_pixel(x, y, the_color); + if (m_show_progress_bar == true) + { + double the_temp_perc; + the_cpt++; + the_temp_perc = the_cpt * 100 / the_loop_size; + if (the_percent != (int8_t)the_temp_perc) + { + the_percent = (int8_t)the_temp_perc; + // printf("percent: %d\n", the_percent); + the_progress_bar.update(); + } + } } } return the_image; } + +/* ------------------------------------------------------------------------- */ + +void Camera::show_progress_bar(void) +{ + m_show_progress_bar = true; +} diff --git a/raytracing/src/renderer/camera.h b/raytracing/src/renderer/camera.h index 5d04bb7..2e12a46 100644 --- a/raytracing/src/renderer/camera.h +++ b/raytracing/src/renderer/camera.h @@ -61,6 +61,8 @@ namespace Raytracer Canvas render(const World &a_world); + void show_progress_bar(void); + private: uint16_t m_h_size; @@ -70,6 +72,7 @@ namespace Raytracer double m_half_width; double m_half_height; double m_pixel_size; + bool m_show_progress_bar; }; }; // namespace Raytracer diff --git a/tests/01_tuples.cpp b/tests/01_tuples.cpp index 435f6c9..5f116b9 100644 --- a/tests/01_tuples.cpp +++ b/tests/01_tuples.cpp @@ -27,7 +27,7 @@ #include -#include +#include #include "core/tuple.h" diff --git a/tests/02_1_colors.cpp b/tests/02_1_colors.cpp index 25a2242..15cae5b 100644 --- a/tests/02_1_colors.cpp +++ b/tests/02_1_colors.cpp @@ -25,7 +25,7 @@ /*---------------------------------------------------------------------------*/ -#include +#include #include "core/color.h" diff --git a/tests/02_2_canvas.cpp b/tests/02_2_canvas.cpp index 1ab246a..5eae9e0 100644 --- a/tests/02_2_canvas.cpp +++ b/tests/02_2_canvas.cpp @@ -25,7 +25,7 @@ /*---------------------------------------------------------------------------*/ -#include +#include #include "renderer/canvas.h" diff --git a/tests/03_matrix.cpp b/tests/03_matrix.cpp index 528e31b..1107d37 100644 --- a/tests/03_matrix.cpp +++ b/tests/03_matrix.cpp @@ -25,7 +25,7 @@ /*---------------------------------------------------------------------------*/ -#include +#include #include "raytracing.h" diff --git a/tests/04_transformations.cpp b/tests/04_transformations.cpp index 5454b7c..14c9708 100644 --- a/tests/04_transformations.cpp +++ b/tests/04_transformations.cpp @@ -25,7 +25,7 @@ /*---------------------------------------------------------------------------*/ -#include +#include #include "raytracing.h" diff --git a/tests/05_rays.cpp b/tests/05_rays.cpp index 4f041ab..a76fd4c 100644 --- a/tests/05_rays.cpp +++ b/tests/05_rays.cpp @@ -25,7 +25,7 @@ /*---------------------------------------------------------------------------*/ -#include +#include #include "raytracing.h" diff --git a/tests/06_light_shading.cpp b/tests/06_light_shading.cpp index cecb865..d959a74 100644 --- a/tests/06_light_shading.cpp +++ b/tests/06_light_shading.cpp @@ -25,7 +25,7 @@ /*---------------------------------------------------------------------------*/ -#include +#include #include "raytracing.h" diff --git a/tests/07_making_scene.cpp b/tests/07_making_scene.cpp index 155883a..0d710db 100644 --- a/tests/07_making_scene.cpp +++ b/tests/07_making_scene.cpp @@ -25,7 +25,7 @@ /*---------------------------------------------------------------------------*/ -#include +#include #include "raytracing.h" diff --git a/tests/08_shadows.cpp b/tests/08_shadows.cpp index 92fe27b..1f3cd28 100644 --- a/tests/08_shadows.cpp +++ b/tests/08_shadows.cpp @@ -25,7 +25,7 @@ /*---------------------------------------------------------------------------*/ -#include +#include #include "raytracing.h" diff --git a/tests/09_planes.cpp b/tests/09_planes.cpp index 544c079..f9ab71c 100644 --- a/tests/09_planes.cpp +++ b/tests/09_planes.cpp @@ -25,7 +25,7 @@ /*---------------------------------------------------------------------------*/ -#include +#include #include "raytracing.h" diff --git a/tests/10_patterns.cpp b/tests/10_patterns.cpp index a229c0b..ec5eb6f 100644 --- a/tests/10_patterns.cpp +++ b/tests/10_patterns.cpp @@ -25,7 +25,7 @@ /*---------------------------------------------------------------------------*/ -#include +#include #include "raytracing.h" diff --git a/tests/11_reflection_refraction.cpp b/tests/11_reflection_refraction.cpp index 8c01da5..fc1494e 100644 --- a/tests/11_reflection_refraction.cpp +++ b/tests/11_reflection_refraction.cpp @@ -25,7 +25,7 @@ /*---------------------------------------------------------------------------*/ -#include +#include #include "raytracing.h" diff --git a/tests/main_test.cpp b/tests/main_test.cpp index 19fa948..302fcff 100644 --- a/tests/main_test.cpp +++ b/tests/main_test.cpp @@ -26,4 +26,4 @@ #define CATCH_INTERNAL_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS #define CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS #define CATCH_CONFIG_MAIN -#include "catch.hpp" +#include "external/catch.hpp"