diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2a16547..7917c61 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -21,4 +21,9 @@ gtest_discover_tests(testMyRays add_executable(ch5_test) target_include_directories(ch5_test PUBLIC ../source/include) target_sources(ch5_test PRIVATE ch5_test.cpp) -target_link_libraries(ch5_test rayonnement) \ No newline at end of file +target_link_libraries(ch5_test rayonnement) + +add_executable(ch6_test) +target_include_directories(ch6_test PUBLIC ../source/include) +target_sources(ch6_test PRIVATE ch6_test.cpp) +target_link_libraries(ch6_test rayonnement) \ No newline at end of file diff --git a/tests/ch6_test.cpp b/tests/ch6_test.cpp new file mode 100644 index 0000000..10c6aca --- /dev/null +++ b/tests/ch6_test.cpp @@ -0,0 +1,57 @@ +/* + * DoRayMe - a quick and dirty Raytracer + * Render test for chapter 5 "Put it together". + * + * Created by Manoƫl Trapier + * Copyright (c) 2020 986-Studio. + * + */ +#include +#include +#include +#include +#include + +int main() +{ + int x, y; + Canvas c = Canvas(100, 100); + + Sphere s = Sphere(); + + s.material.colour = Colour(1, 0.2, 1); + + + Light light = Light(POINT_LIGHT, Point(-10, 10, -10), Colour(1, 1, 1)); + + Point cameraOrigin = Point(0, 0, -5); + double wallDistance = 10; + double wallSize = 7; + double pixelSize = wallSize / c.width; + for(y = 0; y < c.height; y++) + { + double worldY = (wallSize / 2) - pixelSize * y; + for(x = 0; x < c.width; x++) + { + double worldX = -(wallSize / 2) + pixelSize * x; + Point position = Point(worldX, worldY, wallDistance); + Ray r = Ray(cameraOrigin, (position - cameraOrigin).normalise()); + Intersect xs = s.intersect(r); + + Intersection hit = xs.hit(); + + if (!hit.nothing()) + { + Tuple hitPoint = r.position(hit.t); + Tuple hitNormalVector = hit.object->normalAt(hitPoint); + Tuple eye = -r.direction; + Colour pixelColour = hit.object->material.lighting(light, hitPoint, eye, hitNormalVector); + + c.put_pixel(x, y, pixelColour); + } + + } + } + c.SaveAsPNG("ch6_test.png"); + return 0; +} \ No newline at end of file