[WIP] stripe-pattern is now ok.
This commit is contained in:
@@ -58,12 +58,15 @@ SCENARIO("A stripe pattern is constant in y", "[features/patterns.feature]")
|
||||
StripePattern pattern(Color::White(), Color::Black());
|
||||
THEN("stripe_at(pattern, point(0, 0, 0) = white")
|
||||
{
|
||||
REQUIRE(pattern.stripe_at(Tuple::Point(0, 0, 0)) == Color::White());
|
||||
}
|
||||
AND_THEN("stripe_at(pattern, point(0, 1, 0) = white")
|
||||
{
|
||||
REQUIRE(pattern.stripe_at(Tuple::Point(0, 1, 0)) == Color::White());
|
||||
}
|
||||
AND_THEN("stripe_at(pattern, point(0, 2, 0) = white")
|
||||
{
|
||||
REQUIRE(pattern.stripe_at(Tuple::Point(0, 2, 0)) == Color::White());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -128,42 +131,48 @@ SCENARIO("A stripe pattern alternates in x", "[features/patterns.feature]")
|
||||
|
||||
SCENARIO("Lightning with a pattern applied", "[features/materials.feature]")
|
||||
{
|
||||
Material m;
|
||||
GIVEN("m.pattern <- strip_pattern(color(1, 1, 1), color(0, 0, 0))")
|
||||
GIVEN("object <- sphere()")
|
||||
{
|
||||
m.set_pattern(new StripePattern(Color(1, 1, 1), Color(0, 0, 0)));
|
||||
AND_GIVEN("m.ambient <- 1")
|
||||
Sphere object;
|
||||
Material m;
|
||||
GIVEN("m.pattern <- strip_pattern(color(1, 1, 1), color(0, 0, 0))")
|
||||
{
|
||||
m.set_ambient(1);
|
||||
AND_GIVEN("m.diffuse <- 0")
|
||||
m.set_pattern(new StripePattern(Color(1, 1, 1), Color(0, 0, 0)));
|
||||
AND_GIVEN("m.ambient <- 1")
|
||||
{
|
||||
m.set_diffuse(0);
|
||||
AND_GIVEN("m.specular <- 0")
|
||||
m.set_ambient(1);
|
||||
AND_GIVEN("m.diffuse <- 0")
|
||||
{
|
||||
m.set_specular(0);
|
||||
AND_GIVEN("eyev <- vector(0, 0, -1)")
|
||||
m.set_diffuse(0);
|
||||
AND_GIVEN("m.specular <- 0")
|
||||
{
|
||||
Tuple eyev = Tuple::Vector(0, 0, -1);
|
||||
AND_GIVEN("normalv <- vector(0, 0, -1)")
|
||||
m.set_specular(0);
|
||||
AND_GIVEN("eyev <- vector(0, 0, -1)")
|
||||
{
|
||||
Tuple normalv = Tuple::Vector(0, 0, -1);
|
||||
AND_GIVEN("light <- point_light(point(0, 0, -10), color(1, 1, 1))")
|
||||
Tuple eyev = Tuple::Vector(0, 0, -1);
|
||||
AND_GIVEN("normalv <- vector(0, 0, -1)")
|
||||
{
|
||||
PointLight light = PointLight(Tuple::Point(0, 0, -10), Color(1, 1, 1));
|
||||
|
||||
WHEN("c1 <- lighting(m, light, point(0.9, 0, 0), eyev, normalv, false)")
|
||||
Tuple normalv = Tuple::Vector(0, 0, -1);
|
||||
AND_GIVEN("light <- point_light(point(0, 0, -10), color(1, 1, 1))")
|
||||
{
|
||||
Color c1 = m.lighting(light, Tuple::Point(0.9, 0, 0), eyev, normalv, false);
|
||||
AND_WHEN("c2 <- lighting(m, light, point(1.1, 0, 0), eyev, normalv, false)")
|
||||
PointLight light = PointLight(Tuple::Point(0, 0, -10), Color(1, 1, 1));
|
||||
|
||||
WHEN("c1 <- lighting(m, light, point(0.9, 0, 0), eyev, normalv, false)")
|
||||
{
|
||||
Color c2 = m.lighting(light, Tuple::Point(1.1, 0, 0), eyev, normalv, false);
|
||||
THEN("c1 = color(1, 1, 1)")
|
||||
Color c1 =
|
||||
m.lighting(&object, light, Tuple::Point(0.9, 0, 0), eyev, normalv, false);
|
||||
AND_WHEN("c2 <- lighting(m, light, point(1.1, 0, 0), eyev, normalv, false)")
|
||||
{
|
||||
REQUIRE(c1 == Color(1, 1, 1));
|
||||
}
|
||||
AND_THEN("c2 = color(0, 0, 0)")
|
||||
{
|
||||
REQUIRE(c2 == Color(0, 0, 0));
|
||||
Color c2 = m.lighting(&object, light, Tuple::Point(1.1, 0, 0), eyev,
|
||||
normalv, false);
|
||||
THEN("c1 = color(1, 1, 1)")
|
||||
{
|
||||
REQUIRE(c1 == Color(1, 1, 1));
|
||||
}
|
||||
AND_THEN("c2 = color(0, 0, 0)")
|
||||
{
|
||||
REQUIRE(c2 == Color(0, 0, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -175,3 +184,85 @@ SCENARIO("Lightning with a pattern applied", "[features/materials.feature]")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
SCENARIO("Stripes with an object transformation", "[features/patterns.feature]")
|
||||
{
|
||||
GIVEN("object <- sphere()")
|
||||
{
|
||||
Sphere object;
|
||||
AND_GIVEN("set_transform(object, scaling(2, 2, 2))")
|
||||
{
|
||||
object.set_transform(Matrix::scaling(2, 2, 2));
|
||||
AND_GIVEN("pattern <- stripe_pattern(white, black)")
|
||||
{
|
||||
StripePattern pattern(Color::White(), Color::Black());
|
||||
WHEN("c <- stripe_at_object(pattern, object, point(1.5, 0, 0))")
|
||||
{
|
||||
Color c = pattern.stripe_at_object(&object, Tuple::Point(1.5, 0, 0));
|
||||
THEN("c = white")
|
||||
{
|
||||
REQUIRE(c == Color::White());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
SCENARIO("Stripes with an pattern transformation", "[features/patterns.feature]")
|
||||
{
|
||||
GIVEN("object <- sphere()")
|
||||
{
|
||||
Sphere object;
|
||||
AND_GIVEN("pattern <- stripe_pattern(white, black)")
|
||||
{
|
||||
StripePattern pattern(Color::White(), Color::Black());
|
||||
AND_GIVEN("set_transform(pattern, scaling(2, 2, 2))")
|
||||
{
|
||||
pattern.set_pattern_transform(Matrix::scaling(2, 2, 2));
|
||||
WHEN("c <- stripe_at_object(pattern, object, point(1.5, 0, 0))")
|
||||
{
|
||||
Color c = pattern.stripe_at_object(&object, Tuple::Point(1.5, 0, 0));
|
||||
THEN("c = white")
|
||||
{
|
||||
REQUIRE(c == Color::White());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
SCENARIO("Stripes with both an object and pattern transformation", "[features/patterns.feature]")
|
||||
{
|
||||
GIVEN("object <- sphere()")
|
||||
{
|
||||
Sphere object;
|
||||
AND_GIVEN("set_transform(object, scaling(2, 2, 2))")
|
||||
{
|
||||
object.set_transform(Matrix::scaling(2, 2, 2));
|
||||
AND_GIVEN("pattern <- stripe_pattern(white, black)")
|
||||
{
|
||||
StripePattern pattern(Color::White(), Color::Black());
|
||||
AND_GIVEN("set_pattern_transform(pattern, translation(0.5, 0, 0)))")
|
||||
{
|
||||
pattern.set_pattern_transform(Matrix::translation(0.5, 0, 0));
|
||||
WHEN("c <- stripe_at_object(pattern, object, point(2.5, 0, 0))")
|
||||
{
|
||||
Color c = pattern.stripe_at_object(&object, Tuple::Point(1.5, 0, 0));
|
||||
THEN("c = white")
|
||||
{
|
||||
REQUIRE(c == Color::White());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user