コード例 #1
0
ファイル: tests.py プロジェクト: jacrocitto/RayCaster
 def test_determine_diffuse_contribution(self):
     sphere = data.Sphere(data.Point(0, 0, 0), 1, data.Color(0.5, 0.7, 0.8), data.Finish(0.5, 0.5, 0.5, 0.05))
     light = data.Light(data.Point(0, 0, 100), data.Color(1.5, 1.2, 1.3))
     inter_point = data.Point(0, 0, 1)
     inter_list = [
         (
             data.Sphere(data.Point(0, 0, 102), 1, data.Color(0.5, 0.7, 0.8), data.Finish(0.5, 0.5, 0.5, 0.05)),
             data.Point(0, 0, 101),
         )
     ]
     normal = collisions.sphere_normal_at_point(sphere, inter_point)
     off_pt = cast.find_pt_off_sphere(inter_point, normal)
     dir_vect = vector_math.normalize_vector(vector_math.vector_from_to(off_pt, light.pt))
     ray = data.Ray(off_pt, dir_vect)
     sphere_list = []
     l_dir = vector_math.normalize_vector(vector_math.vector_from_to(off_pt, light.pt))
     l_dot_n = vector_math.dot_vector(normal, l_dir)
     result = cast.determine_diffuse_contribution(sphere, off_pt, light, normal, sphere_list, l_dir, l_dot_n)
     self.assertEqual(
         result[0], cast.get_diffuse_contribution(sphere, light, ray, inter_list, normal, dir_vect, off_pt)[0]
     )
     self.assertEqual(
         result[1], cast.get_diffuse_contribution(sphere, light, ray, inter_list, normal, dir_vect, off_pt)[1]
     )
     self.assertEqual(
         result[2], cast.get_diffuse_contribution(sphere, light, ray, inter_list, normal, dir_vect, off_pt)[2]
     )
コード例 #2
0
ファイル: tests.py プロジェクト: jacrocitto/RayCaster
 def test_cast_ray_1(self):
     ray = data.Ray(data.Point(0, 10, 6), data.Vector(0, 0, -2))
     sphere_list = [
         data.Sphere(data.Point(0, 10, -2), 3, data.Color(0, 0.5, 1.0), data.Finish(0.5, 0.4, 0.5, 0.05)),
         data.Sphere(data.Point(0, 10, -20), 0.5, data.Color(0, 0.3, 0.2), data.Finish(0.5, 0.4, 0.5, 0.05)),
     ]
     ambient_color = data.Color(0.25, 0.5, 0.75)
     light = data.Light(data.Point(-100.0, 100.0, -100.0), data.Color(1.5, 1.5, 1.5))
     eye_position = data.Point(0, 0, -14)
     cr = cast.cast_ray(ray, sphere_list, ambient_color, light, eye_position)
     inter_point = collisions.sphere_intersection_point(ray, sphere_list[0])
     normal = collisions.sphere_normal_at_point(sphere_list[0], inter_point)
     off_pt = cast.find_pt_off_sphere(inter_point, normal)
     l_dir = vector_math.normalize_vector(vector_math.vector_from_to(off_pt, light.pt))
     l_dot_n = vector_math.dot_vector(normal, l_dir)
     diffuse_list = cast.determine_diffuse_contribution(
         sphere_list[0], off_pt, light, normal, sphere_list, l_dir, l_dot_n
     )
     spec_list = cast.determine_specular_contribution(
         l_dir, l_dot_n, normal, eye_position, off_pt, light.color, sphere_list[0].finish
     )
     self.assertEqual(
         cr,
         data.Color(
             0 + diffuse_list[0] + spec_list[0],
             0.125 + diffuse_list[1] + spec_list[1],
             0.375 + diffuse_list[2] + spec_list[2],
         ),
     )
コード例 #3
0
ファイル: tests.py プロジェクト: jacrocitto/RayCaster
 def test_get_diffuse_contribution(self):
     sphere = data.Sphere(data.Point(0, 0, 0), 1, data.Color(0.5, 0.7, 0.8), data.Finish(0.5, 0.5, 0.5, 0.05))
     light = data.Light(data.Point(0, 0, 100), data.Color(1.5, 1.2, 1.3))
     inter_point = data.Point(0, 0, 1)
     normal = collisions.sphere_normal_at_point(sphere, inter_point)
     inter_list = []
     off_pt = cast.find_pt_off_sphere(inter_point, normal)
     dir_vect = vector_math.normalize_vector(vector_math.vector_from_to(off_pt, light.pt))
     ray = data.Ray(off_pt, dir_vect)
     result = cast.get_diffuse_contribution(sphere, light, ray, inter_list, normal, dir_vect, off_pt)
     self.assertEqual(result[0], (vector_math.dot_vector(normal, dir_vect) * 1.5 * 0.5 * 0.5))
     self.assertEqual(result[1], (vector_math.dot_vector(normal, dir_vect) * 1.2 * 0.7 * 0.5))
     self.assertEqual(result[2], (vector_math.dot_vector(normal, dir_vect) * 1.3 * 0.8 * 0.5))
コード例 #4
0
ファイル: tests.py プロジェクト: jacrocitto/RayCaster
 def test_find_pt_off_sphere_again(self):
     sphere = data.Sphere(data.Point(1, 6, 2), 2, data.Color(1, 1, 1), data.Finish(0.2, 0.7, 0.5, 0.05))
     point = data.Point(1, 8, 2)
     normal = collisions.sphere_normal_at_point(sphere, point)
     off_pt = cast.find_pt_off_sphere(point, normal)
     self.assertEqual(off_pt, data.Point(1, 8.01, 2))
コード例 #5
0
ファイル: tests.py プロジェクト: jacrocitto/RayCaster
 def test_find_pt_off_sphere(self):
     sphere = data.Sphere(data.Point(0, 0, 0), 1, data.Color(0, 0, 0), data.Finish(0.5, 0.5, 0.5, 0.05))
     point = data.Point(0, 0, 1)
     normal = collisions.sphere_normal_at_point(sphere, point)
     off_pt = cast.find_pt_off_sphere(point, normal)
     self.assertEqual(off_pt, data.Point(0, 0, 1.01))