コード例 #1
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],
         ),
     )
コード例 #2
0
ファイル: tests.py プロジェクト: jacrocitto/RayCaster
 def test_determine_specular_contribution(self):
     l_dir = data.Vector(1, 0, 0)
     l_dot_n = 0
     normal = data.Vector(0, 1, 0)
     eye_position = data.Point(3, 3, 3)
     off_pt = data.Point(4, 4, 4)
     light_color = data.Color(0.5, 0.2, 0.7)
     finish = data.Finish(0.5, 0.5, 0.5, 0.5)
     result = cast.determine_specular_contribution(l_dir, l_dot_n, normal, eye_position, off_pt, light_color, finish)
     self.assertAlmostEqual(result[0], 0.0833333)
     self.assertAlmostEqual(result[1], 0.0333333)
     self.assertAlmostEqual(result[2], 0.11666666)