Finishing touch for patterns!

This commit is contained in:
Godzil
2020-02-21 12:05:30 +00:00
parent 75cf59cc1a
commit 7687581e83
11 changed files with 86 additions and 14 deletions

View File

@@ -3,12 +3,12 @@
# First most is build as a library
add_library(rayonnement STATIC)
file(GLOB RAY_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h)
file(GLOB RAY_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h ${CMAKE_CURRENT_SOURCE_DIR}/pattern/*.h)
file(GLOB RAY_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/shapes/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/worldbuilder/*.cpp)
target_include_directories(rayonnement PUBLIC include)
target_include_directories(rayonnement PUBLIC include pattern)
target_sources(rayonnement PRIVATE ${RAY_HEADERS} ${RAY_SOURCES})
target_link_libraries(rayonnement LodePNG)

View File

@@ -0,0 +1,25 @@
/*
* DoRayMe - a quick and dirty Raytracer
* Checkers Pattern header
*
* Created by Manoël Trapier
* Copyright (c) 2020 986-Studio.
*
*/
#ifndef DORAYME_CHECKERSPATTERN_H
#define DORAYME_CHECKERSPATTERN_H
class CheckersPattern : public Pattern
{
public:
CheckersPattern(Colour a, Colour b) : Pattern(a, b) { };
Colour patternAt(Tuple point)
{
double value = floor(point.x) + floor(point.y) + floor(point.z);
return (fmod(value, 2) == 0)?this->a:this->b;
}
};
#endif /* DORAYME_CHECKERSPATTERN_H */

View File

@@ -27,4 +27,4 @@ public:
}
};
#endif //DORAYME_GRADIENTPATTERN_H
#endif /* DORAYME_GRADIENTPATTERN_H */

View File

@@ -18,14 +18,13 @@ public:
Colour patternAt(Tuple point)
{
Tuple distance = this->b - this->a;
double fraction = point.x - floor(point.x);
double squared = (point.x * point.x) + (point.z * point.z);
Tuple ret = this->a + distance * fraction;
double value = floor(sqrt(squared));
return Colour(ret.x, ret.y, ret.z);
return (fmod(value, 2) == 0)?this->a:this->b;
}
};
#endif //DORAYME_RINGSUPPORT_H
#endif /* DORAYME_RINGSUPPORT_H */

View File

@@ -24,4 +24,4 @@ public:
}
};
#endif //DORAYME_TESTPATTERN_H
#endif /* DORAYME_TESTPATTERN_H */