diff --git a/README.md b/README.md index d076a69..1c19e59 100644 --- a/README.md +++ b/README.md @@ -90,4 +90,7 @@ Planar mapping: ![Planar mapping](output/uvmap_checkeredplane.png) Cylindrical mapping: -![Cylindrical mapping](output/uvmap_checkeredcylinder.png) \ No newline at end of file +![Cylindrical mapping](output/uvmap_checkeredcylinder.png) + +Aligncheck plane: +![Aligncheck plane](output/uvmap_aligncheckplane.png) \ No newline at end of file diff --git a/output/uvmap_aligncheckplane.png b/output/uvmap_aligncheckplane.png new file mode 100644 index 0000000..c405781 Binary files /dev/null and b/output/uvmap_aligncheckplane.png differ diff --git a/source/uvpattern/uv_aligncheck.h b/source/uvpattern/uv_aligncheck.h new file mode 100644 index 0000000..b74c44d --- /dev/null +++ b/source/uvpattern/uv_aligncheck.h @@ -0,0 +1,39 @@ +/* + * DoRayMe - a quick and dirty Raytracer + * UV Align Check test pattern header + * + * Created by Manoël Trapier + * Copyright (c) 2020 986-Studio. + * + */ +#ifndef DORAYME_UV_ALIGNCHECK_H +#define DORAYME_UV_ALIGNCHECK_H + +class UVAlignCheck : public UVPattern +{ +public: + Colour ul, ur, bl, br; + + UVAlignCheck(Colour main, Colour ul, Colour ur, Colour bl, Colour br) : UVPattern(1, 1, main, main), + ul(ul), ur(ur), bl(bl), br(br) {}; + + Colour uvPatternAt(double u, double v) { + /* Remember that v=0 is at the bottom, v=1 at the top */ + if (v > 0.8) + { + if (u < 0.2) { return this->ul; } + if (u > 0.8) { return this->ur; } + } + else if (v < 0.2) + { + if (u < 0.2) { return this->bl; } + if (u > 0.8) { return this->br; } + } + + /* main is stored in A or B */ + return this->a; + }; +}; + + +#endif /* DORAYME_UV_ALIGNCHECK_H */ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2e6222f..9345318 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -83,6 +83,9 @@ target_sources(uvmap_checkeredplane PRIVATE uvmap_checkeredplane.cpp) add_executable(uvmap_checkeredcylinder) target_sources(uvmap_checkeredcylinder PRIVATE uvmap_checkeredcylinder.cpp) +add_executable(uvmap_aligncheckplane) +target_sources(uvmap_aligncheckplane PRIVATE uvmap_aligncheckplane.cpp) + add_test(NAME Chapter05_Test COMMAND $) add_test(NAME Chapter06_Test COMMAND $) add_test(NAME Chapter07_Test COMMAND $) @@ -99,6 +102,7 @@ add_test(NAME AreaLight_Test COMMAND $) add_test(NAME UVMap_CheckeredSphere COMMAND $) add_test(NAME UVMap_CheckeredPlane COMMAND $) add_test(NAME UVMap_CheckeredCylinder COMMAND $) +add_test(NAME UVMap_AlignCheckPlane COMMAND $) add_test(NAME Test_Rendering COMMAND $) add_test(NAME Triangle_RenderTest COMMAND $) add_test(NAME ChristmasBall_Rendering COMMAND $) diff --git a/tests/pattern_test.cpp b/tests/pattern_test.cpp index 5044c5e..82ba139 100644 --- a/tests/pattern_test.cpp +++ b/tests/pattern_test.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #ifdef ENABLE_LUA_SUPPORT @@ -429,4 +430,40 @@ TEST(PatternTest, Using_a_cylindrical_mapping_on_a_3d_point) ASSERT_TRUE(double_equal(u, testResults[i][0])); ASSERT_TRUE(double_equal(v, testResults[i][1])); } +} + +TEST(PatternTest, Layout_of_the_align_check_pattern) +{ + Colour main = Colour(1, 1, 1); + Colour ul = Colour(1, 0, 0); + Colour ur = Colour(1, 1, 0); + Colour bl = Colour(0, 1, 0); + Colour br = Colour(0, 1, 1); + + double testList[][2] = { + { 0.5, 0.5 }, + { 0.1, 0.9 }, + { 0.9, 0.9 }, + { 0.1, 0.1 }, + { 0.9, 0.1 }, + }; + + Colour testResults[] { + main, + ul, + ur, + bl, + br, + }; + + int testCount = sizeof(testList)/sizeof((testList)[0]); + int i; + + UVAlignCheck uvac = UVAlignCheck(main, ul, ur, bl, br); + + for(i = 0; i < testCount; i++) + { + Colour ret = uvac.uvPatternAt(testList[i][0], testList[i][1]); + ASSERT_EQ(ret, testResults[i]); + } } \ No newline at end of file diff --git a/tests/uvmap_aligncheckplane.cpp b/tests/uvmap_aligncheckplane.cpp new file mode 100644 index 0000000..b8412b3 --- /dev/null +++ b/tests/uvmap_aligncheckplane.cpp @@ -0,0 +1,58 @@ +/* + * DoRayMe - a quick and dirty Raytracer + * Render test for chapter 10 + * + * Created by Manoël Trapier + * Copyright (c) 2020 986-Studio. + * + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +int main() +{ + World w = World(); + + Light light = Light(POINT_LIGHT, Point(-10, 10, -10), Colour(1, 1, 1)); + w.addLight(&light); + + Plane sp = Plane(); + UVAlignCheck checkers = UVAlignCheck(Colour(1, 1, 1), + Colour(1, 0, 0), + Colour(1, 1, 0), + Colour(0, 1, 0), + Colour(0, 1, 1) + ); + TextureMap tm = TextureMap(PLANAR_MAP, &checkers); + sp.material.pattern = &tm; + sp.material.ambient = 0.1; + sp.material.diffuse = 0.8; + + w.addObject(&sp); + + /* Set the camera */ + Camera camera = Camera(400, 400, 0.5); + camera.setTransform(viewTransform(Point(1, 2, -5), + Point(0, 0, 0), + Vector(0, 1, 0))); + + /* Now render it */ + Canvas image = camera.render(w); + + image.SaveAsPNG("uvmap_aligncheckplane.png"); + + return 0; +} \ No newline at end of file