From 5a4f9f4dc48124a4bb0851c4db59680b2d26c730 Mon Sep 17 00:00:00 2001 From: Godzil Date: Tue, 18 Feb 2020 11:40:55 +0000 Subject: [PATCH] Renaming Object to Shape (part 1) --- source/CMakeLists.txt | 2 +- source/include/intersection.h | 6 +++--- source/include/object.h | 6 +++--- source/include/sphere.h | 2 +- source/intersect.cpp | 4 ++-- source/{objects => shapes}/light.cpp | 0 source/{objects => shapes}/material.cpp | 0 source/{objects => shapes}/object.cpp | 8 ++++---- source/{objects => shapes}/ray.cpp | 0 source/{objects => shapes}/sphere.cpp | 0 tests/intersect_test.cpp | 6 +++--- tests/ray_test.cpp | 4 ++-- 12 files changed, 19 insertions(+), 19 deletions(-) rename source/{objects => shapes}/light.cpp (100%) rename source/{objects => shapes}/material.cpp (100%) rename source/{objects => shapes}/object.cpp (79%) rename source/{objects => shapes}/ray.cpp (100%) rename source/{objects => shapes}/sphere.cpp (100%) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 074927c..9fb31ca 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -5,7 +5,7 @@ add_library(rayonnement STATIC) 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_sources(rayonnement PRIVATE ${RAY_HEADERS} ${RAY_SOURCES}) diff --git a/source/include/intersection.h b/source/include/intersection.h index 00d5372..e388c06 100644 --- a/source/include/intersection.h +++ b/source/include/intersection.h @@ -11,16 +11,16 @@ #include -class Object; +class Shape; class Intersection { public: double t; - Object *object; + Shape *object; 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 operator==(const Intersection &b) const { return ((this->t == b.t) && (this->object == b.object)); }; diff --git a/source/include/object.h b/source/include/object.h index fc94507..8d5b39c 100644 --- a/source/include/object.h +++ b/source/include/object.h @@ -9,7 +9,7 @@ #ifndef DORAYME_OBJECT_H #define DORAYME_OBJECT_H -class Object; +class Shape; #include #include @@ -18,7 +18,7 @@ class Object; #include /* Base class for all object that can be presented in the world */ -class Object +class Shape { public: Matrix transformMatrix; @@ -26,7 +26,7 @@ public: Material material; public: - Object(); + Shape(); virtual Intersect intersect(Ray r); virtual Tuple normalAt(Tuple point); diff --git a/source/include/sphere.h b/source/include/sphere.h index 7e3aa1b..66a8313 100644 --- a/source/include/sphere.h +++ b/source/include/sphere.h @@ -13,7 +13,7 @@ #include #include -class Sphere : public Object +class Sphere : public Shape { public: /* All sphere are at (0, 0, 0) and radius 1 in the object space */ diff --git a/source/intersect.cpp b/source/intersect.cpp index 5a6fed3..09da1d9 100644 --- a/source/intersect.cpp +++ b/source/intersect.cpp @@ -17,7 +17,7 @@ Intersect::Intersect() { this->allocated = MIN_ALLOC; - this->list = (Intersection *)calloc(sizeof(Object *), MIN_ALLOC); + this->list = (Intersection *)calloc(sizeof(Shape *), MIN_ALLOC); this->num = 0; } @@ -26,7 +26,7 @@ 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 = (Intersection *)realloc(this->list, sizeof(Shape *) * this->allocated); } this->list[this->num++] = i; } diff --git a/source/objects/light.cpp b/source/shapes/light.cpp similarity index 100% rename from source/objects/light.cpp rename to source/shapes/light.cpp diff --git a/source/objects/material.cpp b/source/shapes/material.cpp similarity index 100% rename from source/objects/material.cpp rename to source/shapes/material.cpp diff --git a/source/objects/object.cpp b/source/shapes/object.cpp similarity index 79% rename from source/objects/object.cpp rename to source/shapes/object.cpp index bdb8294..1d4427d 100644 --- a/source/objects/object.cpp +++ b/source/shapes/object.cpp @@ -13,23 +13,23 @@ #include #include -Object::Object() +Shape::Shape() { this->transformMatrix = Matrix4().identity(); this->inverseTransform = this->transformMatrix.inverse(); } -Intersect Object::intersect(Ray r) +Intersect Shape::intersect(Ray r) { return Intersect(); }; -Tuple Object::normalAt(Tuple point) +Tuple Shape::normalAt(Tuple point) { return Vector(0, 0, 0); } -void Object::setTransform(Matrix transform) +void Shape::setTransform(Matrix transform) { this->transformMatrix = transform; this->inverseTransform = transform.inverse(); diff --git a/source/objects/ray.cpp b/source/shapes/ray.cpp similarity index 100% rename from source/objects/ray.cpp rename to source/shapes/ray.cpp diff --git a/source/objects/sphere.cpp b/source/shapes/sphere.cpp similarity index 100% rename from source/objects/sphere.cpp rename to source/shapes/sphere.cpp diff --git a/tests/intersect_test.cpp b/tests/intersect_test.cpp index 0e171c8..adaef43 100644 --- a/tests/intersect_test.cpp +++ b/tests/intersect_test.cpp @@ -32,7 +32,7 @@ TEST(IntersectTest, An_intersection_encapsulate_t_and_object) Intersection i = Intersection(3.5, &s); ASSERT_EQ(i.t, 3.5); - ASSERT_EQ(i.object, (Object *)&s); + ASSERT_EQ(i.object, (Shape *)&s); } TEST(IntersectTest, Aggregating_intersections) @@ -57,8 +57,8 @@ TEST(IntersectTest, Intersect_sets_the_object_on_the_intersection) Intersect xs = s.intersect(r); ASSERT_EQ(xs.count(), 2); - ASSERT_EQ(xs[0].object, (Object *)&s); - ASSERT_EQ(xs[1].object, (Object *)&s); + ASSERT_EQ(xs[0].object, (Shape *)&s); + ASSERT_EQ(xs[1].object, (Shape *)&s); } TEST(IntersectTest, The_hit_when_all_intersection_have_positive_t) diff --git a/tests/ray_test.cpp b/tests/ray_test.cpp index 3bd2dd8..d2ea997 100644 --- a/tests/ray_test.cpp +++ b/tests/ray_test.cpp @@ -38,7 +38,7 @@ 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(); + Shape o = Shape(); o.setTransform(m); @@ -53,7 +53,7 @@ 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(); + Shape o = Shape(); o.setTransform(m);