Skip to content

Commit

Permalink
Add AlignCheck UV Pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Godzil committed Mar 4, 2020
1 parent 7209244 commit f5685a4
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,7 @@ Planar mapping:
![Planar mapping](output/uvmap_checkeredplane.png)

Cylindrical mapping:
![Cylindrical mapping](output/uvmap_checkeredcylinder.png)
![Cylindrical mapping](output/uvmap_checkeredcylinder.png)

Aligncheck plane:
![Aligncheck plane](output/uvmap_aligncheckplane.png)
Binary file added output/uvmap_aligncheckplane.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions source/uvpattern/uv_aligncheck.h
Original file line number Diff line number Diff line change
@@ -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 */
4 changes: 4 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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>)
Expand All @@ -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>)
Expand Down
37 changes: 37 additions & 0 deletions tests/pattern_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]);
}
}
58 changes: 58 additions & 0 deletions tests/uvmap_aligncheckplane.cpp
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit f5685a4

Please sign in to comment.