[WIP] ADD normal_at method
This commit is contained in:
@@ -7,4 +7,4 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
add_executable(chapter_05 chapter_05.cpp)
|
||||
|
||||
target_link_libraries(chapter_05 PRIVATE raytracing)
|
||||
target_link_libraries(chapter_05 PRIVATE raytracing gcov)
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
|
||||
project(raytracing)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
project(raytracing)
|
||||
add_definitions(--coverage)
|
||||
|
||||
add_library(raytracing
|
||||
|
||||
|
||||
@@ -103,6 +103,14 @@ void Object::set_transform(const Matrix &a_transform_matrix)
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
Tuple Object::normal_at(const Tuple &a_point)
|
||||
{
|
||||
Tuple the_result = a_point - Tuple::Point(0, 0, 0);
|
||||
return the_result.normalize();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
Intersections Object::intersect(Ray &a_ray)
|
||||
{
|
||||
Intersections the_ret;
|
||||
|
||||
@@ -56,6 +56,8 @@ namespace Raytracer
|
||||
Matrix &transform(void);
|
||||
void set_transform(const Matrix &a_transform_matrix);
|
||||
|
||||
Tuple normal_at(const Tuple &a_point);
|
||||
|
||||
virtual Intersections intersect(Ray &a_ray);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -37,10 +37,13 @@ SCENARIO("The normal on a sphere at point a on the x axis", "[features/spheres.f
|
||||
{
|
||||
GIVEN("s <- sphere()")
|
||||
{
|
||||
Sphere s;
|
||||
WHEN("n <- normal_at(s, point(1,0,0))")
|
||||
{
|
||||
Tuple n = s.normal_at(Tuple::Point(1, 0, 0));
|
||||
THEN("n = vector(1,0,0)")
|
||||
{
|
||||
REQUIRE(n == Tuple::Vector(1, 0, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,10 +55,13 @@ SCENARIO("The normal on a sphere at point a on the y axis", "[features/spheres.f
|
||||
{
|
||||
GIVEN("s <- sphere()")
|
||||
{
|
||||
Sphere s;
|
||||
WHEN("n <- normal_at(s, point(0,1,0))")
|
||||
{
|
||||
Tuple n = s.normal_at(Tuple::Point(0, 1, 0));
|
||||
THEN("n = vector(0,1,0)")
|
||||
{
|
||||
REQUIRE(n == Tuple::Vector(0, 1, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,10 +73,13 @@ SCENARIO("The normal on a sphere at point a on the z axis", "[features/spheres.f
|
||||
{
|
||||
GIVEN("s <- sphere()")
|
||||
{
|
||||
Sphere s;
|
||||
WHEN("n <- normal_at(s, point(0,0,1))")
|
||||
{
|
||||
Tuple n = s.normal_at(Tuple::Point(0, 0, 1));
|
||||
THEN("n = vector(0,0,1)")
|
||||
{
|
||||
REQUIRE(n == Tuple::Vector(0, 0, 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,10 +91,13 @@ SCENARIO("The normal on a sphere at a nonaxial point", "[features/spheres.featur
|
||||
{
|
||||
GIVEN("s <- sphere()")
|
||||
{
|
||||
Sphere s;
|
||||
WHEN("n <- normal_at(s, point(sqrt(3)/3,sqrt(3)/3,sqrt(3)/3))")
|
||||
{
|
||||
THEN("n = vector(sqrt(3)/3,sqrt(3)/3,sqrt(3)/3)")
|
||||
Tuple n = s.normal_at(Tuple::Point(sqrt(3) / 3, sqrt(3) / 3, sqrt(3) / 3));
|
||||
THEN("n = vector(sqrt(3)/3,sqrt(3)/3,sqrt(3)/3))")
|
||||
{
|
||||
REQUIRE(n == Tuple::Vector(sqrt(3) / 3, sqrt(3) / 3, sqrt(3) / 3));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,10 +109,13 @@ SCENARIO("The normal is a normalized vector", "[features/spheres.feature]")
|
||||
{
|
||||
GIVEN("s <- sphere()")
|
||||
{
|
||||
Sphere s;
|
||||
WHEN("n <- normal_at(s, point(sqrt(3)/3,sqrt(3)/3,sqrt(3)/3))")
|
||||
{
|
||||
Tuple n = s.normal_at(Tuple::Point(sqrt(3) / 3, sqrt(3) / 3, sqrt(3) / 3));
|
||||
THEN("n = normalize(n)")
|
||||
{
|
||||
REQUIRE(n == n.normalize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,4 +21,6 @@ add_executable(raytracing_test
|
||||
|
||||
include_directories("${CMAKE_SOURCE_DIR}/tests")
|
||||
|
||||
target_link_libraries(raytracing_test PRIVATE raytracing)
|
||||
target_link_libraries(raytracing_test PRIVATE raytracing gcov)
|
||||
|
||||
add_test(NAME raytracing_test COMMAND tests/raytracing_test)
|
||||
|
||||
Reference in New Issue
Block a user