コード例 #1
0
ファイル: test_vec3.py プロジェクト: beep39/pymikuvr
    def test_initialization_and_value_set(self):
        a = vec3()
        self.assertEqual(a.x, 0)
        self.assertEqual(a.y, 0)
        self.assertEqual(a.z, 0)

        b = vec3(1,2,3)
        self.assertEqual(b.x, 1)
        self.assertEqual(b.y, 2)
        self.assertEqual(b.z, 3)

        c = vec3(b)
        self.assertFalse(c is b)
        self.assertEqual(b, c)

        d = vec3(b)
        self.assertFalse(d is b)
        self.assertEqual(d, b)

        e = vec3()
        e.set(1,2,3)
        self.assertEqual(e, b)

        f = e.copy()
        self.assertFalse(f is e)
        self.assertEqual(f, e)
コード例 #2
0
ファイル: test_vec3.py プロジェクト: beep39/pymikuvr
 def test_tend(self):
     a = vec3(-1,2,3)
     diff = vec3(3,6,2) # length is 12
     b = a + diff
     self.assertAlmostEqual(vec3.tend(a, b, 0), a)
     self.assertAlmostEqual(vec3.tend(a, b, diff.length()), b)
     self.assertAlmostEqual(vec3.tend(a, b, diff.length() * 0.5), (a + b) / 2)
     self.assertAlmostEqual(vec3.tend(a, a, 0), a)
     self.assertAlmostEqual(vec3.tend(a, a, 100), a)
コード例 #3
0
ファイル: test_vec3.py プロジェクト: beep39/pymikuvr
    def test_cross_order(self):

        # right-handed coordinate system
        
        a = vec3(1,0,0)
        b = vec3(0,1,0)
        c = vec3(0,0,1)
        self.assertAlmostEqual(vec3.cross(a, b), c) 
        self.assertAlmostEqual(vec3.cross(c, a), b) 
        self.assertAlmostEqual(vec3.cross(b, c), a) 
        self.assertAlmostEqual(vec3.cross(vec3.right, vec3.forward), vec3.up)
コード例 #4
0
ファイル: test_vec3.py プロジェクト: beep39/pymikuvr
    def test_length_and_normalize(self):
        a = vec3(1,2,3)
        b = vec3(1,2,3)
        c = vec3()
        d = vec3(3,2,6)

        self.assertAlmostEqual(c.length(), 0)
        self.assertAlmostEqual(d.length(), 7)

        #static
        self.assertAlmostEqual(vec3.normalize(a).length(), 1)
        self.assertEqual(a, b) #unchanged

        #instance
        self.assertAlmostEqual(a.normalize().length(), 1)
        self.assertAlmostEqual(a.length(), 1) #normalized

        #zero length
        self.assertAlmostEqual(c.normalize().length(), 0)
コード例 #5
0
 def path(self, pos_from, pos_to):
     count = c_lib.navigation_path(self.__id, pos_from.x, pos_from.y,
                                   pos_from.z, pos_to.x, pos_to.y, pos_to.z,
                                   path_data, max_path)
     if count <= 0:
         return None
     result = []
     for i in range(0, count * 3, 3):
         result.append(
             vec3(path_data[i], path_data[i + 1], path_data[i + 2]))
     return result
コード例 #6
0
ファイル: test_quat.py プロジェクト: beep39/pymikuvr
    def test_multiply(self):
        a = vec3(1, 2, 3)
        self.assertAlmostEqual(quat() * a, a)
        self.assertAlmostEqual(a * quat(), a)

        self.assertAlmostEqual(quat.from_pyr(90, 0, 0) * vec3.forward, vec3.up)
        self.assertAlmostEqual(vec3.up * quat.from_pyr(90, 0, 0), vec3.forward)

        b = quat.from_pyr(10, 20, 30)
        c = quat.from_pyr(-40, 50, -60)

        self.assertAlmostEqual(b * (c * a), (b * c) * a)
        self.assertAlmostEqual((a * b) * c, a * (b * c))
