Beispiel #1
0
 def test_add(self):
     u = Vec3(2.0, 3.0, 5.0)
     v = Vec3(-1.0, 5.0, -2.0)
     res = u + v
     self.assertVec3Equal(res, Vec3(1.0, 8.0, 3.0))
     u += v
     self.assertVec3Equal(u, Vec3(1.0, 8.0, 3.0))
Beispiel #2
0
 def test_sub(self):
     u = Vec3(2.0, 3.0, 5.0)
     v = Vec3(-1.0, 5.0, -2.0)
     res = u - v
     self.assertVec3Equal(res, Vec3(3.0, -2.0, 7.0))
     u -= v
     self.assertVec3Equal(u, Vec3(3.0, -2.0, 7.0))
Beispiel #3
0
 def test_mul(self):
     u = Vec3(2.0, -3.0, 5.0)
     res = u * 2
     self.assertVec3Equal(res, Vec3(4.0, -6.0, 10.0))
     res = 2 * u
     self.assertVec3Equal(res, Vec3(4.0, -6.0, 10.0))
     u *= 2
     self.assertVec3Equal(u, Vec3(4.0, -6.0, 10.0))
Beispiel #4
0
    def test_from_3vec3(self):
        v1 = Vec3(1.0, 2.0, -1.0)
        v2 = Vec3(-3.0, 4.0, 2.0)
        v3 = Vec3(7.0, 3.0, 3.0)

        m = Mat44()
        m.set_from_3vec3(v1, v2, v3)

        self.assertMat44Equal(
            m,
            Mat44([[1.0, 2.0, -1.0, 0.0], [-3.0, 4.0, 2.0, 0.0],
                   [7.0, 3.0, 3.0, 0.0], [0.0, 0.0, 0.0, 1.0]]))
Beispiel #5
0
 def test_translation(self):
     v = Vec3(-3.0, 4.0, 2.0)
     m = Mat44()
     m.set_translation(v)
     self.assertMat44Equal(
         m,
         Mat44([[1.0, 0.0, 0.0, -3.0], [0.0, 1.0, 0.0, 4.0],
                [0.0, 0.0, 1.0, 2.0], [0.0, 0.0, 0.0, 1.0]]))
Beispiel #6
0
 def test_rotation(self):
     n = Vec3(1.0, 1.0, 1.0)
     n.normalize()
     m = Mat44()
     m.set_rotation(n, 2 * pi / 3)
     self.assertMat44Equal(
         m,
         Mat44([[0.0, 0.0, 1.0, 0.0], [1.0, 0.0, 0.0, 0.0],
                [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 0.0, 1.0]]))
Beispiel #7
0
 def test_scale(self):
     m = Mat44()
     m.set_scale(1.5)
     self.assertMat44Equal(
         m,
         Mat44([[1.5, 0.0, 0.0, 0.0], [0.0, 1.5, 0.0, 0.0],
                [0.0, 0.0, 1.5, 0.0], [0.0, 0.0, 0.0, 1.0]]))
     m.set_scale(Vec3(1.5, 2.0, 2.5))
     self.assertMat44Equal(
         m,
         Mat44([[1.5, 0.0, 0.0, 0.0], [0.0, 2.0, 0.0, 0.0],
                [0.0, 0.0, 2.5, 0.0], [0.0, 0.0, 0.0, 1.0]]))
Beispiel #8
0
 def test_rotate(self):
     u = Vec3(1.0, 0.0, 0.0)
     n = Vec3(1.0, 1.0, 1.0)
     n.normalize()
     u.rotate(n, 2 * pi / 3)
     self.assertVec3Equal(u, Vec3(0.0, 1.0, 0.0))
Beispiel #9
0
 def test_dot(self):
     u = Vec3(2.0, 3.0, 5.0)
     v = Vec3(-1.0, 5.0, -2.0)
     res = Vec3.dot(u, v)
     self.assertEqual(res, 3.0)
Beispiel #10
0
 def test_invert(self):
     u = Vec3(2.0, -3.0, 5.0)
     u.invert()
     self.assertVec3Equal(u, Vec3(-2.0, 3.0, -5.0))
Beispiel #11
0
 def test_copy(self):
     u = Vec3(2.0, -3.0, 5.0)
     v = u.copy()
     self.assertVec3Equal(u, v)
     v[1] = 1.0
     self.assertNotEqual(u[1], v[1])
Beispiel #12
0
 def test_normalize(self):
     u = Vec3(-3.0, 0.0, 4.0)
     u.normalize()
     self.assertVec3Equal(u, Vec3(-0.6, 0.0, 0.8))
Beispiel #13
0
 def test_norm(self):
     u = Vec3(2.0, -3.0, 5.0)
     res = u.norm()
     self.assertEqual(res, 38.0**0.5)
Beispiel #14
0
 def test_cross(self):
     u = Vec3(2.0, 3.0, 5.0)
     v = Vec3(-1.0, 5.0, -2.0)
     res = Vec3.cross(u, v)
     self.assertVec3Equal(res, Vec3(-31.0, -1.0, 13.0))
Beispiel #15
0
 def test_mul_dir(self):
     v = Vec3(-0.6, 0.0, 0.8)
     m = Mat44([[1.0, 2.0, -1.0, 5.0], [-3.0, 4.0, 2.0, 0.0],
                [7.0, 3.0, 3.0, -5.0], [0.0, -4.0, 1.0, -2.0]])
     res = m.mul_dir(v)
     self.assertVec3Equal(res, Vec3(-1.4, 3.4, -1.8))
Beispiel #16
0
 def test_mul_pos(self):
     v = Vec3(-3.0, 4.0, 2.0)
     m = Mat44([[1.0, 2.0, -1.0, 5.0], [-3.0, 4.0, 2.0, 0.0],
                [7.0, 3.0, 3.0, -5.0], [0.0, -4.0, 1.0, -2.0]])
     res = m.mul_pos(v)
     self.assertVec3Equal(res, Vec3(-0.5, -1.8125, 0.5))