Finishing touch for patterns!
This commit is contained in:
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 */
|
||||
30
source/pattern/gradientpattern.h
Normal file
30
source/pattern/gradientpattern.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* DoRayMe - a quick and dirty Raytracer
|
||||
* Gradient Pattern header
|
||||
*
|
||||
* Created by Manoël Trapier
|
||||
* Copyright (c) 2020 986-Studio.
|
||||
*
|
||||
*/
|
||||
#ifndef DORAYME_GRADIENTPATTERN_H
|
||||
#define DORAYME_GRADIENTPATTERN_H
|
||||
|
||||
#include <pattern.h>
|
||||
|
||||
class GradientPattern : public Pattern
|
||||
{
|
||||
public:
|
||||
GradientPattern(Colour a, Colour b) : Pattern(a, b) { };
|
||||
|
||||
Colour patternAt(Tuple point)
|
||||
{
|
||||
Tuple distance = this->b - this->a;
|
||||
double fraction = point.x - floor(point.x);
|
||||
|
||||
Tuple ret = this->a + distance * fraction;
|
||||
|
||||
return Colour(ret.x, ret.y, ret.z);
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* DORAYME_GRADIENTPATTERN_H */
|
||||
30
source/pattern/ringpattern.h
Normal file
30
source/pattern/ringpattern.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* DoRayMe - a quick and dirty Raytracer
|
||||
* Ring Pattern header
|
||||
*
|
||||
* Created by Manoël Trapier
|
||||
* Copyright (c) 2020 986-Studio.
|
||||
*
|
||||
*/
|
||||
#ifndef DORAYME_RINGSUPPORT_H
|
||||
#define DORAYME_RINGSUPPORT_H
|
||||
|
||||
#include <pattern.h>
|
||||
|
||||
class RingPattern : public Pattern
|
||||
{
|
||||
public:
|
||||
RingPattern(Colour a, Colour b) : Pattern(a, b) { };
|
||||
|
||||
Colour patternAt(Tuple point)
|
||||
{
|
||||
double squared = (point.x * point.x) + (point.z * point.z);
|
||||
|
||||
double value = floor(sqrt(squared));
|
||||
|
||||
return (fmod(value, 2) == 0)?this->a:this->b;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif /* DORAYME_RINGSUPPORT_H */
|
||||
32
source/pattern/strippattern.h
Normal file
32
source/pattern/strippattern.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* DoRayMe - a quick and dirty Raytracer
|
||||
* Strip Pattern header
|
||||
*
|
||||
* Created by Manoël Trapier
|
||||
* Copyright (c) 2020 986-Studio.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef DORAYME_STRIPPATTERN_H
|
||||
#define DORAYME_STRIPPATTERN_H
|
||||
|
||||
#include <pattern.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
class StripPattern : public Pattern
|
||||
{
|
||||
public:
|
||||
StripPattern(Colour a, Colour b) : Pattern(a, b) { };
|
||||
|
||||
Colour patternAt(Tuple point)
|
||||
{
|
||||
if (fmod(floor(point.x), 2) == 0)
|
||||
{
|
||||
return this->a;
|
||||
}
|
||||
return this->b;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* DORAYME_STRIPPATTERN_H */
|
||||
27
source/pattern/testpattern.h
Normal file
27
source/pattern/testpattern.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* DoRayMe - a quick and dirty Raytracer
|
||||
* Strip Pattern header
|
||||
*
|
||||
* Created by Manoël Trapier
|
||||
* Copyright (c) 2020 986-Studio.
|
||||
*
|
||||
*/
|
||||
#ifndef DORAYME_TESTPATTERN_H
|
||||
#define DORAYME_TESTPATTERN_H
|
||||
|
||||
#include <pattern.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
class TestPattern : public Pattern
|
||||
{
|
||||
public:
|
||||
TestPattern() : Pattern(Colour(0, 0, 0), Colour(1, 1, 1)) { };
|
||||
|
||||
Colour patternAt(Tuple point)
|
||||
{
|
||||
return Colour(point.x, point.y, point.z);
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* DORAYME_TESTPATTERN_H */
|
||||
Reference in New Issue
Block a user