[ADD] add a skeleton of the group and refactor some test datas.
This commit is contained in:
@@ -37,6 +37,7 @@ add_library(raytracing
|
|||||||
src/shapes/cone.cpp
|
src/shapes/cone.cpp
|
||||||
src/shapes/cube.cpp
|
src/shapes/cube.cpp
|
||||||
src/shapes/cylinder.cpp
|
src/shapes/cylinder.cpp
|
||||||
|
src/shapes/group.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
|
||||||
|
|||||||
@@ -49,5 +49,6 @@
|
|||||||
#include "shapes/cone.h"
|
#include "shapes/cone.h"
|
||||||
#include "shapes/cube.h"
|
#include "shapes/cube.h"
|
||||||
#include "shapes/cylinder.h"
|
#include "shapes/cylinder.h"
|
||||||
|
#include "shapes/group.h"
|
||||||
#include "shapes/plane.h"
|
#include "shapes/plane.h"
|
||||||
#include "shapes/sphere.h"
|
#include "shapes/sphere.h"
|
||||||
61
raytracing/src/shapes/group.cpp
Normal file
61
raytracing/src/shapes/group.cpp
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/*!
|
||||||
|
* group.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: 22/03/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 "core/intersections.h"
|
||||||
|
|
||||||
|
#include "group.h"
|
||||||
|
|
||||||
|
using namespace Raytracer;
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
Intersections Group::local_intersect(const Ray &a_ray)
|
||||||
|
{
|
||||||
|
Intersections the_intersections;
|
||||||
|
|
||||||
|
return the_intersections;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
Tuple Group::local_normal_at(const Tuple &a_local_point) const
|
||||||
|
{
|
||||||
|
return Tuple::Vector(0, 1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
bool Group::is_empty(void)
|
||||||
|
{
|
||||||
|
return m_data.size() == 0;
|
||||||
|
}
|
||||||
55
raytracing/src/shapes/group.h
Normal file
55
raytracing/src/shapes/group.h
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
/*!
|
||||||
|
* group.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: 22/03/2024
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _RAYTRACER_GROUP_H
|
||||||
|
#define _RAYTRACER_GROUP_H
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "shapes/shape.h"
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
namespace Raytracer
|
||||||
|
{
|
||||||
|
class Group : public Shape
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Group(void) = default;
|
||||||
|
Intersections local_intersect(const Ray &a_ray) override;
|
||||||
|
Tuple local_normal_at(const Tuple &a_local_point) const override;
|
||||||
|
|
||||||
|
bool is_empty(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<Shape *> m_data;
|
||||||
|
};
|
||||||
|
}; // namespace Raytracer
|
||||||
|
|
||||||
|
#endif // _RAYTRACER_GROUP_H
|
||||||
@@ -41,7 +41,8 @@ using namespace Raytracer;
|
|||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
Shape::Shape(void) :
|
Shape::Shape(void) :
|
||||||
m_transform(Matrix::identity())
|
m_transform(Matrix::identity()),
|
||||||
|
m_parent(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +50,8 @@ Shape::Shape(void) :
|
|||||||
|
|
||||||
Shape::Shape(Shape &a_copy) :
|
Shape::Shape(Shape &a_copy) :
|
||||||
m_transform(a_copy.m_transform),
|
m_transform(a_copy.m_transform),
|
||||||
m_material(a_copy.m_material)
|
m_material(a_copy.m_material),
|
||||||
|
m_parent(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +59,8 @@ Shape::Shape(Shape &a_copy) :
|
|||||||
|
|
||||||
Shape::Shape(const Shape &a_copy) :
|
Shape::Shape(const Shape &a_copy) :
|
||||||
m_transform(a_copy.m_transform),
|
m_transform(a_copy.m_transform),
|
||||||
m_material(a_copy.m_material)
|
m_material(a_copy.m_material),
|
||||||
|
m_parent(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,6 +75,7 @@ const Shape &Shape::operator=(const Shape &a_shape)
|
|||||||
|
|
||||||
m_transform = a_shape.m_transform;
|
m_transform = a_shape.m_transform;
|
||||||
m_material = a_shape.m_material;
|
m_material = a_shape.m_material;
|
||||||
|
m_parent = a_shape.m_parent;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -80,14 +84,14 @@ const Shape &Shape::operator=(const Shape &a_shape)
|
|||||||
|
|
||||||
bool Shape::operator==(const Shape &a_shape) const
|
bool Shape::operator==(const Shape &a_shape) const
|
||||||
{
|
{
|
||||||
return (m_transform == a_shape.m_transform) && (m_material == a_shape.m_material);
|
return (m_transform == a_shape.m_transform) && (m_material == a_shape.m_material) && (m_parent == a_shape.m_parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
bool Shape::operator==(const Shape *a_shape) const
|
bool Shape::operator==(const Shape *a_shape) const
|
||||||
{
|
{
|
||||||
return (m_transform == a_shape->m_transform) && (m_material == a_shape->m_material);
|
return (m_transform == a_shape->m_transform) && (m_material == a_shape->m_material) && (m_parent == a_shape->m_parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
@@ -134,6 +138,20 @@ void Shape::set_material(const Material &a_material)
|
|||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
Shape *Shape::parent(void)
|
||||||
|
{
|
||||||
|
return m_parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
void Shape::set_parent(Shape *a_shape)
|
||||||
|
{
|
||||||
|
m_parent = a_shape;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
Tuple Shape::normal_at(const Tuple &a_world_point) const
|
Tuple Shape::normal_at(const Tuple &a_world_point) const
|
||||||
{
|
{
|
||||||
Tuple the_local_point = m_transform.inverse() * a_world_point;
|
Tuple the_local_point = m_transform.inverse() * a_world_point;
|
||||||
|
|||||||
@@ -61,6 +61,9 @@ namespace Raytracer
|
|||||||
const Material &material(void) const;
|
const Material &material(void) const;
|
||||||
void set_material(const Material &a_material);
|
void set_material(const Material &a_material);
|
||||||
|
|
||||||
|
Shape *parent(void);
|
||||||
|
void set_parent(Shape *a_shape);
|
||||||
|
|
||||||
Tuple normal_at(const Tuple &a_point) const;
|
Tuple normal_at(const Tuple &a_point) const;
|
||||||
virtual Tuple local_normal_at(const Tuple &a_local_point) const;
|
virtual Tuple local_normal_at(const Tuple &a_local_point) const;
|
||||||
|
|
||||||
@@ -70,6 +73,7 @@ namespace Raytracer
|
|||||||
private:
|
private:
|
||||||
Matrix m_transform;
|
Matrix m_transform;
|
||||||
Material m_material;
|
Material m_material;
|
||||||
|
Shape *m_parent;
|
||||||
};
|
};
|
||||||
}; // namespace Raytracer
|
}; // namespace Raytracer
|
||||||
|
|
||||||
|
|||||||
54
tests/00_common_data.cpp
Normal file
54
tests/00_common_data.cpp
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/*!
|
||||||
|
* 00_common_data.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: 22/03/2024
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include <core/intersections.h>
|
||||||
|
|
||||||
|
#include "common_data.h"
|
||||||
|
|
||||||
|
using namespace Raytracer;
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
Intersections TestShape::local_intersect(const Ray &a_ray)
|
||||||
|
{
|
||||||
|
saved_ray = a_ray;
|
||||||
|
return Intersections();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
Tuple TestShape::local_normal_at(const Tuple &a_local_point) const
|
||||||
|
{
|
||||||
|
return Tuple::Vector(a_local_point.x(), a_local_point.y(), a_local_point.z());
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
const Color TestPattern::pattern_at(const Tuple &a_point) const
|
||||||
|
{
|
||||||
|
return Color(a_point.x(), a_point.y(), a_point.z());
|
||||||
|
}
|
||||||
@@ -31,38 +31,12 @@
|
|||||||
|
|
||||||
#include "raytracing.h"
|
#include "raytracing.h"
|
||||||
|
|
||||||
|
#include "common_data.h"
|
||||||
|
|
||||||
using namespace Raytracer;
|
using namespace Raytracer;
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
class TestShape : public Shape
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
TestShape(void) = default;
|
|
||||||
|
|
||||||
Intersections local_intersect(const Ray &a_ray) override
|
|
||||||
{
|
|
||||||
saved_ray = a_ray;
|
|
||||||
return Intersections();
|
|
||||||
}
|
|
||||||
|
|
||||||
Tuple local_normal_at(const Tuple &a_local_point) const override
|
|
||||||
{
|
|
||||||
return Tuple::Vector(a_local_point.x(), a_local_point.y(), a_local_point.z());
|
|
||||||
}
|
|
||||||
|
|
||||||
Ray saved_ray;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
TestShape test_shape(void)
|
|
||||||
{
|
|
||||||
return TestShape();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
SCENARIO("The default transformation", "[features/shapes.feature]")
|
SCENARIO("The default transformation", "[features/shapes.feature]")
|
||||||
{
|
{
|
||||||
GIVEN("s <- test_shape()")
|
GIVEN("s <- test_shape()")
|
||||||
|
|||||||
@@ -29,23 +29,12 @@
|
|||||||
|
|
||||||
#include "raytracing.h"
|
#include "raytracing.h"
|
||||||
|
|
||||||
|
#include "common_data.h"
|
||||||
|
|
||||||
using namespace Raytracer;
|
using namespace Raytracer;
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
class TestPattern : public Pattern
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
TestPattern(void) = default;
|
|
||||||
|
|
||||||
const Color pattern_at(const Tuple &a_point) const override
|
|
||||||
{
|
|
||||||
return Color(a_point.x(), a_point.y(), a_point.z());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
SCENARIO("Creating a stripe pattern", "[features/patterns.feature]")
|
SCENARIO("Creating a stripe pattern", "[features/patterns.feature]")
|
||||||
{
|
{
|
||||||
GIVEN("pattern <- stripe_pattern(white, black)")
|
GIVEN("pattern <- stripe_pattern(white, black)")
|
||||||
|
|||||||
@@ -31,23 +31,12 @@
|
|||||||
|
|
||||||
#include "raytracing.h"
|
#include "raytracing.h"
|
||||||
|
|
||||||
|
#include "common_data.h"
|
||||||
|
|
||||||
using namespace Raytracer;
|
using namespace Raytracer;
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
class TestPattern : public Pattern
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
TestPattern(void) = default;
|
|
||||||
|
|
||||||
const Color pattern_at(const Tuple &a_point) const override
|
|
||||||
{
|
|
||||||
return Color(a_point.x(), a_point.y(), a_point.z());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
SCENARIO("Reflectivity for the default material", "[features/materials.feature]")
|
SCENARIO("Reflectivity for the default material", "[features/materials.feature]")
|
||||||
{
|
{
|
||||||
GIVEN("m <- material()")
|
GIVEN("m <- material()")
|
||||||
|
|||||||
@@ -29,30 +29,12 @@
|
|||||||
|
|
||||||
#include "raytracing.h"
|
#include "raytracing.h"
|
||||||
|
|
||||||
|
#include "common_data.h"
|
||||||
|
|
||||||
using namespace Raytracer;
|
using namespace Raytracer;
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
class CubeTestIntersect
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Tuple origin;
|
|
||||||
Tuple direction;
|
|
||||||
double t1;
|
|
||||||
double t2;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
class CubeTestNormal
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Tuple point;
|
|
||||||
Tuple normal;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
SCENARIO("A Ray intersects a cube", "[features/cubes.feature]")
|
SCENARIO("A Ray intersects a cube", "[features/cubes.feature]")
|
||||||
{
|
{
|
||||||
// | | origin | direction | t1 | t2 |
|
// | | origin | direction | t1 | t2 |
|
||||||
@@ -63,7 +45,7 @@ SCENARIO("A Ray intersects a cube", "[features/cubes.feature]")
|
|||||||
// | +z | point(0.5, 0, 5) | vector( 0, 0,-1) | 4 | 6 |
|
// | +z | point(0.5, 0, 5) | vector( 0, 0,-1) | 4 | 6 |
|
||||||
// | -z | point(0.5, 0, -5) | vector( 0, 0, 1) | 4 | 6 |
|
// | -z | point(0.5, 0, -5) | vector( 0, 0, 1) | 4 | 6 |
|
||||||
// | inside | point(0, 0.5, 0) | vector( 0, 0, 1) | -1 | -1 |
|
// | inside | point(0, 0.5, 0) | vector( 0, 0, 1) | -1 | -1 |
|
||||||
CubeTestIntersect the_test[] = {
|
DataOrigDirT1T2 the_test[] = {
|
||||||
{ Tuple::Point(5.0, 0.5, 0.0), Tuple::Vector(-1, 0, 0), 4, 6},
|
{ Tuple::Point(5.0, 0.5, 0.0), Tuple::Vector(-1, 0, 0), 4, 6},
|
||||||
{Tuple::Point(-5.0, 0.5, 0.0), Tuple::Vector(1, 0, 0), 4, 6},
|
{Tuple::Point(-5.0, 0.5, 0.0), Tuple::Vector(1, 0, 0), 4, 6},
|
||||||
{ Tuple::Point(0.5, 5.0, 0.0), Tuple::Vector(0, -1, 0), 4, 6},
|
{ Tuple::Point(0.5, 5.0, 0.0), Tuple::Vector(0, -1, 0), 4, 6},
|
||||||
@@ -113,7 +95,7 @@ SCENARIO("A Ray misses a cube", "[features/cubes.feature]")
|
|||||||
// | point(2, 0, 2) | vector(0, 0, -1) |
|
// | point(2, 0, 2) | vector(0, 0, -1) |
|
||||||
// | point(0, 2, 2) | vector(0, -1, 0) |
|
// | point(0, 2, 2) | vector(0, -1, 0) |
|
||||||
// | point(2, 2, 0) | vector(-1, 0, 0) |
|
// | point(2, 2, 0) | vector(-1, 0, 0) |
|
||||||
CubeTestIntersect the_test[] = {
|
DataOrigDirT1T2 the_test[] = {
|
||||||
{Tuple::Point(-2, 0, 0), Tuple::Vector(0.2673, 0.5345, 0.8018), -1, -1},
|
{Tuple::Point(-2, 0, 0), Tuple::Vector(0.2673, 0.5345, 0.8018), -1, -1},
|
||||||
{ Tuple::Point(0, -2, 0), Tuple::Vector(0.8018, 0.2673, 0.5345), -1, -1},
|
{ Tuple::Point(0, -2, 0), Tuple::Vector(0.8018, 0.2673, 0.5345), -1, -1},
|
||||||
{ Tuple::Point(0, 0, -2), Tuple::Vector(0.5345, 0.8018, 0.2673), -1, -1},
|
{ Tuple::Point(0, 0, -2), Tuple::Vector(0.5345, 0.8018, 0.2673), -1, -1},
|
||||||
@@ -155,7 +137,7 @@ SCENARIO("The normal on the surface of a cube", "[features/cubes.feature]")
|
|||||||
// | point(0.4, 0.4, -1) | vector(0, 0, -1) |
|
// | point(0.4, 0.4, -1) | vector(0, 0, -1) |
|
||||||
// | point(1, 1, -1) | vector(1, 0, 0) |
|
// | point(1, 1, -1) | vector(1, 0, 0) |
|
||||||
// | point(-1,-1, -1) | vector(-1, 0, 0) |
|
// | point(-1,-1, -1) | vector(-1, 0, 0) |
|
||||||
CubeTestNormal the_test[] = {
|
DataPointNormal the_test[] = {
|
||||||
{ Tuple::Point(1, 0.5, -0.8), Tuple::Vector(1, 0, 0)},
|
{ Tuple::Point(1, 0.5, -0.8), Tuple::Vector(1, 0, 0)},
|
||||||
{ Tuple::Point(-1, -0.2, 0.9), Tuple::Vector(-1, 0, 0)},
|
{ Tuple::Point(-1, -0.2, 0.9), Tuple::Vector(-1, 0, 0)},
|
||||||
{Tuple::Point(-0.4, 1, -0.1), Tuple::Vector(0, 1, 0)},
|
{Tuple::Point(-0.4, 1, -0.1), Tuple::Vector(0, 1, 0)},
|
||||||
|
|||||||
@@ -29,57 +29,19 @@
|
|||||||
|
|
||||||
#include "raytracing.h"
|
#include "raytracing.h"
|
||||||
|
|
||||||
|
#include "common_data.h"
|
||||||
|
|
||||||
using namespace Raytracer;
|
using namespace Raytracer;
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
class CylinderTestIntersect
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Tuple origin;
|
|
||||||
Tuple direction;
|
|
||||||
double t0 = -1;
|
|
||||||
double t1 = -1;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
class CylinderTestNormal
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Tuple point;
|
|
||||||
Tuple normal;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
class CylinderTestConstrained
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Tuple point;
|
|
||||||
Tuple direction;
|
|
||||||
uint16_t count;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
class ConeTestConstrained
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Tuple origin;
|
|
||||||
Tuple direction;
|
|
||||||
uint16_t count;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
SCENARIO("A Ray misses a cylinder", "[features/cylinders.feature]")
|
SCENARIO("A Ray misses a cylinder", "[features/cylinders.feature]")
|
||||||
{
|
{
|
||||||
// | origin | direction |
|
// | origin | direction |
|
||||||
// | point(1, 0, 0) | vector(0, 1, 0) |
|
// | point(1, 0, 0) | vector(0, 1, 0) |
|
||||||
// | point(0, 0, 0) | vector(0, 1, 0) |
|
// | point(0, 0, 0) | vector(0, 1, 0) |
|
||||||
// | point(0, 0, -5) | vector(1, 1, 1) |
|
// | point(0, 0, -5) | vector(1, 1, 1) |
|
||||||
CylinderTestIntersect the_test[] = {
|
DataOrigDirT0T1 the_test[] = {
|
||||||
{Tuple::Point(1, 0, 0), Tuple::Vector(0, 1, 0)},
|
{Tuple::Point(1, 0, 0), Tuple::Vector(0, 1, 0)},
|
||||||
{Tuple::Point(0, 0, 0), Tuple::Vector(0, 1, 0)},
|
{Tuple::Point(0, 0, 0), Tuple::Vector(0, 1, 0)},
|
||||||
{Tuple::Point(0, 0, -5), Tuple::Vector(1, 1, 1)}
|
{Tuple::Point(0, 0, -5), Tuple::Vector(1, 1, 1)}
|
||||||
@@ -114,7 +76,7 @@ SCENARIO("A Ray strikes a cylinder", "[features/cylinders.feature]")
|
|||||||
// | point(1, 0, -5) | vector(0, 0, 1) | 5 | 5 |
|
// | point(1, 0, -5) | vector(0, 0, 1) | 5 | 5 |
|
||||||
// | point(0, 0, -5) | vector(0, 0, 1) | 4 | 6 |
|
// | point(0, 0, -5) | vector(0, 0, 1) | 4 | 6 |
|
||||||
// | point(0.5, 0, -5) | vector(0.1, 1, 1) | 6.80798 | 7.08872 |
|
// | point(0.5, 0, -5) | vector(0.1, 1, 1) | 6.80798 | 7.08872 |
|
||||||
CylinderTestIntersect the_test[] = {
|
DataOrigDirT0T1 the_test[] = {
|
||||||
{ Tuple::Point(1, 0, -5), Tuple::Vector(0, 0, 1), 5, 5},
|
{ Tuple::Point(1, 0, -5), Tuple::Vector(0, 0, 1), 5, 5},
|
||||||
{ Tuple::Point(0, 0, -5), Tuple::Vector(0, 0, 1), 4, 6},
|
{ Tuple::Point(0, 0, -5), Tuple::Vector(0, 0, 1), 4, 6},
|
||||||
{Tuple::Point(0.5, 0, -5), Tuple::Vector(0.1, 1, 1), 6.80798, 7.08872}
|
{Tuple::Point(0.5, 0, -5), Tuple::Vector(0.1, 1, 1), 6.80798, 7.08872}
|
||||||
@@ -161,7 +123,7 @@ SCENARIO("Normal vector on a cylinder", "[features/cylinders.feature]")
|
|||||||
// | point(0, 5, -1) | vector(0, 0, -1) |
|
// | point(0, 5, -1) | vector(0, 0, -1) |
|
||||||
// | point(0, -2, 1) | vector(0, 0, 1) |
|
// | point(0, -2, 1) | vector(0, 0, 1) |
|
||||||
// | point(-1, 1, 0) | vector(-1, 0, 0) |
|
// | point(-1, 1, 0) | vector(-1, 0, 0) |
|
||||||
CylinderTestNormal the_test[] = {
|
DataPointNormal the_test[] = {
|
||||||
{ Tuple::Point(1, 0, 0), Tuple::Vector(1, 0, 0)},
|
{ Tuple::Point(1, 0, 0), Tuple::Vector(1, 0, 0)},
|
||||||
{ Tuple::Point(0, 5, -1), Tuple::Vector(0, 0, -1)},
|
{ Tuple::Point(0, 5, -1), Tuple::Vector(0, 0, -1)},
|
||||||
{ Tuple::Point(0, -2, 1), Tuple::Vector(0, 0, 1)},
|
{ Tuple::Point(0, -2, 1), Tuple::Vector(0, 0, 1)},
|
||||||
@@ -215,7 +177,7 @@ SCENARIO("Intersecting a constrained cylinder", "[features/cylinders.feature]")
|
|||||||
// | 4 | point(0, 2, -5) | vector(0, 0, 1) | 0 |
|
// | 4 | point(0, 2, -5) | vector(0, 0, 1) | 0 |
|
||||||
// | 5 | point(0, 1, -5) | vector(0, 0, 1) | 0 |
|
// | 5 | point(0, 1, -5) | vector(0, 0, 1) | 0 |
|
||||||
// | 6 | point(0, 1.5, -2) | vector(0, 0, 1) | 2 |
|
// | 6 | point(0, 1.5, -2) | vector(0, 0, 1) | 2 |
|
||||||
CylinderTestConstrained the_test[] = {
|
DataPointDirCount the_test[] = {
|
||||||
{Tuple::Point(0, 1.5, 0), Tuple::Vector(0.1, 1, 0), 0},
|
{Tuple::Point(0, 1.5, 0), Tuple::Vector(0.1, 1, 0), 0},
|
||||||
{Tuple::Point(0, 3, -5), Tuple::Vector(0, 0, 1), 0},
|
{Tuple::Point(0, 3, -5), Tuple::Vector(0, 0, 1), 0},
|
||||||
{Tuple::Point(0, 0, -5), Tuple::Vector(0, 0, 1), 0},
|
{Tuple::Point(0, 0, -5), Tuple::Vector(0, 0, 1), 0},
|
||||||
@@ -280,7 +242,7 @@ SCENARIO("Intersecting the caps of a closed cylinder", "[features/cylinders.feat
|
|||||||
// | 3 | point(0, 4, -2) | vector(0, -1, 1) | 2 | # corner case
|
// | 3 | point(0, 4, -2) | vector(0, -1, 1) | 2 | # corner case
|
||||||
// | 4 | point(0, 0, -2) | vector(0, 1, 2) | 2 |
|
// | 4 | point(0, 0, -2) | vector(0, 1, 2) | 2 |
|
||||||
// | 5 | point(0, -1, -2) | vector(0, 1, 1) | 2 | # corner case
|
// | 5 | point(0, -1, -2) | vector(0, 1, 1) | 2 | # corner case
|
||||||
CylinderTestConstrained the_test[] = {
|
DataPointDirCount the_test[] = {
|
||||||
{Tuple::Point(0, 3, 0), Tuple::Vector(0, -1, 0), 2},
|
{Tuple::Point(0, 3, 0), Tuple::Vector(0, -1, 0), 2},
|
||||||
{Tuple::Point(0, 3, -2), Tuple::Vector(0, -1, 2), 2},
|
{Tuple::Point(0, 3, -2), Tuple::Vector(0, -1, 2), 2},
|
||||||
{Tuple::Point(0, 4, -2), Tuple::Vector(0, -1, 1), 2},
|
{Tuple::Point(0, 4, -2), Tuple::Vector(0, -1, 1), 2},
|
||||||
@@ -335,7 +297,7 @@ SCENARIO("The normal vector on the cylinder's end caps", "[features/cylinders.fe
|
|||||||
// | point(0, 2, 0) | vector(0, 1, 0) |
|
// | point(0, 2, 0) | vector(0, 1, 0) |
|
||||||
// | point(0.5, 2, 0) | vector(0, 1, 0) |
|
// | point(0.5, 2, 0) | vector(0, 1, 0) |
|
||||||
// | point(0, 2, 0.5) | vector(0, 1, 0) |
|
// | point(0, 2, 0.5) | vector(0, 1, 0) |
|
||||||
CylinderTestNormal the_test[] = {
|
DataPointNormal the_test[] = {
|
||||||
{ Tuple::Point(0, 1, 0), Tuple::Vector(0, -1, 0)},
|
{ Tuple::Point(0, 1, 0), Tuple::Vector(0, -1, 0)},
|
||||||
{Tuple::Point(0.5, 1, 0), Tuple::Vector(0, -1, 0)},
|
{Tuple::Point(0.5, 1, 0), Tuple::Vector(0, -1, 0)},
|
||||||
{ Tuple::Point(0, 1, 0.5), Tuple::Vector(0, -1, 0)},
|
{ Tuple::Point(0, 1, 0.5), Tuple::Vector(0, -1, 0)},
|
||||||
@@ -381,7 +343,7 @@ SCENARIO("Intersecting a cone with a ray", "[features/cones.feature]")
|
|||||||
// | point(0, 0, -5) | vector(0, 0, 1) | 5 | 5 |
|
// | point(0, 0, -5) | vector(0, 0, 1) | 5 | 5 |
|
||||||
// | point(0, 0, -5) | vector(1, 1, 1) | 8.66025 | 8.66025 |
|
// | point(0, 0, -5) | vector(1, 1, 1) | 8.66025 | 8.66025 |
|
||||||
// | point(1, 1, -5) | vector(-0.5, -1, 1) | 4.55006 | 49.44994 |
|
// | point(1, 1, -5) | vector(-0.5, -1, 1) | 4.55006 | 49.44994 |
|
||||||
CylinderTestIntersect the_test[] = {
|
DataOrigDirT0T1 the_test[] = {
|
||||||
{Tuple::Point(0, 0, -5), Tuple::Vector(0, 0, 1), 5, 5},
|
{Tuple::Point(0, 0, -5), Tuple::Vector(0, 0, 1), 5, 5},
|
||||||
{Tuple::Point(0, 0, -5), Tuple::Vector(1, 1, 1), 8.66025, 8.66025},
|
{Tuple::Point(0, 0, -5), Tuple::Vector(1, 1, 1), 8.66025, 8.66025},
|
||||||
{Tuple::Point(1, 1, -5), Tuple::Vector(-0.5, -1, 1), 4.55006, 49.44994}
|
{Tuple::Point(1, 1, -5), Tuple::Vector(-0.5, -1, 1), 4.55006, 49.44994}
|
||||||
@@ -458,7 +420,7 @@ SCENARIO("Intersecting a cone's end caps", "[features/cones.feature]")
|
|||||||
// | point(0, 0, -0.25) | vector(0, 1, 1) | 2 |
|
// | point(0, 0, -0.25) | vector(0, 1, 1) | 2 |
|
||||||
// | point(0, 0, -0.25) | vector(0, 1, 0) | 4 |
|
// | point(0, 0, -0.25) | vector(0, 1, 0) | 4 |
|
||||||
|
|
||||||
ConeTestConstrained the_test[] = {
|
DataOrigDirCount the_test[] = {
|
||||||
{Tuple::Point(0, 0, -5), Tuple::Vector(0, 1, 0), 0},
|
{Tuple::Point(0, 0, -5), Tuple::Vector(0, 1, 0), 0},
|
||||||
{Tuple::Point(0, 0, -0.25), Tuple::Vector(0, 1, 1), 2},
|
{Tuple::Point(0, 0, -0.25), Tuple::Vector(0, 1, 1), 2},
|
||||||
{Tuple::Point(0, 0, -0.25), Tuple::Vector(0, 1, 0), 4}
|
{Tuple::Point(0, 0, -0.25), Tuple::Vector(0, 1, 0), 4}
|
||||||
@@ -508,7 +470,7 @@ SCENARIO("Computing the normal vector on a cone", "[features/cones.feature]")
|
|||||||
// | point(0, 0, 0) | vector(0, 0, 0) |
|
// | point(0, 0, 0) | vector(0, 0, 0) |
|
||||||
// | point(1, 1, 1) | vector(1, -sqrt(2), 1) |
|
// | point(1, 1, 1) | vector(1, -sqrt(2), 1) |
|
||||||
// | point(-1, -1, 0) | vector(-1, 1, 0) |
|
// | point(-1, -1, 0) | vector(-1, 1, 0) |
|
||||||
CylinderTestNormal the_test[] = {
|
DataPointNormal the_test[] = {
|
||||||
{ Tuple::Point(0, 0, 0), Tuple::Vector(0, 0, 0)},
|
{ Tuple::Point(0, 0, 0), Tuple::Vector(0, 0, 0)},
|
||||||
{ Tuple::Point(1, 1, 1), Tuple::Vector(1, -sqrt(2), 1)},
|
{ Tuple::Point(1, 1, 1), Tuple::Vector(1, -sqrt(2), 1)},
|
||||||
{Tuple::Point(-1, -1, 0), Tuple::Vector(-1, 1, 0)}
|
{Tuple::Point(-1, -1, 0), Tuple::Vector(-1, 1, 0)}
|
||||||
|
|||||||
66
tests/14_groups.cpp
Normal file
66
tests/14_groups.cpp
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
/*!
|
||||||
|
* 14_groups.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: 21/03/2024
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
|
||||||
|
#include "raytracing.h"
|
||||||
|
|
||||||
|
#include "common_data.h"
|
||||||
|
|
||||||
|
using namespace Raytracer;
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
SCENARIO("Creating a new group", "[features/groups.feature]")
|
||||||
|
{
|
||||||
|
GIVEN("g <- group()")
|
||||||
|
{
|
||||||
|
Group g;
|
||||||
|
THEN("g.transform = identity_matrix")
|
||||||
|
{
|
||||||
|
REQUIRE(g.transform() == Matrix::identity());
|
||||||
|
}
|
||||||
|
AND_THEN("g is empty")
|
||||||
|
{
|
||||||
|
REQUIRE(g.is_empty() == true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
SCENARIO("A shape has a parent attribute", "[features/shapes.feature]")
|
||||||
|
{
|
||||||
|
GIVEN("s <- test_shape()")
|
||||||
|
{
|
||||||
|
TestShape s;
|
||||||
|
THEN("s.parent is nothing")
|
||||||
|
{
|
||||||
|
REQUIRE(s.parent() == nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|||||||
add_executable(raytracing_test
|
add_executable(raytracing_test
|
||||||
main_test.cpp
|
main_test.cpp
|
||||||
|
|
||||||
|
00_common_data.cpp
|
||||||
01_tuples.cpp
|
01_tuples.cpp
|
||||||
02_1_colors.cpp
|
02_1_colors.cpp
|
||||||
02_2_canvas.cpp
|
02_2_canvas.cpp
|
||||||
@@ -26,6 +27,7 @@ add_executable(raytracing_test
|
|||||||
11_reflection_refraction.cpp
|
11_reflection_refraction.cpp
|
||||||
12_cubes.cpp
|
12_cubes.cpp
|
||||||
13_cylinders.cpp
|
13_cylinders.cpp
|
||||||
|
14_groups.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
include_directories("${CMAKE_SOURCE_DIR}/tests")
|
include_directories("${CMAKE_SOURCE_DIR}/tests")
|
||||||
|
|||||||
114
tests/common_data.h
Normal file
114
tests/common_data.h
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
/*!
|
||||||
|
* sphere.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: 22/03/2024
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _RAYTRACER_COMMON_DATA_H
|
||||||
|
#define _RAYTRACER_COMMON_DATA_H
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#include <core/tuple.h>
|
||||||
|
#include <patterns/pattern.h>
|
||||||
|
#include <shapes/shape.h>
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
namespace Raytracer
|
||||||
|
{
|
||||||
|
class TestShape : public Shape
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TestShape(void) = default;
|
||||||
|
|
||||||
|
Intersections local_intersect(const Ray &a_ray) override;
|
||||||
|
|
||||||
|
Tuple local_normal_at(const Tuple &a_local_point) const override;
|
||||||
|
|
||||||
|
Ray saved_ray;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
class TestPattern : public Pattern
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TestPattern(void) = default;
|
||||||
|
|
||||||
|
const Color pattern_at(const Tuple &a_point) const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
class DataOrigDirT1T2
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Tuple origin;
|
||||||
|
Tuple direction;
|
||||||
|
double t1;
|
||||||
|
double t2;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
class DataOrigDirT0T1
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Tuple origin;
|
||||||
|
Tuple direction;
|
||||||
|
double t0 = -1;
|
||||||
|
double t1 = -1;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
class DataPointNormal
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Tuple point;
|
||||||
|
Tuple normal;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
class DataPointDirCount
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Tuple point;
|
||||||
|
Tuple direction;
|
||||||
|
uint16_t count;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
class DataOrigDirCount
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Tuple origin;
|
||||||
|
Tuple direction;
|
||||||
|
uint16_t count;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Raytracer
|
||||||
|
|
||||||
|
#endif // _RAYTRACER_COMMON_DATA_H
|
||||||
Reference in New Issue
Block a user