Started working on 2D patterns.
This commit is contained in:
@@ -8,7 +8,8 @@ endif()
|
||||
# First most is build as a library
|
||||
add_library(rayonnement STATIC)
|
||||
|
||||
file(GLOB RAY_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h ${CMAKE_CURRENT_SOURCE_DIR}/pattern/*.h)
|
||||
file(GLOB RAY_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h ${CMAKE_CURRENT_SOURCE_DIR}/pattern/*.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/uvpattern/*.h)
|
||||
|
||||
file(GLOB RAY_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/shapes/*.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/worldbuilder/*.cpp)
|
||||
|
||||
28
source/include/uv_pattern.h
Normal file
28
source/include/uv_pattern.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* DoRayMe - a quick and dirty Raytracer
|
||||
* UV Pattern header
|
||||
*
|
||||
* Created by Manoël Trapier
|
||||
* Copyright (c) 2020 986-Studio.
|
||||
*
|
||||
*/
|
||||
#ifndef DORAYME_UV_PATTERN_H
|
||||
#define DORAYME_UV_PATTERN_H
|
||||
|
||||
#include <colour.h>
|
||||
|
||||
class UVPattern
|
||||
{
|
||||
public:
|
||||
Colour a;
|
||||
Colour b;
|
||||
double width;
|
||||
double height;
|
||||
|
||||
UVPattern(double width, double height, Colour a, Colour b) : a(a), b(b),
|
||||
width(width), height(height) {};
|
||||
|
||||
virtual Colour uvPatternAt(double u, double v) = 0;
|
||||
};
|
||||
|
||||
#endif /* DORAYME_UV_PATTERN_H */
|
||||
32
source/uvpattern/uv_checkers.h
Normal file
32
source/uvpattern/uv_checkers.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* DoRayMe - a quick and dirty Raytracer
|
||||
* UV Checkers header
|
||||
*
|
||||
* Created by Manoël Trapier
|
||||
* Copyright (c) 2020 986-Studio.
|
||||
*
|
||||
*/
|
||||
#ifndef DORAYME_UV_CHECKERS_H
|
||||
#define DORAYME_UV_CHECKERS_H
|
||||
|
||||
#include <uv_pattern.h>
|
||||
#include <math.h>
|
||||
|
||||
class UVCheckers : public UVPattern
|
||||
{
|
||||
public:
|
||||
UVCheckers(double width, double height, Colour a, Colour b) : UVPattern(width, height, a, b) {};
|
||||
|
||||
Colour uvPatternAt(double u, double v) {
|
||||
double u2 = floor(u * this->width);
|
||||
double v2 = floor(v * this->width);
|
||||
|
||||
if (fmod((u2 + v2), 2) == 0)
|
||||
{
|
||||
return this->a;
|
||||
}
|
||||
return this->b;
|
||||
};
|
||||
};
|
||||
|
||||
#endif /* DORAYME_UV_CHECKERS_H */
|
||||
Reference in New Issue
Block a user