-
Notifications
You must be signed in to change notification settings - Fork 0
/
world_test.cpp
39 lines (36 loc) · 1.39 KB
/
world_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <gtest/gtest.h>
#include "intersection.cpp"
#include "world.cpp"
TEST(World, IntersectPositive) {
Vector pos = Vector(0.f, 0.f, -4.f);
Vector dir = Vector(0.f, 0.f, 1.f);
Ray ray = Ray(pos, dir, T_MIN, T_MAX);
Sphere sphere = Sphere(Vector(0.f, 0.f, 0.f), 0.15f);
World world;
world.spheres.push_back(sphere);
Intersection intersection = Intersection();
ASSERT_TRUE(world.intersect(ray, intersection));
}
TEST(World, IsVisiblePositive) {
World world;
world.spheres.push_back(Sphere(Vector(0.f, 0.f, 0.f), 0.15f));
world.lights.push_back(Light(Vector(0.f, 5.f, 0.f), Color(1.f, 1.f, 1.f)));
Vector eye = Vector(0.f, 0.f, 0.f);
Vector lookAt = Vector(0.f, 0.f, -1.f);
Ray cameraRay = Ray(eye, lookAt, T_MIN, T_MAX);
Intersection intersection = Intersection();
world.intersect(cameraRay, intersection);
ASSERT_TRUE(world.isVisible(intersection));
}
TEST(World, IsVisibleNegative) {
World world;
world.spheres.push_back(Sphere(Vector(0.f, 0.f, 0.f), 0.15f));
world.spheres.push_back(Sphere(Vector(0.f, 1.f, 0.f), 0.15f));
world.lights.push_back(Light(Vector(0.f, 5.f, 0.f), Color(1.f, 1.f, 1.f)));
Vector eye = Vector(0.f, 0.f, 0.f);
Vector lookAt = Vector(0.f, 0.f, -1.f);
Ray cameraRay = Ray(eye, lookAt, T_MIN, T_MAX);
Intersection intersection = Intersection();
world.intersect(cameraRay, intersection);
ASSERT_FALSE(world.isVisible(intersection));
}