Add transformation to objects.

This commit is contained in:
Godzil
2020-02-17 14:15:55 +00:00
parent b799e5f819
commit 00b283053e
5 changed files with 107 additions and 4 deletions

View File

@@ -7,6 +7,8 @@
*
*/
#include <ray.h>
#include <transformation.h>
#include <object.h>
#include <gtest/gtest.h>
@@ -29,4 +31,34 @@ TEST(RayTest, Computing_a_point_from_a_distance)
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));
}
TEST(RayTest, Translating_a_ray)
{
Ray r = Ray(Point(1, 2, 3), Vector(0, 1, 0));
Matrix m = translation(3, 4, 5);
Object o = Object();
o.setTransform(m);
Ray r2 = o.transform(r);
ASSERT_EQ(r2.origin, Point(4, 6, 8));
ASSERT_EQ(r2.direction, Vector(0, 1, 0));
}
TEST(RayTest, Scaling_a_ray)
{
Ray r = Ray(Point(1, 2, 3), Vector(0, 1, 0));
Matrix m = scaling(2, 3, 4);
Object o = Object();
o.setTransform(m);
Ray r2 = o.transform(r);
ASSERT_EQ(r2.origin, Point(2, 6, 12));
ASSERT_EQ(r2.direction, Vector(0, 3, 0));
}