[WIP] start chapter 10.
This commit is contained in:
@@ -18,12 +18,16 @@ add_library(raytracing
|
|||||||
src/core/intersections.cpp
|
src/core/intersections.cpp
|
||||||
src/core/matrix.cpp
|
src/core/matrix.cpp
|
||||||
src/core/tuple.cpp
|
src/core/tuple.cpp
|
||||||
|
|
||||||
src/lights/point-light.cpp
|
src/lights/point-light.cpp
|
||||||
|
|
||||||
src/renderer/camera.cpp
|
src/renderer/camera.cpp
|
||||||
src/renderer/canvas.cpp
|
src/renderer/canvas.cpp
|
||||||
src/renderer/material.cpp
|
src/renderer/material.cpp
|
||||||
src/renderer/ray.cpp
|
src/renderer/ray.cpp
|
||||||
|
src/renderer/stripe-pattern.cpp
|
||||||
src/renderer/world.cpp
|
src/renderer/world.cpp
|
||||||
|
|
||||||
src/shapes/plane.cpp
|
src/shapes/plane.cpp
|
||||||
src/shapes/shape.cpp
|
src/shapes/shape.cpp
|
||||||
src/shapes/sphere.cpp
|
src/shapes/sphere.cpp
|
||||||
|
|||||||
@@ -32,11 +32,15 @@
|
|||||||
#include "core/intersections.h"
|
#include "core/intersections.h"
|
||||||
#include "core/matrix.h"
|
#include "core/matrix.h"
|
||||||
#include "core/tuple.h"
|
#include "core/tuple.h"
|
||||||
|
|
||||||
#include "lights/point-light.h"
|
#include "lights/point-light.h"
|
||||||
|
|
||||||
#include "renderer/camera.h"
|
#include "renderer/camera.h"
|
||||||
#include "renderer/canvas.h"
|
#include "renderer/canvas.h"
|
||||||
#include "renderer/material.h"
|
#include "renderer/material.h"
|
||||||
#include "renderer/ray.h"
|
#include "renderer/ray.h"
|
||||||
|
#include "renderer/stripe-pattern.h"
|
||||||
#include "renderer/world.h"
|
#include "renderer/world.h"
|
||||||
|
|
||||||
#include "shapes/plane.h"
|
#include "shapes/plane.h"
|
||||||
#include "shapes/sphere.h"
|
#include "shapes/sphere.h"
|
||||||
|
|||||||
67
raytracing/src/renderer/stripe-pattern.cpp
Normal file
67
raytracing/src/renderer/stripe-pattern.cpp
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
/*!
|
||||||
|
* stripe-pattern.cpp
|
||||||
|
*
|
||||||
|
* Copyright (c) 2024, NADAL Jean-Baptiste. All rights reserved.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @Author: NADAL Jean-Baptiste
|
||||||
|
* @Date: 28/02/2024
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// This is an independent project of an individual developer. Dear PVS-Studio, please check it.
|
||||||
|
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
#include "core/common.h"
|
||||||
|
|
||||||
|
#include "stripe-pattern.h"
|
||||||
|
|
||||||
|
using namespace Raytracer;
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
StripePattern::StripePattern(const Color &a_color_a, const Color &a_color_b) : m_a(a_color_a), m_b(a_color_b)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
const Color &StripePattern::a(void) const
|
||||||
|
{
|
||||||
|
return m_a;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
const Color &StripePattern::b(void) const
|
||||||
|
{
|
||||||
|
return m_b;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
const Color &StripePattern::stripe_at(Tuple a_point) const
|
||||||
|
{
|
||||||
|
if (((int)std::floor(a_point.x()) % 2) == 0)
|
||||||
|
return m_a;
|
||||||
|
|
||||||
|
return m_b;
|
||||||
|
}
|
||||||
54
raytracing/src/renderer/stripe-pattern.h
Normal file
54
raytracing/src/renderer/stripe-pattern.h
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/*!
|
||||||
|
* stripe-pattern.h
|
||||||
|
*
|
||||||
|
* Copyright (c) 2024, NADAL Jean-Baptiste. All rights reserved.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @Author: NADAL Jean-Baptiste
|
||||||
|
* @Date: 28/02/2024
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _RAYTRACER_STRIPE_PATTERN_H
|
||||||
|
#define _RAYTRACER_STRIPE_PATTERN_H
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#include "core/color.h"
|
||||||
|
#include "core/tuple.h"
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
namespace Raytracer
|
||||||
|
{
|
||||||
|
class StripePattern
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
StripePattern(const Color &a_color_a, const Color &a_color_b);
|
||||||
|
|
||||||
|
const Color &a(void) const;
|
||||||
|
const Color &b(void) const;
|
||||||
|
|
||||||
|
const Color &stripe_at(Tuple a_point) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Color m_a;
|
||||||
|
Color m_b;
|
||||||
|
};
|
||||||
|
}; // namespace Raytracer
|
||||||
|
|
||||||
|
#endif /* _RAYTRACER_STRIPE_PATTERN_H */
|
||||||
125
tests/10_patterns.cpp
Normal file
125
tests/10_patterns.cpp
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
/*!
|
||||||
|
* 10_patterns.cpp
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015-2024, NADAL Jean-Baptiste. All rights reserved.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* @Author: NADAL Jean-Baptiste
|
||||||
|
* @Date: 27/02/2024
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include <catch.hpp>
|
||||||
|
|
||||||
|
#include "raytracing.h"
|
||||||
|
|
||||||
|
using namespace Raytracer;
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
SCENARIO("Creating a stripe pattern", "[features/patterns.feature]")
|
||||||
|
{
|
||||||
|
GIVEN("pattern <- strip_pattern(white, black)")
|
||||||
|
{
|
||||||
|
StripePattern pattern(Color::White(), Color::Black());
|
||||||
|
THEN("pattern.a = white")
|
||||||
|
{
|
||||||
|
REQUIRE(pattern.a() == Color::White());
|
||||||
|
}
|
||||||
|
AND_THEN("pattern.b = black")
|
||||||
|
{
|
||||||
|
REQUIRE(pattern.b() == Color::Black());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
SCENARIO("A stripe pattern is constant in y", "[features/patterns.feature]")
|
||||||
|
{
|
||||||
|
GIVEN("pattern <- strip_pattern(white, black)")
|
||||||
|
{
|
||||||
|
StripePattern pattern(Color::White(), Color::Black());
|
||||||
|
THEN("stripe_at(pattern, point(0, 0, 0) = white")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
AND_THEN("stripe_at(pattern, point(0, 1, 0) = white")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
AND_THEN("stripe_at(pattern, point(0, 2, 0) = white")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
SCENARIO("A stripe pattern is constant in z", "[features/patterns.feature]")
|
||||||
|
{
|
||||||
|
GIVEN("pattern <- strip_pattern(white, black)")
|
||||||
|
{
|
||||||
|
StripePattern pattern(Color::White(), Color::Black());
|
||||||
|
THEN("stripe_at(pattern, point(0, 0, 0) = white")
|
||||||
|
{
|
||||||
|
REQUIRE(pattern.stripe_at(Tuple::Point(0, 0, 0)) == Color::White());
|
||||||
|
}
|
||||||
|
AND_THEN("stripe_at(pattern, point(0, 0, 1) = white")
|
||||||
|
{
|
||||||
|
REQUIRE(pattern.stripe_at(Tuple::Point(0, 0, 1)) == Color::White());
|
||||||
|
}
|
||||||
|
AND_THEN("stripe_at(pattern, point(0, 0, 2) = white")
|
||||||
|
{
|
||||||
|
REQUIRE(pattern.stripe_at(Tuple::Point(0, 0, 2)) == Color::White());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
SCENARIO("A stripe pattern alternates in x", "[features/patterns.feature]")
|
||||||
|
{
|
||||||
|
GIVEN("pattern <- strip_pattern(white, black)")
|
||||||
|
{
|
||||||
|
StripePattern pattern(Color::White(), Color::Black());
|
||||||
|
THEN("stripe_at(pattern, point(0, 0, 0) = white")
|
||||||
|
{
|
||||||
|
REQUIRE(pattern.stripe_at(Tuple::Point(0, 0, 0)) == Color::White());
|
||||||
|
}
|
||||||
|
AND_THEN("stripe_at(pattern, point(0.9, 0, 0) = white")
|
||||||
|
{
|
||||||
|
REQUIRE(pattern.stripe_at(Tuple::Point(0.9, 0, 0)) == Color::White());
|
||||||
|
}
|
||||||
|
AND_THEN("stripe_at(pattern, point(1, 0, 0) = black")
|
||||||
|
{
|
||||||
|
REQUIRE(pattern.stripe_at(Tuple::Point(1, 0, 0)) == Color::Black());
|
||||||
|
}
|
||||||
|
AND_THEN("stripe_at(pattern, point(-0.1, 0, 0) = black")
|
||||||
|
{
|
||||||
|
REQUIRE(pattern.stripe_at(Tuple::Point(-0.1, 0, 0)) == Color::Black());
|
||||||
|
}
|
||||||
|
AND_THEN("stripe_at(pattern, point(-1, 0, 0) = black")
|
||||||
|
{
|
||||||
|
REQUIRE(pattern.stripe_at(Tuple::Point(-1, 0, 0)) == Color::Black());
|
||||||
|
}
|
||||||
|
AND_THEN("stripe_at(pattern, point(-1.1, 0, 0) = white")
|
||||||
|
{
|
||||||
|
REQUIRE(pattern.stripe_at(Tuple::Point(-1.1, 0, 0)) == Color::White());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
cmake_minimum_required(VERSION 3.14)
|
cmake_minimum_required(VERSION 3.19)
|
||||||
|
|
||||||
project(raytracing_test)
|
project(raytracing_test)
|
||||||
|
|
||||||
@@ -20,6 +20,7 @@ add_executable(raytracing_test
|
|||||||
07_making_scene.cpp
|
07_making_scene.cpp
|
||||||
08_shadows.cpp
|
08_shadows.cpp
|
||||||
09_planes.cpp
|
09_planes.cpp
|
||||||
|
10_patterns.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
include_directories("${CMAKE_SOURCE_DIR}/tests")
|
include_directories("${CMAKE_SOURCE_DIR}/tests")
|
||||||
|
|||||||
Reference in New Issue
Block a user