コード例 #7
0
ファイル: test_quat.py プロジェクト: beep39/pymikuvr
    def test_invert(self):
        a = quat.from_pyr(10, 20, 30)
        b = quat(a)

        #static
        quat.invert(a)
        self.assertEqual(a, b)  #unchanged

        #instance
        self.assertAlmostEqual(a.invert(), quat.invert(b))
        self.assertAlmostEqual(a, quat.invert(b))

        self.assertAlmostEqual(quat.invert(quat()), quat())

        self.assertAlmostEqual(a * quat.invert(a), quat())
        self.assertAlmostEqual(a * (quat.invert(a) * b), b)

        c = vec3(1, 2, 3)
        self.assertAlmostEqual(quat.invert(a) * c, c * a)
コード例 #8
0
ファイル: test_vec3.py プロジェクト: beep39/pymikuvr
 def test_arifmetic(self):
     a = vec3(1,2,3)
     a2 = vec3(1*2,2*2,3*2)
     b = vec3(-4,5,-6)
     self.assertAlmostEqual(a + b - a, b)
     self.assertAlmostEqual(-a + b + a, b)
     self.assertAlmostEqual(a * b / a, b)
     self.assertAlmostEqual(a / 1, a)
     self.assertAlmostEqual(a / 2, vec3(a.x / 2, a.y / 2, a.z / 2))
     self.assertAlmostEqual(a * 1, a)
     self.assertAlmostEqual(a * 0, vec3())
     self.assertAlmostEqual(a * 2, a2)
     self.assertAlmostEqual(0 * a, vec3())
     self.assertEqual(1 * a, a)
     self.assertEqual(2 * a, a2)
コード例 #9
0
ファイル: test_quat.py プロジェクト: beep39/pymikuvr
    def test_rot_direction(self):

        # https://github.com/beep39/pymikuvr/wiki/Coordinate-system

        self.assertAlmostEqual(
            quat.from_pyr(90, 0, 0) * vec3(0, 1, 0), vec3(0, 0, 1))
        self.assertAlmostEqual(
            quat.from_pyr(0, 0, 90) * vec3(1, 0, 0), vec3(0, 1, 0))
        self.assertAlmostEqual(
            quat.from_pyr(0, 90, 0) * vec3(0, 0, 1), vec3(1, 0, 0))

        self.assertAlmostEqual(quat.from_pyr(90, 0, 0) * vec3.forward, vec3.up)
        self.assertAlmostEqual(quat.from_pyr(0, 0, 90) * vec3.right, vec3.up)
        self.assertAlmostEqual(
            quat.from_pyr(0, 90, 0) * vec3.right, vec3.forward)
コード例 #10
0
ファイル: test_transform.py プロジェクト: beep39/pymikuvr
    def test_posrot(self):
        v = vec3(1, 2, 3)
        q = quat.from_pyr(10, 20, 30)

        a = transform()
        a.pos.set(v.x, v.y, v.z)
        self.assertAlmostEqual(a.pos, v)
        self.assertAlmostEqual(a.local_pos, v)
        a.rot.set(q.x, q.y, q.z, q.w)
        self.assertAlmostEqual(a.rot, q)
        self.assertAlmostEqual(a.local_rot, q)

        b = transform()
        b.pos = v
        self.assertAlmostEqual(b.pos, v)
        self.assertAlmostEqual(b.local_pos, v)
        b.rot = q
        self.assertAlmostEqual(b.rot, q)
        self.assertAlmostEqual(b.local_rot, q)

        c = transform()
        c.local_pos.set(v.x, v.y, v.z)
        self.assertAlmostEqual(c.pos, v)
        self.assertAlmostEqual(c.local_pos, v)
        c.local_rot.set(q.x, q.y, q.z, q.w)
        self.assertAlmostEqual(c.rot, q)
        self.assertAlmostEqual(c.local_rot, q)

        d = transform()
        d.local_pos = v
        self.assertAlmostEqual(d.pos, v)
        self.assertAlmostEqual(d.local_pos, v)
        d.local_rot = q
        self.assertAlmostEqual(d.rot, q)
        self.assertAlmostEqual(d.local_rot, q)

        gc.collect()
