Add AlignCheck UV Pattern

This commit is contained in:
Godzil
2020-03-04 16:42:43 +00:00
parent 7209244f48
commit f5685a45e1
6 changed files with 142 additions and 1 deletions

View File

@@ -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 $<TARGET_FILE:ch5_test>)
add_test(NAME Chapter06_Test COMMAND $<TARGET_FILE:ch6_test>)
add_test(NAME Chapter07_Test COMMAND $<TARGET_FILE:ch7_test>)
@@ -99,6 +102,7 @@ add_test(NAME AreaLight_Test COMMAND $<TARGET_FILE:arealight_test>)
add_test(NAME UVMap_CheckeredSphere COMMAND $<TARGET_FILE:uvmap_checkeredsphere>)
add_test(NAME UVMap_CheckeredPlane COMMAND $<TARGET_FILE:uvmap_checkeredplane>)
add_test(NAME UVMap_CheckeredCylinder COMMAND $<TARGET_FILE:uvmap_checkeredcylinder>)
add_test(NAME UVMap_AlignCheckPlane COMMAND $<TARGET_FILE:uvmap_aligncheckplane>)
add_test(NAME Test_Rendering COMMAND $<TARGET_FILE:test_render>)
add_test(NAME Triangle_RenderTest COMMAND $<TARGET_FILE:triangle_rendertest>)
add_test(NAME ChristmasBall_Rendering COMMAND $<TARGET_FILE:christmasball_render>)

View File

@@ -20,6 +20,7 @@
#include <material.h>
#include <uv_pattern.h>
#include <uv_checkers.h>
#include <uv_aligncheck.h>
#include <texturemap.h>
#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]);
}
}

View File

@@ -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 <world.h>
#include <light.h>
#include <sphere.h>
#include <plane.h>
#include <material.h>
#include <colour.h>
#include <canvas.h>
#include <camera.h>
#include <pattern.h>
#include <texturemap.h>
#include <uv_checkers.h>
#include <uv_aligncheck.h>
#include <transformation.h>
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;
}