Renaming Object to Shape (part 1)
This commit is contained in:
@@ -5,7 +5,7 @@ add_library(rayonnement STATIC)
|
|||||||
|
|
||||||
file(GLOB RAY_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h)
|
file(GLOB RAY_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h)
|
||||||
|
|
||||||
file(GLOB RAY_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/objects/*.cpp)
|
file(GLOB RAY_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/shapes/*.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})
|
||||||
|
|||||||
@@ -11,16 +11,16 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
class Object;
|
class Shape;
|
||||||
|
|
||||||
class Intersection
|
class Intersection
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
double t;
|
double t;
|
||||||
Object *object;
|
Shape *object;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Intersection(double t, Object *object) : t(t), object(object) { };
|
Intersection(double t, Shape *object) : t(t), object(object) { };
|
||||||
bool nothing() { return (this->object == nullptr); };
|
bool nothing() { return (this->object == nullptr); };
|
||||||
|
|
||||||
bool operator==(const Intersection &b) const { return ((this->t == b.t) && (this->object == b.object)); };
|
bool operator==(const Intersection &b) const { return ((this->t == b.t) && (this->object == b.object)); };
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#ifndef DORAYME_OBJECT_H
|
#ifndef DORAYME_OBJECT_H
|
||||||
#define DORAYME_OBJECT_H
|
#define DORAYME_OBJECT_H
|
||||||
|
|
||||||
class Object;
|
class Shape;
|
||||||
|
|
||||||
#include <ray.h>
|
#include <ray.h>
|
||||||
#include <tuple.h>
|
#include <tuple.h>
|
||||||
@@ -18,7 +18,7 @@ class Object;
|
|||||||
#include <material.h>
|
#include <material.h>
|
||||||
|
|
||||||
/* Base class for all object that can be presented in the world */
|
/* Base class for all object that can be presented in the world */
|
||||||
class Object
|
class Shape
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Matrix transformMatrix;
|
Matrix transformMatrix;
|
||||||
@@ -26,7 +26,7 @@ public:
|
|||||||
Material material;
|
Material material;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Object();
|
Shape();
|
||||||
|
|
||||||
virtual Intersect intersect(Ray r);
|
virtual Intersect intersect(Ray r);
|
||||||
virtual Tuple normalAt(Tuple point);
|
virtual Tuple normalAt(Tuple point);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
#include <ray.h>
|
#include <ray.h>
|
||||||
#include <intersect.h>
|
#include <intersect.h>
|
||||||
|
|
||||||
class Sphere : public Object
|
class Sphere : public Shape
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/* All sphere are at (0, 0, 0) and radius 1 in the object space */
|
/* All sphere are at (0, 0, 0) and radius 1 in the object space */
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
Intersect::Intersect()
|
Intersect::Intersect()
|
||||||
{
|
{
|
||||||
this->allocated = MIN_ALLOC;
|
this->allocated = MIN_ALLOC;
|
||||||
this->list = (Intersection *)calloc(sizeof(Object *), MIN_ALLOC);
|
this->list = (Intersection *)calloc(sizeof(Shape *), MIN_ALLOC);
|
||||||
this->num = 0;
|
this->num = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ void Intersect::add(Intersection i)
|
|||||||
if ((this->num + 1) < this->allocated)
|
if ((this->num + 1) < this->allocated)
|
||||||
{
|
{
|
||||||
this->allocated *= 2;
|
this->allocated *= 2;
|
||||||
this->list = (Intersection *)realloc(this->list, sizeof(Object *) * this->allocated);
|
this->list = (Intersection *)realloc(this->list, sizeof(Shape *) * this->allocated);
|
||||||
}
|
}
|
||||||
this->list[this->num++] = i;
|
this->list[this->num++] = i;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,23 +13,23 @@
|
|||||||
#include <tuple.h>
|
#include <tuple.h>
|
||||||
#include <intersect.h>
|
#include <intersect.h>
|
||||||
|
|
||||||
Object::Object()
|
Shape::Shape()
|
||||||
{
|
{
|
||||||
this->transformMatrix = Matrix4().identity();
|
this->transformMatrix = Matrix4().identity();
|
||||||
this->inverseTransform = this->transformMatrix.inverse();
|
this->inverseTransform = this->transformMatrix.inverse();
|
||||||
}
|
}
|
||||||
|
|
||||||
Intersect Object::intersect(Ray r)
|
Intersect Shape::intersect(Ray r)
|
||||||
{
|
{
|
||||||
return Intersect();
|
return Intersect();
|
||||||
};
|
};
|
||||||
|
|
||||||
Tuple Object::normalAt(Tuple point)
|
Tuple Shape::normalAt(Tuple point)
|
||||||
{
|
{
|
||||||
return Vector(0, 0, 0);
|
return Vector(0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Object::setTransform(Matrix transform)
|
void Shape::setTransform(Matrix transform)
|
||||||
{
|
{
|
||||||
this->transformMatrix = transform;
|
this->transformMatrix = transform;
|
||||||
this->inverseTransform = transform.inverse();
|
this->inverseTransform = transform.inverse();
|
||||||
@@ -32,7 +32,7 @@ TEST(IntersectTest, An_intersection_encapsulate_t_and_object)
|
|||||||
Intersection i = Intersection(3.5, &s);
|
Intersection i = Intersection(3.5, &s);
|
||||||
|
|
||||||
ASSERT_EQ(i.t, 3.5);
|
ASSERT_EQ(i.t, 3.5);
|
||||||
ASSERT_EQ(i.object, (Object *)&s);
|
ASSERT_EQ(i.object, (Shape *)&s);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(IntersectTest, Aggregating_intersections)
|
TEST(IntersectTest, Aggregating_intersections)
|
||||||
@@ -57,8 +57,8 @@ TEST(IntersectTest, Intersect_sets_the_object_on_the_intersection)
|
|||||||
Intersect xs = s.intersect(r);
|
Intersect xs = s.intersect(r);
|
||||||
|
|
||||||
ASSERT_EQ(xs.count(), 2);
|
ASSERT_EQ(xs.count(), 2);
|
||||||
ASSERT_EQ(xs[0].object, (Object *)&s);
|
ASSERT_EQ(xs[0].object, (Shape *)&s);
|
||||||
ASSERT_EQ(xs[1].object, (Object *)&s);
|
ASSERT_EQ(xs[1].object, (Shape *)&s);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(IntersectTest, The_hit_when_all_intersection_have_positive_t)
|
TEST(IntersectTest, The_hit_when_all_intersection_have_positive_t)
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ TEST(RayTest, Translating_a_ray)
|
|||||||
Ray r = Ray(Point(1, 2, 3), Vector(0, 1, 0));
|
Ray r = Ray(Point(1, 2, 3), Vector(0, 1, 0));
|
||||||
|
|
||||||
Matrix m = translation(3, 4, 5);
|
Matrix m = translation(3, 4, 5);
|
||||||
Object o = Object();
|
Shape o = Shape();
|
||||||
|
|
||||||
o.setTransform(m);
|
o.setTransform(m);
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ TEST(RayTest, Scaling_a_ray)
|
|||||||
Ray r = Ray(Point(1, 2, 3), Vector(0, 1, 0));
|
Ray r = Ray(Point(1, 2, 3), Vector(0, 1, 0));
|
||||||
|
|
||||||
Matrix m = scaling(2, 3, 4);
|
Matrix m = scaling(2, 3, 4);
|
||||||
Object o = Object();
|
Shape o = Shape();
|
||||||
|
|
||||||
o.setTransform(m);
|
o.setTransform(m);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user