コード例 #11
0
 def update():
     s = vec3(source.x, 0, -source.y)
     l = s.length()
     if l > 1:
         s /= l
     t.pos += head.rot * s * (system.dt * speed)
コード例 #12
0
ファイル: test_transform.py プロジェクト: beep39/pymikuvr
    def test_hierarchy(self):
        v = vec3(1, 2, 3)
        v2 = vec3(4, 5, 6)

        a = transform()
        a.parent = None
        with self.assertRaises(ValueError) as context:
            a.parent = a
        self.assertEqual(a.parent, None)
        self.assertEqual(len(a.children), 0)

        b = transform()
        b.pos = v
        c = transform()
        c.pos = v2
        self.assertAlmostEqual(b.local_pos, v)
        c.parent = b
        self.assertEqual(c.parent, b)
        self.assertEqual(len(b.children), 1)
        self.assertEqual(b.children[0], c)
        self.assertAlmostEqual(b.local_pos, v)
        self.assertAlmostEqual(b.pos, v)
        self.assertAlmostEqual(c.pos, v2)
        c.parent = None
        self.assertEqual(c.parent, None)
        self.assertEqual(len(b.children), 0)

        c.parent = b
        c.parent = b
        with self.assertRaises(ValueError) as context:
            b.parent = c
        self.assertEqual(b.parent, None)
        self.assertEqual(c.parent, b)
        self.assertEqual(len(b.children), 1)
        self.assertEqual(b.children[0], c)

        c.parent = None
        self.assertEqual(c.parent, None)
        self.assertEqual(len(b.children), 0)

        d = transform()
        d.pos = v
        e = transform()
        e.pos = v2
        e.add_child(d)
        self.assertEqual(d.parent, e)
        self.assertAlmostEqual(d.local_pos, vec3())
        self.assertAlmostEqual(d.pos, e.pos)

        d.set_parent(None)
        self.assertEqual(d.parent, None)
        self.assertAlmostEqual(d.pos, e.pos)

        d.set_parent(e)
        self.assertEqual(d.parent, e)
        self.assertAlmostEqual(d.local_pos, vec3())
        self.assertAlmostEqual(d.pos, e.pos)

        f = transform()
        f.pos = v
        g = transform()
        g.pos = v2
        g.set_parent(f, False)
        self.assertAlmostEqual(g.local_pos, v2 - v)
        self.assertAlmostEqual(f.pos, v)

        gc.collect()
コード例 #13
0
 def farthest(self, pos, dir, radius):
     if c_lib.navigation_farthest_point(self.__id, pos.x, pos.y, pos.z,
                                        dir.x, dir.z, radius, tmp_xp,
                                        tmp_yp, tmp_zp):
         return vec3(tmp_x.value, tmp_y.value, tmp_z.value)
     return None
コード例 #14
0
 def nearest(self, pos, radius=1):
     if c_lib.navigation_nearest_point(self.__id, pos.x, pos.y, pos.z,
                                       radius, tmp_xp, tmp_yp, tmp_zp):
         return vec3(tmp_x.value, tmp_y.value, tmp_z.value)
     return None
コード例 #15
0
ファイル: test_vec3.py プロジェクト: beep39/pymikuvr
 def test_lerp(self):
     a = vec3(1,2,3)
     b = vec3(-4,5,-6)
     self.assertAlmostEqual(vec3.lerp(a, b, 0), a)
     self.assertAlmostEqual(vec3.lerp(a, b, 1), b)
     self.assertAlmostEqual(vec3.lerp(a, b, 0.5), (a + b) / 2)
コード例 #16
0
ファイル: test_vec3.py プロジェクト: beep39/pymikuvr
 def test_eq(self):
     a = vec3(1,2,3)
     b = vec3(1,2,3)
     c = vec3()
     self.assertTrue(a==b)
     self.assertFalse(b==c)