From 8faf1db3be0600284693a553921a131c2c11fd58 Mon Sep 17 00:00:00 2001 From: Godzil Date: Sat, 15 Feb 2020 23:45:19 +0000 Subject: [PATCH] More Ray work. --- source/include/ray.h | 13 +++++++++++++ tests/CMakeLists.txt | 2 +- tests/ray_test.cpp | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 tests/ray_test.cpp diff --git a/source/include/ray.h b/source/include/ray.h index d525021..d66db0c 100644 --- a/source/include/ray.h +++ b/source/include/ray.h @@ -9,4 +9,17 @@ #ifndef DORAYME_RAY_H #define DORAYME_RAY_H +#include + +class Ray +{ +public: + Vector direction; + Point origin; + + Ray(Point origin, Vector direction) : origin(origin), direction(direction) { }; + + Tuple position(double t) { return this->origin + this->direction * t; }; +}; + #endif //DORAYME_RAY_H diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4233fec..90cbc26 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -3,7 +3,7 @@ project(DoRayTested) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) -set(TESTS_SRC tuple_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) add_executable(testMyRays) target_include_directories(testMyRays PUBLIC ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) diff --git a/tests/ray_test.cpp b/tests/ray_test.cpp new file mode 100644 index 0000000..1a9d0d7 --- /dev/null +++ b/tests/ray_test.cpp @@ -0,0 +1,32 @@ +/* + * DoRayMe - a quick and dirty Raytracer + * Ray unit tests + * + * Created by Manoƫl Trapier + * Copyright (c) 2020 986-Studio. + * + */ +#include +#include + + +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)); +} \ No newline at end of file