|
@@ -9,6 +9,7 @@
|
|
#include <material.h>
|
|
#include <material.h>
|
|
#include <math.h>
|
|
#include <math.h>
|
|
#include <colour.h>
|
|
#include <colour.h>
|
|
|
|
+#include <testshape.h>
|
|
#include <gtest/gtest.h>
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
TEST(MaterialTest, The_default_material)
|
|
TEST(MaterialTest, The_default_material)
|
|
@@ -28,33 +29,36 @@ static Point position = Point(0, 0, 0);
|
|
|
|
|
|
TEST(MaterialTest, Lighting_with_the_eye_between_the_light_and_the_surface)
|
|
TEST(MaterialTest, Lighting_with_the_eye_between_the_light_and_the_surface)
|
|
{
|
|
{
|
|
|
|
+ TestShape t = TestShape();
|
|
Vector eyev = Vector(0, 0, -1);
|
|
Vector eyev = Vector(0, 0, -1);
|
|
Vector normalv = Vector(0, 0, -1);
|
|
Vector normalv = Vector(0, 0, -1);
|
|
Light light = Light(POINT_LIGHT, Point(0, 0, -10), Colour(1, 1, 1));
|
|
Light light = Light(POINT_LIGHT, Point(0, 0, -10), Colour(1, 1, 1));
|
|
|
|
|
|
- Colour result = m.lighting(light, position, eyev, normalv);
|
|
|
|
|
|
+ Colour result = m.lighting(light, position, eyev, normalv, &t);
|
|
|
|
|
|
ASSERT_EQ(result, Colour(1.9, 1.9, 1.9));
|
|
ASSERT_EQ(result, Colour(1.9, 1.9, 1.9));
|
|
}
|
|
}
|
|
|
|
|
|
TEST(MaterialTest, Lighting_with_the_eye_between_the_light_and_the_surface_eye_offset_by_45)
|
|
TEST(MaterialTest, Lighting_with_the_eye_between_the_light_and_the_surface_eye_offset_by_45)
|
|
{
|
|
{
|
|
|
|
+ TestShape t = TestShape();
|
|
Vector eyev = Vector(0, -sqrt(2)/2, -sqrt(2)/2);
|
|
Vector eyev = Vector(0, -sqrt(2)/2, -sqrt(2)/2);
|
|
Vector normalv = Vector(0, 0, -1);
|
|
Vector normalv = Vector(0, 0, -1);
|
|
Light light = Light(POINT_LIGHT, Point(0, 0, -10), Colour(1, 1, 1));
|
|
Light light = Light(POINT_LIGHT, Point(0, 0, -10), Colour(1, 1, 1));
|
|
|
|
|
|
- Colour result = m.lighting(light, position, eyev, normalv);
|
|
|
|
|
|
+ Colour result = m.lighting(light, position, eyev, normalv, &t);
|
|
|
|
|
|
ASSERT_EQ(result, Colour(1.0, 1.0, 1.0));
|
|
ASSERT_EQ(result, Colour(1.0, 1.0, 1.0));
|
|
}
|
|
}
|
|
|
|
|
|
TEST(MaterialTest, Lighting_with_the_eye_opposite_surface_light_offset_45)
|
|
TEST(MaterialTest, Lighting_with_the_eye_opposite_surface_light_offset_45)
|
|
{
|
|
{
|
|
|
|
+ TestShape t = TestShape();
|
|
Vector eyev = Vector(0, 0, -1);
|
|
Vector eyev = Vector(0, 0, -1);
|
|
Vector normalv = Vector(0, 0, -1);
|
|
Vector normalv = Vector(0, 0, -1);
|
|
Light light = Light(POINT_LIGHT, Point(0, 10, -10), Colour(1, 1, 1));
|
|
Light light = Light(POINT_LIGHT, Point(0, 10, -10), Colour(1, 1, 1));
|
|
|
|
|
|
- Colour result = m.lighting(light, position, eyev, normalv);
|
|
|
|
|
|
+ Colour result = m.lighting(light, position, eyev, normalv, &t);
|
|
|
|
|
|
set_equal_precision(0.0001);
|
|
set_equal_precision(0.0001);
|
|
|
|
|
|
@@ -65,11 +69,12 @@ TEST(MaterialTest, Lighting_with_the_eye_opposite_surface_light_offset_45)
|
|
|
|
|
|
TEST(MaterialTest, Lighting_with_the_eye_in_the_path_of_the_reflection_vector)
|
|
TEST(MaterialTest, Lighting_with_the_eye_in_the_path_of_the_reflection_vector)
|
|
{
|
|
{
|
|
|
|
+ TestShape t = TestShape();
|
|
Vector eyev = Vector(0, -sqrt(2)/2, -sqrt(2)/2);
|
|
Vector eyev = Vector(0, -sqrt(2)/2, -sqrt(2)/2);
|
|
Vector normalv = Vector(0, 0, -1);
|
|
Vector normalv = Vector(0, 0, -1);
|
|
Light light = Light(POINT_LIGHT, Point(0, 10, -10), Colour(1, 1, 1));
|
|
Light light = Light(POINT_LIGHT, Point(0, 10, -10), Colour(1, 1, 1));
|
|
|
|
|
|
- Colour result = m.lighting(light, position, eyev, normalv);
|
|
|
|
|
|
+ Colour result = m.lighting(light, position, eyev, normalv, &t);
|
|
|
|
|
|
set_equal_precision(0.0001);
|
|
set_equal_precision(0.0001);
|
|
|
|
|
|
@@ -80,23 +85,25 @@ TEST(MaterialTest, Lighting_with_the_eye_in_the_path_of_the_reflection_vector)
|
|
|
|
|
|
TEST(MaterialTest, Lighting_with_the_light_behind_the_surface)
|
|
TEST(MaterialTest, Lighting_with_the_light_behind_the_surface)
|
|
{
|
|
{
|
|
|
|
+ TestShape t = TestShape();
|
|
Vector eyev = Vector(0, 0, -1);
|
|
Vector eyev = Vector(0, 0, -1);
|
|
Vector normalv = Vector(0, 0, -1);
|
|
Vector normalv = Vector(0, 0, -1);
|
|
Light light = Light(POINT_LIGHT, Point(0, 0, 10), Colour(1, 1, 1));
|
|
Light light = Light(POINT_LIGHT, Point(0, 0, 10), Colour(1, 1, 1));
|
|
|
|
|
|
- Colour result = m.lighting(light, position, eyev, normalv);
|
|
|
|
|
|
+ Colour result = m.lighting(light, position, eyev, normalv, &t);
|
|
|
|
|
|
ASSERT_EQ(result, Colour(0.1, 0.1, 0.1));
|
|
ASSERT_EQ(result, Colour(0.1, 0.1, 0.1));
|
|
}
|
|
}
|
|
|
|
|
|
TEST(MaterialTest, Lighting_with_the_surface_in_shadow)
|
|
TEST(MaterialTest, Lighting_with_the_surface_in_shadow)
|
|
{
|
|
{
|
|
|
|
+ TestShape t = TestShape();
|
|
Vector eyev = Vector(0, 0, -1);
|
|
Vector eyev = Vector(0, 0, -1);
|
|
Vector normalv = Vector(0, 0, -1);
|
|
Vector normalv = Vector(0, 0, -1);
|
|
Light light = Light(POINT_LIGHT, Point(0, 0, -10), Colour(1, 1, 1));
|
|
Light light = Light(POINT_LIGHT, Point(0, 0, -10), Colour(1, 1, 1));
|
|
bool inShadow = true;
|
|
bool inShadow = true;
|
|
|
|
|
|
- Colour result = m.lighting(light, position, eyev, normalv, inShadow);
|
|
|
|
|
|
+ Colour result = m.lighting(light, position, eyev, normalv, &t, inShadow);
|
|
|
|
|
|
ASSERT_EQ(result, Colour(0.1, 0.1, 0.1));
|
|
ASSERT_EQ(result, Colour(0.1, 0.1, 0.1));
|
|
}
|
|
}
|