Finishing touch for patterns!
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
25
source/pattern/checkerspattern.h
Normal file
25
source/pattern/checkerspattern.h
Normal 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 */
|
||||
@@ -27,4 +27,4 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
#endif //DORAYME_GRADIENTPATTERN_H
|
||||
#endif /* DORAYME_GRADIENTPATTERN_H */
|
||||
@@ -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 */
|
||||
@@ -24,4 +24,4 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
#endif //DORAYME_TESTPATTERN_H
|
||||
#endif /* DORAYME_TESTPATTERN_H */
|
||||
Reference in New Issue
Block a user