More Ray work.
This commit is contained in:
@@ -9,4 +9,17 @@
|
|||||||
#ifndef DORAYME_RAY_H
|
#ifndef DORAYME_RAY_H
|
||||||
#define DORAYME_RAY_H
|
#define DORAYME_RAY_H
|
||||||
|
|
||||||
|
#include <tuple.h>
|
||||||
|
|
||||||
|
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
|
#endif //DORAYME_RAY_H
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ 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 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)
|
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})
|
||||||
|
|||||||
32
tests/ray_test.cpp
Normal file
32
tests/ray_test.cpp
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* DoRayMe - a quick and dirty Raytracer
|
||||||
|
* Ray unit tests
|
||||||
|
*
|
||||||
|
* Created by Manoël Trapier
|
||||||
|
* Copyright (c) 2020 986-Studio.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include <ray.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));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user