Ejemplo n.º 1
0
    def test_intersect(self):
        sphere1 = Sphere(Vector3f(2.0, 0.0, 0.0), 1)
        sphere2 = Sphere(Vector3f(-2.0, 0.0, 0.0), 1)

        self.assertEqual(sphere1.intersect(Vector3f(0, 0, 0), Vector3f(1, 0, 0)), 1.0)
        self.assertEqual(sphere1.intersect(Vector3f(0, 0, 0), Vector3f(0, 1, 0)), "NONE")

        self.assertEqual(sphere2.intersect(Vector3f(0, 0, 0), Vector3f(1, 0, 0)), "NONE")
Ejemplo n.º 2
0
class TestSphere(TestRenderablePrimitive):

    def setUp(self):
        self.renderable = Sphere()
        self.renderable2 = Sphere()

    def test_interface(self):
        super(TestSphere, self).test_interface()
        for func in ['setRadius']:
            self.assertTrue(hasattr(self.renderable, func) and callable(getattr(self.renderable, func)), "Interface requires function: " + func)

    def test_intersect(self):
        sphere1 = Sphere(Vector3f(2.0, 0.0, 0.0), 1)
        sphere2 = Sphere(Vector3f(-2.0, 0.0, 0.0), 1)

        self.assertEqual(sphere1.intersect(Vector3f(0, 0, 0), Vector3f(1, 0, 0)), 1.0)
        self.assertEqual(sphere1.intersect(Vector3f(0, 0, 0), Vector3f(0, 1, 0)), "NONE")

        self.assertEqual(sphere2.intersect(Vector3f(0, 0, 0), Vector3f(1, 0, 0)), "NONE")

    def test_normalAt(self):
        sphere1 = Sphere(Vector3f(2.0, 0.0, 0.0), 1)

        self.assertEqual(sphere1.normalAt(Vector3f(1, 0, 0)).toList(), [-1, 0, 0])
        self.assertEqual(sphere1.normalAt(Vector3f(1, 0.1, 0)).toList(), Vector3f(-1, 0.1, 0.0).toList())
        self.assertEqual(sphere1.normalAt(Vector3f(5, 0, 0)).toList(), [3, 0, 0])

    def test_setRadius(self):
        self.assertEqual(self.renderable.setRadius(1.0), 1.0)
        self.assertEqual(self.renderable.setRadius(0.0), 1.0)
        self.assertEqual(self.renderable.setRadius(-1.0), 1.0)
        self.assertEqual(self.renderable.setRadius(1.1), 1.1)
        self.assertEqual(self.renderable.setRadius(0.0005), 0.0005)
        self.assertEqual(self.renderable.setRadius(), 0.0005)
        self.assertEqual(self.renderable.setRadius(1), 1.0)
Ejemplo n.º 3
0
 def test_integration_renderComplexScene(self):
     self.raytracer.setOutput('test_integration_renderComplexScene.png', 300, 300)
     self.raytracer.setAmbient([0.2, 0.2, 0.2])
     sph1 = Sphere(Vector3f(0.0, 1.0, 0.0), 0.5)
     sph2 = Sphere(Vector3f(-1.0, 1.0, 0.0), 0.4)
     sph3 = Sphere(Vector3f(0.2, -1.0, 1.2), 0.5)
     sph4 = Sphere(Vector3f(1.0, -1.0, -1.0), 0.3)
     sph5 = Sphere(Vector3f(-1.0, -1.0, -1.0), 0.3)
     sph1.setDiffuseColor([0.8, 0.0, 0.0])
     sph2.setDiffuseColor([1.0, 1.0, 1.0])
     sph2.setDiffuseConstant(0.5)
     sph3.setDiffuseColor([0.0, 0.0, 0.8])
     sph3.setShininess(20)
     sph4.setSpecularColor([0.0, 1.0, 0.0])
     sph5.setDiffuseColor([1.0, 0.0, 1.0])
     sph5.setShininess(200)
     self.raytracer.addPrimitive(sph1)
     self.raytracer.addPrimitive(sph2)
     self.raytracer.addPrimitive(sph3)
     self.raytracer.addPrimitive(sph4)
     self.raytracer.addPrimitive(sph5)
     self.raytracer.addPointLight(Vector3f(1.0,-4.0,1.0), [1.0, 1.0, 1.0], 2)
     self.raytracer.setCamera(Vector3f(0.0, -6.0, 0.0), Vector3f(0.0, 1.0, 0.0), Vector3f(0.0, 0.0, 1.0), 70)
     start = time()
     self.raytracer.render()
     end = time()
     self.assertTrue(os.path.exists('./test_integration_renderComplexScene.png'), "The file wasn't created upon rendering")
     print "Rendered a 300 * 300 image with 4 spheres and 1 light in {} seconds".format(end - start)
Ejemplo n.º 4
0
 def setUp(self):
     self.renderable = Sphere()
     self.renderable2 = Sphere()
Ejemplo n.º 5
0
    def test_normalAt(self):
        sphere1 = Sphere(Vector3f(2.0, 0.0, 0.0), 1)

        self.assertEqual(sphere1.normalAt(Vector3f(1, 0, 0)).toList(), [-1, 0, 0])
        self.assertEqual(sphere1.normalAt(Vector3f(1, 0.1, 0)).toList(), Vector3f(-1, 0.1, 0.0).toList())
        self.assertEqual(sphere1.normalAt(Vector3f(5, 0, 0)).toList(), [3, 0, 0])