Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5ebed12f4f | ||
|
|
73d60fb7e4 | ||
|
|
4a9379c0b2 | ||
|
|
aeb4669162 | ||
|
|
a8194169c5 | ||
|
|
656ff52204 | ||
|
|
00b283053e | ||
|
|
b799e5f819 | ||
|
|
cabe7ff147 | ||
|
|
17aebe6538 | ||
|
|
a1087a9871 | ||
|
|
c4418683c6 | ||
|
|
1900d1f45d | ||
|
|
513cd9d7eb | ||
|
|
01a0de09ab | ||
|
|
8faf1db3be | ||
|
|
79af9fbc97 | ||
|
|
1e2588441f | ||
|
|
1f4b14c896 |
2
external/glfw
vendored
2
external/glfw
vendored
Submodule external/glfw updated: 76406c7894...6aca3e99f0
2
external/googletest
vendored
2
external/googletest
vendored
Submodule external/googletest updated: 41b5f149ab...23b2a3b1cf
2
external/lodepng
vendored
2
external/lodepng
vendored
Submodule external/lodepng updated: 5a0dba1038...48e5364ef4
@@ -3,8 +3,13 @@
|
|||||||
# First most is build as a library
|
# First most is build as a library
|
||||||
add_library(rayonnement STATIC)
|
add_library(rayonnement STATIC)
|
||||||
|
|
||||||
set(RAY_HEADERS include/tuples.h include/math_helper.h include/colour.h include/canvas.h include/matrix.h include/transformation.h)
|
set(RAY_HEADERS include/tuple.h include/math_helper.h include/colour.h include/canvas.h
|
||||||
set(RAY_SOURCES tuples.cpp math_helper.cpp colour.cpp canvas.cpp matrix.cpp transformation.cpp)
|
include/matrix.h include/transformation.h include/intersect.h include/intersection.h
|
||||||
|
include/light.h include/material.h
|
||||||
|
include/object.h include/ray.h include/sphere.h)
|
||||||
|
set(RAY_SOURCES tuple.cpp math_helper.cpp colour.cpp canvas.cpp matrix.cpp transformation.cpp intersect.cpp
|
||||||
|
objects/light.cpp objects/material.cpp
|
||||||
|
objects/object.cpp objects/ray.cpp objects/sphere.cpp)
|
||||||
|
|
||||||
target_include_directories(rayonnement PUBLIC include)
|
target_include_directories(rayonnement PUBLIC include)
|
||||||
target_sources(rayonnement PRIVATE ${RAY_HEADERS} ${RAY_SOURCES})
|
target_sources(rayonnement PRIVATE ${RAY_HEADERS} ${RAY_SOURCES})
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#ifndef DORAYME_COLOUR_H
|
#ifndef DORAYME_COLOUR_H
|
||||||
#define DORAYME_COLOUR_H
|
#define DORAYME_COLOUR_H
|
||||||
|
|
||||||
#include <tuples.h>
|
#include <tuple.h>
|
||||||
|
|
||||||
class Colour : public Tuple
|
class Colour : public Tuple
|
||||||
{
|
{
|
||||||
|
|||||||
29
source/include/intersect.h
Normal file
29
source/include/intersect.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* DoRayMe - a quick and dirty Raytracer
|
||||||
|
* Intersect header
|
||||||
|
*
|
||||||
|
* Created by Manoël Trapier
|
||||||
|
* Copyright (c) 2020 986-Studio.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef DORAYME_INTERSECT_H
|
||||||
|
#define DORAYME_INTERSECT_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <intersection.h>
|
||||||
|
|
||||||
|
class Intersect
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
Intersection *list;
|
||||||
|
uint32_t num;
|
||||||
|
uint32_t allocated;
|
||||||
|
public:
|
||||||
|
Intersect();
|
||||||
|
void add(Intersection i);
|
||||||
|
int count() { return this->num; };
|
||||||
|
Intersection operator[](const int p) { return this->list[p]; }
|
||||||
|
Intersection hit();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //DORAYME_INTERSECT_H
|
||||||
29
source/include/intersection.h
Normal file
29
source/include/intersection.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* DoRayMe - a quick and dirty Raytracer
|
||||||
|
* Intersection header
|
||||||
|
*
|
||||||
|
* Created by Manoël Trapier
|
||||||
|
* Copyright (c) 2020 986-Studio.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef DORAYME_INTERSECTION_H
|
||||||
|
#define DORAYME_INTERSECTION_H
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
class Object;
|
||||||
|
|
||||||
|
class Intersection
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
double t;
|
||||||
|
Object *object;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Intersection(double t, Object *object) : t(t), object(object) { };
|
||||||
|
bool nothing() { return (this->object == nullptr); };
|
||||||
|
|
||||||
|
bool operator==(const Intersection &b) const { return ((this->t == b.t) && (this->object == b.object)); };
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //DORAYME_INTERSECTION_H
|
||||||
32
source/include/light.h
Normal file
32
source/include/light.h
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* DoRayMe - a quick and dirty Raytracer
|
||||||
|
* Light header
|
||||||
|
*
|
||||||
|
* Created by Manoël Trapier
|
||||||
|
* Copyright (c) 2020 986-Studio.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef DORAYME_LIGHT_H
|
||||||
|
#define DORAYME_LIGHT_H
|
||||||
|
|
||||||
|
#include <tuple.h>
|
||||||
|
#include <colour.h>
|
||||||
|
|
||||||
|
enum LightType
|
||||||
|
{
|
||||||
|
POINT_LIGHT = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
class Light
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Colour intensity;
|
||||||
|
Tuple position;
|
||||||
|
LightType type;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Light(LightType type = POINT_LIGHT, Tuple position=Point(0, 0, 0),
|
||||||
|
Colour intensity=Colour(1, 1, 1)) : type(type), position(position), intensity(intensity) { };
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //DORAYME_LIGHT_H
|
||||||
37
source/include/material.h
Normal file
37
source/include/material.h
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* DoRayMe - a quick and dirty Raytracer
|
||||||
|
* Material header
|
||||||
|
*
|
||||||
|
* Created by Manoël Trapier
|
||||||
|
* Copyright (c) 2020 986-Studio.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef DORAYME_MATERIAL_H
|
||||||
|
#define DORAYME_MATERIAL_H
|
||||||
|
|
||||||
|
#include <tuple.h>
|
||||||
|
#include <colour.h>
|
||||||
|
#include <light.h>
|
||||||
|
|
||||||
|
class Material
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Colour colour;
|
||||||
|
double ambient;
|
||||||
|
double diffuse;
|
||||||
|
double specular;
|
||||||
|
double shininess;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Material() : colour(Colour(1, 1, 1)), ambient(0.1), diffuse(0.9), specular(0.9), shininess(200) {};
|
||||||
|
|
||||||
|
Colour lighting(Light light, Tuple point, Tuple eyeVector, Tuple normalVector);
|
||||||
|
|
||||||
|
bool operator==(const Material &b) const { return double_equal(this->ambient, b.ambient) &&
|
||||||
|
double_equal(this->diffuse, b.diffuse) &&
|
||||||
|
double_equal(this->specular, b.specular) &&
|
||||||
|
double_equal(this->shininess, b.shininess) &&
|
||||||
|
(this->colour == b.colour); };
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //DORAYME_MATERIAL_H
|
||||||
@@ -10,7 +10,11 @@
|
|||||||
#ifndef DORAYME_MATH_HELPER_H
|
#ifndef DORAYME_MATH_HELPER_H
|
||||||
#define DORAYME_MATH_HELPER_H
|
#define DORAYME_MATH_HELPER_H
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
void set_equal_precision(double v);
|
void set_equal_precision(double v);
|
||||||
bool double_equal(double a, double b);
|
bool double_equal(double a, double b);
|
||||||
|
|
||||||
|
double deg_to_rad(double deg);
|
||||||
|
|
||||||
#endif //DORAYME_MATH_HELPER_H
|
#endif //DORAYME_MATH_HELPER_H
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#ifndef DORAYME_MATRIX_H
|
#ifndef DORAYME_MATRIX_H
|
||||||
#define DORAYME_MATRIX_H
|
#define DORAYME_MATRIX_H
|
||||||
|
|
||||||
#include <tuples.h>
|
#include <tuple.h>
|
||||||
|
|
||||||
class Matrix
|
class Matrix
|
||||||
{
|
{
|
||||||
@@ -19,7 +19,7 @@ protected:
|
|||||||
int size;
|
int size;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Matrix(int size);
|
Matrix(int size = 4);
|
||||||
Matrix(double values[], int size);
|
Matrix(double values[], int size);
|
||||||
|
|
||||||
double get(int x, int y) const { return this->data[this->size * x + y]; };
|
double get(int x, int y) const { return this->data[this->size * x + y]; };
|
||||||
|
|||||||
40
source/include/object.h
Normal file
40
source/include/object.h
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* DoRayMe - a quick and dirty Raytracer
|
||||||
|
* Object header
|
||||||
|
*
|
||||||
|
* Created by Manoël Trapier
|
||||||
|
* Copyright (c) 2020 986-Studio.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef DORAYME_OBJECT_H
|
||||||
|
#define DORAYME_OBJECT_H
|
||||||
|
|
||||||
|
class Object;
|
||||||
|
|
||||||
|
#include <ray.h>
|
||||||
|
#include <tuple.h>
|
||||||
|
#include <matrix.h>
|
||||||
|
#include <intersect.h>
|
||||||
|
#include <material.h>
|
||||||
|
|
||||||
|
/* Base class for all object that can be presented in the world */
|
||||||
|
class Object
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Matrix transformMatrix;
|
||||||
|
Matrix inverseTransform;
|
||||||
|
Material material;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Object();
|
||||||
|
|
||||||
|
virtual Intersect intersect(Ray r);
|
||||||
|
virtual Tuple normalAt(Tuple point);
|
||||||
|
|
||||||
|
void setTransform(Matrix transform);
|
||||||
|
void setMaterial(Material material) { this->material = material; };
|
||||||
|
Ray transform(Ray r) { return Ray(this->transformMatrix * r.origin, this->transformMatrix * r.direction); };
|
||||||
|
Ray invTransform(Ray r) { return Ray(this->inverseTransform * r.origin, this->inverseTransform * r.direction); };
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //DORAYME_OBJECT_H
|
||||||
25
source/include/ray.h
Normal file
25
source/include/ray.h
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* DoRayMe - a quick and dirty Raytracer
|
||||||
|
* Ray header
|
||||||
|
*
|
||||||
|
* Created by Manoël Trapier
|
||||||
|
* Copyright (c) 2020 986-Studio.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef DORAYME_RAY_H
|
||||||
|
#define DORAYME_RAY_H
|
||||||
|
|
||||||
|
#include <tuple.h>
|
||||||
|
|
||||||
|
class Ray
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Tuple direction;
|
||||||
|
Tuple origin;
|
||||||
|
|
||||||
|
Ray(Tuple origin, Tuple direction) : origin(origin), direction(direction) { };
|
||||||
|
|
||||||
|
Tuple position(double t) { return this->origin + this->direction * t; };
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //DORAYME_RAY_H
|
||||||
24
source/include/sphere.h
Normal file
24
source/include/sphere.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* DoRayMe - a quick and dirty Raytracer
|
||||||
|
* Sphere header
|
||||||
|
*
|
||||||
|
* Created by Manoël Trapier
|
||||||
|
* Copyright (c) 2020 986-Studio.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef DORAYME_SPHERE_H
|
||||||
|
#define DORAYME_SPHERE_H
|
||||||
|
|
||||||
|
#include <object.h>
|
||||||
|
#include <ray.h>
|
||||||
|
#include <intersect.h>
|
||||||
|
|
||||||
|
class Sphere : public Object
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/* All sphere are at (0, 0, 0) and radius 1 in the object space */
|
||||||
|
virtual Intersect intersect(Ray r);
|
||||||
|
virtual Tuple normalAt(Tuple point);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //DORAYME_SPHERE_H
|
||||||
@@ -6,8 +6,8 @@
|
|||||||
* Copyright (c) 2020 986-Studio.
|
* Copyright (c) 2020 986-Studio.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#ifndef DORAYME_TUPLES_H
|
#ifndef DORAYME_TUPLE_H
|
||||||
#define DORAYME_TUPLES_H
|
#define DORAYME_TUPLE_H
|
||||||
|
|
||||||
#include <math_helper.h>
|
#include <math_helper.h>
|
||||||
|
|
||||||
@@ -41,6 +41,8 @@ public:
|
|||||||
double magnitude();
|
double magnitude();
|
||||||
Tuple normalise();
|
Tuple normalise();
|
||||||
double dot(const Tuple &b);
|
double dot(const Tuple &b);
|
||||||
|
Tuple cross(const Tuple &b) const;
|
||||||
|
Tuple reflect(const Tuple &normal);
|
||||||
};
|
};
|
||||||
|
|
||||||
class Point: public Tuple
|
class Point: public Tuple
|
||||||
@@ -53,7 +55,6 @@ class Vector: public Tuple
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Vector(double x, double y, double z) : Tuple(x, y, z, 0.0) {};
|
Vector(double x, double y, double z) : Tuple(x, y, z, 0.0) {};
|
||||||
Vector cross(const Vector &b) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* DORAYME_TUPLES_H */
|
#endif /*DORAYME_TUPLE_H*/
|
||||||
54
source/intersect.cpp
Normal file
54
source/intersect.cpp
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* DoRayMe - a quick and dirty Raytracer
|
||||||
|
* Intersect implementation
|
||||||
|
*
|
||||||
|
* Created by Manoël Trapier
|
||||||
|
* Copyright (c) 2020 986-Studio.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <math_helper.h>
|
||||||
|
#include <intersect.h>
|
||||||
|
|
||||||
|
#include <float.h>
|
||||||
|
|
||||||
|
#define MIN_ALLOC (2)
|
||||||
|
|
||||||
|
Intersect::Intersect()
|
||||||
|
{
|
||||||
|
this->allocated = MIN_ALLOC;
|
||||||
|
this->list = (Intersection *)calloc(sizeof(Object *), MIN_ALLOC);
|
||||||
|
this->num = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Intersect::add(Intersection i)
|
||||||
|
{
|
||||||
|
if ((this->num + 1) < this->allocated)
|
||||||
|
{
|
||||||
|
this->allocated *= 2;
|
||||||
|
this->list = (Intersection *)realloc(this->list, sizeof(Object *) * this->allocated);
|
||||||
|
}
|
||||||
|
this->list[this->num++] = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
Intersection Intersect::hit()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
double minHit = DBL_MAX;
|
||||||
|
uint32_t curHit = -1;
|
||||||
|
for(i = 0; i < this->num; i++)
|
||||||
|
{
|
||||||
|
if ((this->list[i].t >= 0) && (this->list[i].t < minHit))
|
||||||
|
{
|
||||||
|
curHit = i;
|
||||||
|
minHit = this->list[i].t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (curHit == -1)
|
||||||
|
{
|
||||||
|
return Intersection(0, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this->list[curHit];
|
||||||
|
}
|
||||||
@@ -22,3 +22,8 @@ bool double_equal(double a, double b)
|
|||||||
{
|
{
|
||||||
return fabs(a - b) < current_precision;
|
return fabs(a - b) < current_precision;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double deg_to_rad(double deg)
|
||||||
|
{
|
||||||
|
return deg * M_PI / 180.;
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <matrix.h>
|
#include <matrix.h>
|
||||||
#include <tuples.h>
|
#include <tuple.h>
|
||||||
#include <math_helper.h>
|
#include <math_helper.h>
|
||||||
|
|
||||||
Matrix::Matrix(int width)
|
Matrix::Matrix(int width)
|
||||||
|
|||||||
8
source/objects/light.cpp
Normal file
8
source/objects/light.cpp
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
/*
|
||||||
|
* DoRayMe - a quick and dirty Raytracer
|
||||||
|
* Light implementation
|
||||||
|
*
|
||||||
|
* Created by Manoël Trapier
|
||||||
|
* Copyright (c) 2020 986-Studio.
|
||||||
|
*
|
||||||
|
*/
|
||||||
56
source/objects/material.cpp
Normal file
56
source/objects/material.cpp
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* DoRayMe - a quick and dirty Raytracer
|
||||||
|
* Material implementation
|
||||||
|
*
|
||||||
|
* Created by Manoël Trapier
|
||||||
|
* Copyright (c) 2020 986-Studio.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include <tuple.h>
|
||||||
|
#include <material.h>
|
||||||
|
#include <colour.h>
|
||||||
|
|
||||||
|
Colour Material::lighting(Light light, Tuple point, Tuple eyeVector, Tuple normalVector)
|
||||||
|
{
|
||||||
|
Tuple lightVector = (light.position - point).normalise();
|
||||||
|
Tuple reflectVector = Tuple(0, 0, 0, 0);
|
||||||
|
|
||||||
|
Tuple effectiveColour = this->colour * light.intensity;
|
||||||
|
Tuple ambientColour = Colour(0, 0, 0);
|
||||||
|
Tuple diffuseColour = Colour(0, 0, 0);
|
||||||
|
Tuple specularColour = Colour(0, 0, 0);
|
||||||
|
Tuple finalColour = Colour(0, 0, 0);
|
||||||
|
|
||||||
|
double lightDotNormal, reflectDotEye;
|
||||||
|
|
||||||
|
ambientColour = effectiveColour * this->ambient;
|
||||||
|
|
||||||
|
lightDotNormal = lightVector.dot(normalVector);
|
||||||
|
|
||||||
|
if (lightDotNormal < 0)
|
||||||
|
{
|
||||||
|
diffuseColour = Colour(0, 0, 0);
|
||||||
|
specularColour = Colour(0, 0, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
diffuseColour = effectiveColour * this->diffuse * lightDotNormal;
|
||||||
|
reflectVector = -lightVector.reflect(normalVector);
|
||||||
|
|
||||||
|
reflectDotEye = reflectVector.dot(eyeVector);
|
||||||
|
|
||||||
|
if (reflectDotEye < 0)
|
||||||
|
{
|
||||||
|
specularColour = Colour(0, 0, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
double factor = pow(reflectDotEye, this->shininess);
|
||||||
|
specularColour = light.intensity * this->specular * factor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
finalColour = ambientColour + diffuseColour + specularColour;
|
||||||
|
|
||||||
|
return Colour(finalColour.x, finalColour.y, finalColour.z);
|
||||||
|
}
|
||||||
36
source/objects/object.cpp
Normal file
36
source/objects/object.cpp
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* DoRayMe - a quick and dirty Raytracer
|
||||||
|
* Object implementation
|
||||||
|
*
|
||||||
|
* Created by Manoël Trapier
|
||||||
|
* Copyright (c) 2020 986-Studio.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ray.h>
|
||||||
|
#include <object.h>
|
||||||
|
#include <matrix.h>
|
||||||
|
#include <tuple.h>
|
||||||
|
#include <intersect.h>
|
||||||
|
|
||||||
|
Object::Object()
|
||||||
|
{
|
||||||
|
this->transformMatrix = Matrix4().identity();
|
||||||
|
this->inverseTransform = this->transformMatrix.inverse();
|
||||||
|
}
|
||||||
|
|
||||||
|
Intersect Object::intersect(Ray r)
|
||||||
|
{
|
||||||
|
return Intersect();
|
||||||
|
};
|
||||||
|
|
||||||
|
Tuple Object::normalAt(Tuple point)
|
||||||
|
{
|
||||||
|
return Vector(0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Object::setTransform(Matrix transform)
|
||||||
|
{
|
||||||
|
this->transformMatrix = transform;
|
||||||
|
this->inverseTransform = transform.inverse();
|
||||||
|
}
|
||||||
8
source/objects/ray.cpp
Normal file
8
source/objects/ray.cpp
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
/*
|
||||||
|
* DoRayMe - a quick and dirty Raytracer
|
||||||
|
* Ray implementation
|
||||||
|
*
|
||||||
|
* Created by Manoël Trapier
|
||||||
|
* Copyright (c) 2020 986-Studio.
|
||||||
|
*
|
||||||
|
*/
|
||||||
50
source/objects/sphere.cpp
Normal file
50
source/objects/sphere.cpp
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* DoRayMe - a quick and dirty Raytracer
|
||||||
|
* Sphere implementation
|
||||||
|
*
|
||||||
|
* Created by Manoël Trapier
|
||||||
|
* Copyright (c) 2020 986-Studio.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include <sphere.h>
|
||||||
|
#include <ray.h>
|
||||||
|
#include <tuple.h>
|
||||||
|
#include <intersect.h>
|
||||||
|
|
||||||
|
Intersect Sphere::intersect(Ray r)
|
||||||
|
{
|
||||||
|
Intersect ret;
|
||||||
|
double a, b, c, discriminant;
|
||||||
|
|
||||||
|
Ray transRay = this->invTransform(r);
|
||||||
|
|
||||||
|
Tuple sphere_to_ray = transRay.origin - Point(0, 0, 0);
|
||||||
|
|
||||||
|
a = transRay.direction.dot(transRay.direction);
|
||||||
|
b = 2 * transRay.direction.dot(sphere_to_ray);
|
||||||
|
c = sphere_to_ray.dot(sphere_to_ray) - 1;
|
||||||
|
|
||||||
|
discriminant = b * b - 4 * a * c;
|
||||||
|
|
||||||
|
if (discriminant >= 0)
|
||||||
|
{
|
||||||
|
ret.add(Intersection((-b - sqrt(discriminant)) / (2 * a), this));
|
||||||
|
ret.add(Intersection((-b + sqrt(discriminant)) / (2 * a), this));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
Tuple Sphere::normalAt(Tuple point)
|
||||||
|
{
|
||||||
|
Tuple object_point = this->inverseTransform * point;
|
||||||
|
Tuple object_normal = (object_point - Point(0, 0, 0)).normalise();
|
||||||
|
Tuple world_normal = this->inverseTransform.transpose() * object_normal;
|
||||||
|
|
||||||
|
/* W may get wrong, so hack it. This is perfectly normal as we are using a 4x4 matrix instead of a 3x3 */
|
||||||
|
world_normal.w = 0;
|
||||||
|
|
||||||
|
return world_normal.normalise();
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
* Copyright (c) 2020 986-Studio.
|
* Copyright (c) 2020 986-Studio.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include <tuples.h>
|
#include <tuple.h>
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
@@ -27,9 +27,15 @@ double Tuple::dot(const Tuple &b)
|
|||||||
return this->x * b.x + this->y * b.y + this->z * b.z + this->w * b.w;
|
return this->x * b.x + this->y * b.y + this->z * b.z + this->w * b.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector Vector::cross(const Vector &b) const
|
Tuple Tuple::cross(const Tuple &b) const
|
||||||
{
|
{
|
||||||
return Vector(this->y * b.z - this->z * b.y,
|
return Tuple(this->y * b.z - this->z * b.y,
|
||||||
this->z * b.x - this->x * b.z,
|
this->z * b.x - this->x * b.z,
|
||||||
this->x * b.y - this->y * b.x);
|
this->x * b.y - this->y * b.x,
|
||||||
|
0);
|
||||||
|
}
|
||||||
|
|
||||||
|
Tuple Tuple::reflect(const Tuple &normal)
|
||||||
|
{
|
||||||
|
return *this - normal * 2 * this->dot(normal);
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,8 @@ project(DoRayTested)
|
|||||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
|
|
||||||
set(TESTS_SRC tuples_test.cpp colour_test.cpp canvas_test.cpp matrix_test.cpp transformation_test.cpp)
|
set(TESTS_SRC tuple_test.cpp colour_test.cpp canvas_test.cpp matrix_test.cpp transformation_test.cpp ray_test.cpp
|
||||||
|
intersect_test.cpp sphere_test.cpp light_test.cpp material_test.cpp)
|
||||||
|
|
||||||
add_executable(testMyRays)
|
add_executable(testMyRays)
|
||||||
target_include_directories(testMyRays PUBLIC ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
|
target_include_directories(testMyRays PUBLIC ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
|
||||||
@@ -15,3 +16,9 @@ gtest_discover_tests(testMyRays
|
|||||||
WORKING_DIRECTORY ${PROJECT_DIR}
|
WORKING_DIRECTORY ${PROJECT_DIR}
|
||||||
PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_DIR}"
|
PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_DIR}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
add_executable(ch5_test)
|
||||||
|
target_include_directories(ch5_test PUBLIC ../source/include)
|
||||||
|
target_sources(ch5_test PRIVATE ch5_test.cpp)
|
||||||
|
target_link_libraries(ch5_test rayonnement)
|
||||||
46
tests/ch5_test.cpp
Normal file
46
tests/ch5_test.cpp
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* DoRayMe - a quick and dirty Raytracer
|
||||||
|
* Render test for chapter 5 "Put it together".
|
||||||
|
*
|
||||||
|
* Created by Manoël Trapier
|
||||||
|
* Copyright (c) 2020 986-Studio.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include <ray.h>
|
||||||
|
#include <sphere.h>
|
||||||
|
#include <colour.h>
|
||||||
|
#include <canvas.h>
|
||||||
|
#include <transformation.h>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int x, y;
|
||||||
|
Canvas c = Canvas(100, 100);
|
||||||
|
|
||||||
|
Sphere s = Sphere();
|
||||||
|
Colour red = Colour(1, 0, 0);
|
||||||
|
|
||||||
|
Point cameraOrigin = Point(0, 0, -5);
|
||||||
|
double wallDistance = 10;
|
||||||
|
double wallSize = 7;
|
||||||
|
double pixelSize = wallSize / c.width;
|
||||||
|
for(y = 0; y < c.height; y++)
|
||||||
|
{
|
||||||
|
double worldY = (wallSize / 2) - pixelSize * y;
|
||||||
|
for(x = 0; x < c.width; x++)
|
||||||
|
{
|
||||||
|
double worldX = -(wallSize / 2) + pixelSize * x;
|
||||||
|
Point position = Point(worldX, worldY, wallDistance);
|
||||||
|
Ray r = Ray(cameraOrigin, (position - cameraOrigin).normalise());
|
||||||
|
Intersect xs = s.intersect(r);
|
||||||
|
|
||||||
|
if (!xs.hit().nothing())
|
||||||
|
{
|
||||||
|
c.put_pixel(x, y, red);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c.SaveAsPNG("ch5_test.png");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
132
tests/intersect_test.cpp
Normal file
132
tests/intersect_test.cpp
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
/*
|
||||||
|
* DoRayMe - a quick and dirty Raytracer
|
||||||
|
* Intersect unit tests
|
||||||
|
*
|
||||||
|
* Created by Manoël Trapier
|
||||||
|
* Copyright (c) 2020 986-Studio.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include <intersect.h>
|
||||||
|
#include <sphere.h>
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
|
||||||
|
TEST(IntersectTest, Creating_an_intersect_and_do_some_check)
|
||||||
|
{
|
||||||
|
Intersect i;
|
||||||
|
|
||||||
|
ASSERT_EQ(i.count(), 0);
|
||||||
|
|
||||||
|
i.add(Intersection(1.0, nullptr));
|
||||||
|
i.add(Intersection(4.2, nullptr));
|
||||||
|
|
||||||
|
ASSERT_EQ(i.count(), 2);
|
||||||
|
|
||||||
|
ASSERT_EQ(i[0].t, 1.0);
|
||||||
|
ASSERT_EQ(i[1].t, 4.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IntersectTest, An_intersection_encapsulate_t_and_object)
|
||||||
|
{
|
||||||
|
Sphere s = Sphere();
|
||||||
|
Intersection i = Intersection(3.5, &s);
|
||||||
|
|
||||||
|
ASSERT_EQ(i.t, 3.5);
|
||||||
|
ASSERT_EQ(i.object, (Object *)&s);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IntersectTest, Aggregating_intersections)
|
||||||
|
{
|
||||||
|
Sphere s = Sphere();
|
||||||
|
Intersection i1 = Intersection(1, &s);
|
||||||
|
Intersection i2 = Intersection(2, &s);
|
||||||
|
|
||||||
|
Intersect xs = Intersect();
|
||||||
|
xs.add(i1);
|
||||||
|
xs.add(i2);
|
||||||
|
|
||||||
|
ASSERT_EQ(xs.count(), 2);
|
||||||
|
ASSERT_EQ(xs[0].t, 1);
|
||||||
|
ASSERT_EQ(xs[1].t, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IntersectTest, Intersect_sets_the_object_on_the_intersection)
|
||||||
|
{
|
||||||
|
Ray r = Ray(Point(0, 0, -5), Vector(0, 0, 1));
|
||||||
|
Sphere s = Sphere();
|
||||||
|
Intersect xs = s.intersect(r);
|
||||||
|
|
||||||
|
ASSERT_EQ(xs.count(), 2);
|
||||||
|
ASSERT_EQ(xs[0].object, (Object *)&s);
|
||||||
|
ASSERT_EQ(xs[1].object, (Object *)&s);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IntersectTest, The_hit_when_all_intersection_have_positive_t)
|
||||||
|
{
|
||||||
|
Sphere s = Sphere();
|
||||||
|
Intersect xs = Intersect();
|
||||||
|
|
||||||
|
Intersection i1 = Intersection(1, &s);
|
||||||
|
Intersection i2 = Intersection(2, &s);
|
||||||
|
|
||||||
|
xs.add(i1);
|
||||||
|
xs.add(i2);
|
||||||
|
|
||||||
|
Intersection i = xs.hit();
|
||||||
|
|
||||||
|
ASSERT_EQ(i, i1);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IntersectTest, The_hit_when_some_intersection_have_negative_t)
|
||||||
|
{
|
||||||
|
Sphere s = Sphere();
|
||||||
|
Intersect xs = Intersect();
|
||||||
|
|
||||||
|
Intersection i1 = Intersection(-1, &s);
|
||||||
|
Intersection i2 = Intersection(2, &s);
|
||||||
|
Intersection i3 = Intersection(12, &s);
|
||||||
|
|
||||||
|
xs.add(i1);
|
||||||
|
xs.add(i2);
|
||||||
|
xs.add(i3);
|
||||||
|
|
||||||
|
Intersection i = xs.hit();
|
||||||
|
|
||||||
|
ASSERT_EQ(i, i2);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IntersectTest, The_hit_when_all_intersection_have_negative_t)
|
||||||
|
{
|
||||||
|
Sphere s = Sphere();
|
||||||
|
Intersect xs = Intersect();
|
||||||
|
|
||||||
|
Intersection i1 = Intersection(-2, &s);
|
||||||
|
Intersection i2 = Intersection(-1, &s);
|
||||||
|
|
||||||
|
xs.add(i1);
|
||||||
|
xs.add(i2);
|
||||||
|
|
||||||
|
Intersection i = xs.hit();
|
||||||
|
|
||||||
|
ASSERT_TRUE(i.nothing());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(IntersectTest, The_hit_is_always_the_lowest_nonnegative_intersection)
|
||||||
|
{
|
||||||
|
Sphere s = Sphere();
|
||||||
|
Intersect xs = Intersect();
|
||||||
|
|
||||||
|
Intersection i1 = Intersection(5, &s);
|
||||||
|
Intersection i2 = Intersection(7, &s);
|
||||||
|
Intersection i3 = Intersection(-3, &s);
|
||||||
|
Intersection i4 = Intersection(2, &s);
|
||||||
|
|
||||||
|
xs.add(i1);
|
||||||
|
xs.add(i2);
|
||||||
|
xs.add(i3);
|
||||||
|
xs.add(i4);
|
||||||
|
|
||||||
|
Intersection i = xs.hit();
|
||||||
|
|
||||||
|
ASSERT_EQ(i, i4);
|
||||||
|
}
|
||||||
24
tests/light_test.cpp
Normal file
24
tests/light_test.cpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* DoRayMe - a quick and dirty Raytracer
|
||||||
|
* Light unit tests
|
||||||
|
*
|
||||||
|
* Created by Manoël Trapier
|
||||||
|
* Copyright (c) 2020 986-Studio.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include <light.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <colour.h>
|
||||||
|
#include <tuple.h>
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
TEST(LightTest, A_point_lighthas_a_position_and_intensity)
|
||||||
|
{
|
||||||
|
Colour intensity = Colour(1, 1, 1);
|
||||||
|
Point position = Point(0, 0, 0);
|
||||||
|
|
||||||
|
Light light = Light(POINT_LIGHT, position, intensity);
|
||||||
|
|
||||||
|
ASSERT_EQ(light.position, position);
|
||||||
|
ASSERT_EQ(light.intensity, intensity);
|
||||||
|
}
|
||||||
90
tests/material_test.cpp
Normal file
90
tests/material_test.cpp
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* DoRayMe - a quick and dirty Raytracer
|
||||||
|
* Material unit tests
|
||||||
|
*
|
||||||
|
* Created by Manoël Trapier
|
||||||
|
* Copyright (c) 2020 986-Studio.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include <material.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <colour.h>
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
TEST(MaterialTest, The_default_material)
|
||||||
|
{
|
||||||
|
Material m = Material();
|
||||||
|
|
||||||
|
ASSERT_EQ(m.colour, Colour(1, 1, 1));
|
||||||
|
ASSERT_EQ(m.ambient, 0.1);
|
||||||
|
ASSERT_EQ(m.diffuse, 0.9);
|
||||||
|
ASSERT_EQ(m.specular, 0.9);
|
||||||
|
ASSERT_EQ(m.shininess, 200.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is used by the next tests
|
||||||
|
static Material m = Material();
|
||||||
|
static Point position = Point(0, 0, 0);
|
||||||
|
|
||||||
|
TEST(MaterialTest, Lighting_with_the_eye_between_the_light_and_the_surface)
|
||||||
|
{
|
||||||
|
Vector eyev = Vector(0, 0, -1);
|
||||||
|
Vector normalv = Vector(0, 0, -1);
|
||||||
|
Light light = Light(POINT_LIGHT, Point(0, 0, -10), Colour(1, 1, 1));
|
||||||
|
|
||||||
|
Colour result = m.lighting(light, position, eyev, normalv);
|
||||||
|
|
||||||
|
ASSERT_EQ(result, Colour(1.9, 1.9, 1.9));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(MaterialTest, Lighting_with_the_eye_between_the_light_and_the_surface_eye_offset_by_45)
|
||||||
|
{
|
||||||
|
Vector eyev = Vector(0, -sqrt(2)/2, -sqrt(2)/2);
|
||||||
|
Vector normalv = Vector(0, 0, -1);
|
||||||
|
Light light = Light(POINT_LIGHT, Point(0, 0, -10), Colour(1, 1, 1));
|
||||||
|
|
||||||
|
Colour result = m.lighting(light, position, eyev, normalv);
|
||||||
|
|
||||||
|
ASSERT_EQ(result, Colour(1.0, 1.0, 1.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(MaterialTest, Lighting_with_the_eye_opposite_surface_light_offset_45)
|
||||||
|
{
|
||||||
|
Vector eyev = Vector(0, 0, -1);
|
||||||
|
Vector normalv = Vector(0, 0, -1);
|
||||||
|
Light light = Light(POINT_LIGHT, Point(0, 10, -10), Colour(1, 1, 1));
|
||||||
|
|
||||||
|
Colour result = m.lighting(light, position, eyev, normalv);
|
||||||
|
|
||||||
|
set_equal_precision(0.0001);
|
||||||
|
|
||||||
|
ASSERT_EQ(result, Colour(0.7364, 0.7364, 0.7364));
|
||||||
|
|
||||||
|
set_equal_precision(FLT_EPSILON);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(MaterialTest, Lighting_with_the_eye_in_the_path_of_the_reflection_vector)
|
||||||
|
{
|
||||||
|
Vector eyev = Vector(0, -sqrt(2)/2, -sqrt(2)/2);
|
||||||
|
Vector normalv = Vector(0, 0, -1);
|
||||||
|
Light light = Light(POINT_LIGHT, Point(0, 10, -10), Colour(1, 1, 1));
|
||||||
|
|
||||||
|
Colour result = m.lighting(light, position, eyev, normalv);
|
||||||
|
|
||||||
|
set_equal_precision(0.0001);
|
||||||
|
|
||||||
|
ASSERT_EQ(result, Colour(1.6364, 1.6364, 1.6364));
|
||||||
|
|
||||||
|
set_equal_precision(FLT_EPSILON);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(MaterialTest, Lighting_with_the_light_behind_the_surface)
|
||||||
|
{
|
||||||
|
Vector eyev = Vector(0, 0, -1);
|
||||||
|
Vector normalv = Vector(0, 0, -1);
|
||||||
|
Light light = Light(POINT_LIGHT, Point(0, 0, 10), Colour(1, 1, 1));
|
||||||
|
|
||||||
|
Colour result = m.lighting(light, position, eyev, normalv);
|
||||||
|
|
||||||
|
ASSERT_EQ(result, Colour(0.1, 0.1, 0.1));
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include <matrix.h>
|
#include <matrix.h>
|
||||||
#include <tuples.h>
|
#include <tuple.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
|||||||
64
tests/ray_test.cpp
Normal file
64
tests/ray_test.cpp
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* DoRayMe - a quick and dirty Raytracer
|
||||||
|
* Ray unit tests
|
||||||
|
*
|
||||||
|
* Created by Manoël Trapier
|
||||||
|
* Copyright (c) 2020 986-Studio.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include <ray.h>
|
||||||
|
#include <transformation.h>
|
||||||
|
#include <object.h>
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
|
||||||
|
TEST(RayTest, Creating_a_ray_and_querying_it)
|
||||||
|
{
|
||||||
|
Point origin = Point(1, 2, 3);
|
||||||
|
Vector direction = Vector(4, 5, 6);
|
||||||
|
|
||||||
|
Ray r = Ray(origin, direction);
|
||||||
|
|
||||||
|
ASSERT_EQ(r.origin, origin);
|
||||||
|
ASSERT_EQ(r.direction, direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(RayTest, Computing_a_point_from_a_distance)
|
||||||
|
{
|
||||||
|
Ray r = Ray(Point(2, 3, 4), Vector(1, 0, 0));
|
||||||
|
|
||||||
|
ASSERT_EQ(r.position(0), Point(2, 3, 4));
|
||||||
|
ASSERT_EQ(r.position(1), Point(3, 3, 4));
|
||||||
|
ASSERT_EQ(r.position(-1), Point(1, 3, 4));
|
||||||
|
ASSERT_EQ(r.position(2.5), Point(4.5, 3, 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(RayTest, Translating_a_ray)
|
||||||
|
{
|
||||||
|
Ray r = Ray(Point(1, 2, 3), Vector(0, 1, 0));
|
||||||
|
|
||||||
|
Matrix m = translation(3, 4, 5);
|
||||||
|
Object o = Object();
|
||||||
|
|
||||||
|
o.setTransform(m);
|
||||||
|
|
||||||
|
Ray r2 = o.transform(r);
|
||||||
|
|
||||||
|
ASSERT_EQ(r2.origin, Point(4, 6, 8));
|
||||||
|
ASSERT_EQ(r2.direction, Vector(0, 1, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(RayTest, Scaling_a_ray)
|
||||||
|
{
|
||||||
|
Ray r = Ray(Point(1, 2, 3), Vector(0, 1, 0));
|
||||||
|
|
||||||
|
Matrix m = scaling(2, 3, 4);
|
||||||
|
Object o = Object();
|
||||||
|
|
||||||
|
o.setTransform(m);
|
||||||
|
|
||||||
|
Ray r2 = o.transform(r);
|
||||||
|
|
||||||
|
ASSERT_EQ(r2.origin, Point(2, 6, 12));
|
||||||
|
ASSERT_EQ(r2.direction, Vector(0, 3, 0));
|
||||||
|
}
|
||||||
201
tests/sphere_test.cpp
Normal file
201
tests/sphere_test.cpp
Normal file
@@ -0,0 +1,201 @@
|
|||||||
|
/*
|
||||||
|
* DoRayMe - a quick and dirty Raytracer
|
||||||
|
* Sphere unit tests
|
||||||
|
*
|
||||||
|
* Created by Manoël Trapier
|
||||||
|
* Copyright (c) 2020 986-Studio.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include <ray.h>
|
||||||
|
#include <sphere.h>
|
||||||
|
#include <material.h>
|
||||||
|
#include <transformation.h>
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
|
||||||
|
TEST(SphereTest, A_ray_intersect_a_sphere_at_two_points)
|
||||||
|
{
|
||||||
|
Ray r = Ray(Point(0, 0, -5), Vector(0, 0, 1));
|
||||||
|
Sphere s = Sphere();
|
||||||
|
Intersect xs = s.intersect(r);
|
||||||
|
|
||||||
|
ASSERT_EQ(xs.count(), 2);
|
||||||
|
ASSERT_EQ(xs[0].t, 4.0);
|
||||||
|
ASSERT_EQ(xs[1].t, 6.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SphereTest, A_ray_intersect_a_sphere_at_a_tangent)
|
||||||
|
{
|
||||||
|
Ray r = Ray(Point(0, 1, -5), Vector(0, 0, 1));
|
||||||
|
Sphere s = Sphere();
|
||||||
|
Intersect xs = s.intersect(r);
|
||||||
|
|
||||||
|
ASSERT_EQ(xs.count(), 2);
|
||||||
|
ASSERT_EQ(xs[0].t, 5.0);
|
||||||
|
ASSERT_EQ(xs[1].t, 5.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SphereTest, A_ray_miss_a_sphere)
|
||||||
|
{
|
||||||
|
Ray r = Ray(Point(0, 2, -5), Vector(0, 0, 1));
|
||||||
|
Sphere s = Sphere();
|
||||||
|
Intersect xs = s.intersect(r);
|
||||||
|
|
||||||
|
ASSERT_EQ(xs.count(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SphereTest, A_ray_originate_inside_a_sphere)
|
||||||
|
{
|
||||||
|
Ray r = Ray(Point(0, 0, 0), Vector(0, 0, 1));
|
||||||
|
Sphere s = Sphere();
|
||||||
|
Intersect xs = s.intersect(r);
|
||||||
|
|
||||||
|
ASSERT_EQ(xs.count(), 2);
|
||||||
|
ASSERT_EQ(xs[0].t, -1.0);
|
||||||
|
ASSERT_EQ(xs[1].t, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SphereTest, A_sphere_is_behind_a_ray)
|
||||||
|
{
|
||||||
|
Ray r = Ray(Point(0, 0, 5), Vector(0, 0, 1));
|
||||||
|
Sphere s = Sphere();
|
||||||
|
Intersect xs = s.intersect(r);
|
||||||
|
|
||||||
|
ASSERT_EQ(xs.count(), 2);
|
||||||
|
ASSERT_EQ(xs[0].t, -6.0);
|
||||||
|
ASSERT_EQ(xs[1].t, -4.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SphereTest, A_sphere_default_transformation)
|
||||||
|
{
|
||||||
|
Sphere s = Sphere();
|
||||||
|
ASSERT_EQ(s.transformMatrix, Matrix4().identity());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SphereTest, Changing_a_sphere_transformation)
|
||||||
|
{
|
||||||
|
Sphere s = Sphere();
|
||||||
|
Matrix t = translation(2, 3, 4);
|
||||||
|
|
||||||
|
s.setTransform(t);
|
||||||
|
|
||||||
|
ASSERT_EQ(s.transformMatrix, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SphereTest, Intersecting_a_scaled_sphere_with_a_ray)
|
||||||
|
{
|
||||||
|
Ray r = Ray(Point(0, 0, -5), Vector(0, 0, 1));
|
||||||
|
Sphere s = Sphere();
|
||||||
|
|
||||||
|
s.setTransform(scaling(2, 2, 2));
|
||||||
|
|
||||||
|
Intersect xs = s.intersect(r);
|
||||||
|
|
||||||
|
ASSERT_EQ(xs.count(), 2);
|
||||||
|
ASSERT_EQ(xs[0].t, 3.0);
|
||||||
|
ASSERT_EQ(xs[1].t, 7.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SphereTest, Intersecting_a_translated_sphere_with_a_ray)
|
||||||
|
{
|
||||||
|
Ray r = Ray(Point(0, 0, -5), Vector(0, 0, 1));
|
||||||
|
Sphere s = Sphere();
|
||||||
|
|
||||||
|
s.setTransform(translation(5, 0, 0));
|
||||||
|
|
||||||
|
Intersect xs = s.intersect(r);
|
||||||
|
|
||||||
|
ASSERT_EQ(xs.count(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SphereTest, The_normal_on_a_sphere_at_a_point_on_the_X_axis)
|
||||||
|
{
|
||||||
|
Sphere s = Sphere();
|
||||||
|
Tuple n = s.normalAt(Point(1, 0, 0));
|
||||||
|
|
||||||
|
ASSERT_EQ(n, Vector(1, 0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SphereTest, The_normal_on_a_sphere_at_a_point_on_the_Y_axis)
|
||||||
|
{
|
||||||
|
Sphere s = Sphere();
|
||||||
|
Tuple n = s.normalAt(Point(0, 1, 0));
|
||||||
|
|
||||||
|
ASSERT_EQ(n, Vector(0, 1, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SphereTest, The_normal_on_a_sphere_at_a_point_on_the_Z_axis)
|
||||||
|
{
|
||||||
|
Sphere s = Sphere();
|
||||||
|
Tuple n = s.normalAt(Point(0, 0, 1));
|
||||||
|
|
||||||
|
ASSERT_EQ(n, Vector(0, 0, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SphereTest, The_normal_on_a_sphere_at_a_nonaxial_point)
|
||||||
|
{
|
||||||
|
Sphere s = Sphere();
|
||||||
|
Tuple n = s.normalAt(Point(sqrt(3)/3, sqrt(3)/3, sqrt(3)/3));
|
||||||
|
|
||||||
|
ASSERT_EQ(n, Vector(sqrt(3)/3, sqrt(3)/3, sqrt(3)/3));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SphereTest, The_normal_is_a_normalise_vector)
|
||||||
|
{
|
||||||
|
Sphere s = Sphere();
|
||||||
|
Tuple n = s.normalAt(Point(sqrt(3)/3, sqrt(3)/3, sqrt(3)/3));
|
||||||
|
|
||||||
|
ASSERT_EQ(n, n.normalise());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SphereTest, Computing_the_normal_on_a_translated_sphere)
|
||||||
|
{
|
||||||
|
Sphere s = Sphere();
|
||||||
|
|
||||||
|
s.setTransform(translation(0, 1, 0));
|
||||||
|
|
||||||
|
Tuple n = s.normalAt(Point(0, 1.70711, -0.70711));
|
||||||
|
|
||||||
|
set_equal_precision(0.0001);
|
||||||
|
|
||||||
|
ASSERT_EQ(n, Vector(0, 0.70711, -0.70711));
|
||||||
|
|
||||||
|
/* Revert to default */
|
||||||
|
set_equal_precision(FLT_EPSILON);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SphereTest, Computing_the_normal_on_a_tranformed_sphere)
|
||||||
|
{
|
||||||
|
Sphere s = Sphere();
|
||||||
|
|
||||||
|
s.setTransform(scaling(1, 0.5, 1) * rotation_z(M_PI / 5));
|
||||||
|
|
||||||
|
Tuple n = s.normalAt(Point(0, sqrt(2)/2, -sqrt(2)/2));
|
||||||
|
|
||||||
|
set_equal_precision(0.0001);
|
||||||
|
|
||||||
|
ASSERT_EQ(n, Vector(0, 0.97014, -0.24254));
|
||||||
|
|
||||||
|
/* Revert to default */
|
||||||
|
set_equal_precision(FLT_EPSILON);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SphereTest, A_sphere_have_a_default_material)
|
||||||
|
{
|
||||||
|
Sphere s = Sphere();
|
||||||
|
Material m = Material();
|
||||||
|
|
||||||
|
ASSERT_EQ(s.material, m);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SphereTest, A_sphere_may_be_assigned_a_material)
|
||||||
|
{
|
||||||
|
Sphere s = Sphere();
|
||||||
|
|
||||||
|
Material m = Material();
|
||||||
|
m.ambient = 1;
|
||||||
|
|
||||||
|
s.setMaterial(m);
|
||||||
|
|
||||||
|
ASSERT_EQ(s.material, m);
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include <transformation.h>
|
#include <transformation.h>
|
||||||
#include <tuples.h>
|
#include <tuple.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
|||||||
@@ -6,11 +6,11 @@
|
|||||||
* Copyright (c) 2020 986-Studio.
|
* Copyright (c) 2020 986-Studio.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include <tuples.h>
|
#include <tuple.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
TEST(TuplesTests, Tuple_With_w_equal_1_and_is_point)
|
TEST(TupleTest, Tuple_With_w_equal_1_and_is_point)
|
||||||
{
|
{
|
||||||
Tuple a = Tuple(4.3, -4.2, 3.1, 1.0);
|
Tuple a = Tuple(4.3, -4.2, 3.1, 1.0);
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ TEST(TuplesTests, Tuple_With_w_equal_1_and_is_point)
|
|||||||
ASSERT_FALSE(a.isVector());
|
ASSERT_FALSE(a.isVector());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TuplesTests, Tuple_With_w_equal_0_and_is_vector)
|
TEST(TupleTest, Tuple_With_w_equal_0_and_is_vector)
|
||||||
{
|
{
|
||||||
Tuple a = Tuple(4.3, -4.2, 3.1, 0.0);
|
Tuple a = Tuple(4.3, -4.2, 3.1, 0.0);
|
||||||
|
|
||||||
@@ -34,21 +34,21 @@ TEST(TuplesTests, Tuple_With_w_equal_0_and_is_vector)
|
|||||||
ASSERT_TRUE(a.isVector());
|
ASSERT_TRUE(a.isVector());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TuplesTests, Point_create_tuples_with_w_equal_1)
|
TEST(TupleTest, Point_create_tuples_with_w_equal_1)
|
||||||
{
|
{
|
||||||
Tuple a = Point(4, -4, 3);
|
Tuple a = Point(4, -4, 3);
|
||||||
|
|
||||||
ASSERT_EQ(a, Tuple(4, -4, 3, 1));
|
ASSERT_EQ(a, Tuple(4, -4, 3, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TuplesTests, Vector_create_tuples_with_w_equal_0)
|
TEST(TupleTest, Vector_create_tuples_with_w_equal_0)
|
||||||
{
|
{
|
||||||
Tuple a = Vector(4, -4, 3);
|
Tuple a = Vector(4, -4, 3);
|
||||||
|
|
||||||
ASSERT_EQ(a, Tuple(4, -4, 3, 0));
|
ASSERT_EQ(a, Tuple(4, -4, 3, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TuplesTests, Adding_two_tuples)
|
TEST(TupleTest, Adding_two_tuples)
|
||||||
{
|
{
|
||||||
Tuple a1 = Tuple(3, -2, 5, 1);
|
Tuple a1 = Tuple(3, -2, 5, 1);
|
||||||
Tuple a2 = Tuple(-2, 3, 1, 0);
|
Tuple a2 = Tuple(-2, 3, 1, 0);
|
||||||
@@ -56,7 +56,7 @@ TEST(TuplesTests, Adding_two_tuples)
|
|||||||
ASSERT_EQ(a1 + a2, Tuple(1, 1, 6, 1));
|
ASSERT_EQ(a1 + a2, Tuple(1, 1, 6, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TuplesTests, Substracting_two_points)
|
TEST(TupleTest, Substracting_two_points)
|
||||||
{
|
{
|
||||||
Point p1 = Point(3, 2, 1);
|
Point p1 = Point(3, 2, 1);
|
||||||
Point p2 = Point(5, 6, 7);
|
Point p2 = Point(5, 6, 7);
|
||||||
@@ -64,7 +64,7 @@ TEST(TuplesTests, Substracting_two_points)
|
|||||||
ASSERT_EQ(p1 - p2, Vector(-2, -4, -6));
|
ASSERT_EQ(p1 - p2, Vector(-2, -4, -6));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TuplesTests, Substracting_a_vector_from_a_point)
|
TEST(TupleTest, Substracting_a_vector_from_a_point)
|
||||||
{
|
{
|
||||||
Point p = Point(3, 2, 1);
|
Point p = Point(3, 2, 1);
|
||||||
Vector v = Vector(5, 6, 7);
|
Vector v = Vector(5, 6, 7);
|
||||||
@@ -72,7 +72,7 @@ TEST(TuplesTests, Substracting_a_vector_from_a_point)
|
|||||||
ASSERT_EQ(p - v, Point(-2, -4, -6));
|
ASSERT_EQ(p - v, Point(-2, -4, -6));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TuplesTests, Substracting_two_vectors)
|
TEST(TupleTest, Substracting_two_vectors)
|
||||||
{
|
{
|
||||||
Vector v1 = Vector(3, 2, 1);
|
Vector v1 = Vector(3, 2, 1);
|
||||||
Vector v2 = Vector(5, 6, 7);
|
Vector v2 = Vector(5, 6, 7);
|
||||||
@@ -80,7 +80,7 @@ TEST(TuplesTests, Substracting_two_vectors)
|
|||||||
ASSERT_EQ(v1 - v2, Vector(-2, -4, -6));
|
ASSERT_EQ(v1 - v2, Vector(-2, -4, -6));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TuplesTests, Substracting_a_vector_from_zero_vector)
|
TEST(TupleTest, Substracting_a_vector_from_zero_vector)
|
||||||
{
|
{
|
||||||
Vector zero = Vector(0, 0, 0);
|
Vector zero = Vector(0, 0, 0);
|
||||||
Vector v = Vector(1, -2, 3);
|
Vector v = Vector(1, -2, 3);
|
||||||
@@ -88,84 +88,84 @@ TEST(TuplesTests, Substracting_a_vector_from_zero_vector)
|
|||||||
ASSERT_EQ(zero - v, Vector(-1, 2, -3));
|
ASSERT_EQ(zero - v, Vector(-1, 2, -3));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TuplesTests, Negating_a_tuple)
|
TEST(TupleTest, Negating_a_tuple)
|
||||||
{
|
{
|
||||||
Tuple a = Tuple(1, -2, 3, -4);
|
Tuple a = Tuple(1, -2, 3, -4);
|
||||||
|
|
||||||
ASSERT_EQ(-a, Tuple(-1, 2, -3, 4));
|
ASSERT_EQ(-a, Tuple(-1, 2, -3, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TuplesTests, Multiplying_a_tuple_by_a_scalar)
|
TEST(TupleTest, Multiplying_a_tuple_by_a_scalar)
|
||||||
{
|
{
|
||||||
Tuple a = Tuple(1, -2, 3, -4);
|
Tuple a = Tuple(1, -2, 3, -4);
|
||||||
|
|
||||||
ASSERT_EQ(a * 3.5, Tuple(3.5, -7, 10.5, -14));
|
ASSERT_EQ(a * 3.5, Tuple(3.5, -7, 10.5, -14));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TuplesTests, Multiplying_a_tuple_by_a_fraction)
|
TEST(TupleTest, Multiplying_a_tuple_by_a_fraction)
|
||||||
{
|
{
|
||||||
Tuple a = Tuple(1, -2, 3, -4);
|
Tuple a = Tuple(1, -2, 3, -4);
|
||||||
|
|
||||||
ASSERT_EQ(a * 0.5, Tuple(0.5, -1, 1.5, -2));
|
ASSERT_EQ(a * 0.5, Tuple(0.5, -1, 1.5, -2));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TuplesTests, Dividing_a_tuple_by_a_scalar)
|
TEST(TupleTest, Dividing_a_tuple_by_a_scalar)
|
||||||
{
|
{
|
||||||
Tuple a = Tuple(1, -2, 3, -4);
|
Tuple a = Tuple(1, -2, 3, -4);
|
||||||
|
|
||||||
ASSERT_EQ(a / 2, Tuple(0.5, -1, 1.5, -2));
|
ASSERT_EQ(a / 2, Tuple(0.5, -1, 1.5, -2));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TuplesTests, Computing_the_magnitude_of_vector_1_0_0)
|
TEST(TupleTest, Computing_the_magnitude_of_vector_1_0_0)
|
||||||
{
|
{
|
||||||
Vector v = Vector(1, 0, 0);
|
Vector v = Vector(1, 0, 0);
|
||||||
|
|
||||||
ASSERT_EQ(v.magnitude(), 1);
|
ASSERT_EQ(v.magnitude(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TuplesTests, Computing_the_magnitude_of_vector_0_1_0)
|
TEST(TupleTest, Computing_the_magnitude_of_vector_0_1_0)
|
||||||
{
|
{
|
||||||
Vector v = Vector(0, 1, 0);
|
Vector v = Vector(0, 1, 0);
|
||||||
|
|
||||||
ASSERT_EQ(v.magnitude(), 1);
|
ASSERT_EQ(v.magnitude(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TuplesTests, Computing_the_magnitude_of_vector_0_0_1)
|
TEST(TupleTest, Computing_the_magnitude_of_vector_0_0_1)
|
||||||
{
|
{
|
||||||
Vector v = Vector(0, 0, 1);
|
Vector v = Vector(0, 0, 1);
|
||||||
|
|
||||||
ASSERT_EQ(v.magnitude(), 1);
|
ASSERT_EQ(v.magnitude(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TuplesTests, Computing_the_magnitude_of_vector_1_2_3)
|
TEST(TupleTest, Computing_the_magnitude_of_vector_1_2_3)
|
||||||
{
|
{
|
||||||
Vector v = Vector(1, 2, 3);
|
Vector v = Vector(1, 2, 3);
|
||||||
|
|
||||||
ASSERT_EQ(v.magnitude(), sqrt(14));
|
ASSERT_EQ(v.magnitude(), sqrt(14));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TuplesTests, Computing_the_magnitude_of_vector_n1_n2_n3)
|
TEST(TupleTest, Computing_the_magnitude_of_vector_n1_n2_n3)
|
||||||
{
|
{
|
||||||
Vector v = Vector(-1, -2, -3);
|
Vector v = Vector(-1, -2, -3);
|
||||||
|
|
||||||
ASSERT_EQ(v.magnitude(), sqrt(14));
|
ASSERT_EQ(v.magnitude(), sqrt(14));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TuplesTests, Nomilise_vector_4_0_0_give_1_0_0)
|
TEST(TupleTest, Nomilise_vector_4_0_0_give_1_0_0)
|
||||||
{
|
{
|
||||||
Vector v = Vector(4, 0, 0);
|
Vector v = Vector(4, 0, 0);
|
||||||
|
|
||||||
ASSERT_EQ(v.normalise(), Vector(1, 0, 0));
|
ASSERT_EQ(v.normalise(), Vector(1, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TuplesTests, Nomilise_vector_1_2_3)
|
TEST(TupleTest, Nomilise_vector_1_2_3)
|
||||||
{
|
{
|
||||||
Vector v = Vector(1, 2, 3);
|
Vector v = Vector(1, 2, 3);
|
||||||
|
|
||||||
ASSERT_EQ(v.normalise(), Vector(1 / sqrt(14), 2 / sqrt(14), 3 / sqrt(14)));
|
ASSERT_EQ(v.normalise(), Vector(1 / sqrt(14), 2 / sqrt(14), 3 / sqrt(14)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TuplesTests, Dot_product_of_two_tuples)
|
TEST(TupleTest, Dot_product_of_two_tuples)
|
||||||
{
|
{
|
||||||
Vector a = Vector(1, 2, 3);
|
Vector a = Vector(1, 2, 3);
|
||||||
Vector b = Vector(2, 3, 4);
|
Vector b = Vector(2, 3, 4);
|
||||||
@@ -173,7 +173,7 @@ TEST(TuplesTests, Dot_product_of_two_tuples)
|
|||||||
ASSERT_EQ(a.dot(b), 20);
|
ASSERT_EQ(a.dot(b), 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TuplesTests, Cross_product_of_two_vector)
|
TEST(TupleTest, Cross_product_of_two_vector)
|
||||||
{
|
{
|
||||||
Vector a = Vector(1, 2, 3);
|
Vector a = Vector(1, 2, 3);
|
||||||
Vector b = Vector(2, 3, 4);
|
Vector b = Vector(2, 3, 4);
|
||||||
@@ -181,3 +181,23 @@ TEST(TuplesTests, Cross_product_of_two_vector)
|
|||||||
ASSERT_EQ(a.cross(b), Vector(-1, 2, -1));
|
ASSERT_EQ(a.cross(b), Vector(-1, 2, -1));
|
||||||
ASSERT_EQ(b.cross(a), Vector(1, -2, 1));
|
ASSERT_EQ(b.cross(a), Vector(1, -2, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(TupleTest, Reflecting_a_vector_approaching_at_45)
|
||||||
|
{
|
||||||
|
Vector v = Vector(1, -1, 0); /* Vector */
|
||||||
|
Vector n = Vector(0, 1, 0); /* Normal */
|
||||||
|
|
||||||
|
Tuple r = v.reflect(n);
|
||||||
|
|
||||||
|
ASSERT_EQ(r, Vector(1, 1, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(TupleTest, Reflecting_a_vector_off_a_slanted_surface)
|
||||||
|
{
|
||||||
|
Vector v = Vector(0, -1, 0); /* Vector */
|
||||||
|
Vector n = Vector(sqrt(2)/2, sqrt(2)/2, 0); /* Normal */
|
||||||
|
|
||||||
|
Tuple r = v.reflect(n);
|
||||||
|
|
||||||
|
ASSERT_EQ(r, Vector(1, 0, 0));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user