def test_repr(self): mat = Matrix4(IDENTITY) v = repr(mat) self.assertGreater(len(v), 10) self.assertIn("Matrix4", v) mat = Matrix4([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) v = repr(mat) self.assertGreater(len(v), 20) self.assertIn("Matrix4", v) mat = Matrix4(ZEROS_16) v = repr(mat) self.assertGreater(len(v), 10) self.assertIn("Matrix4", v)
def render(self, time, frametime): ortho = Matrix4.orthogonal_projection(0, self.window_size[0], 0, self.window_size[1]) self.renderer.render_string("%.2f" % time, 100, 100, 1, mvp=ortho) self.renderer.render_string("Приветик!", 100, 200, 1, mvp=ortho) if time > 30: raise Exit()
def test_inverse(self): mat = Matrix4([ 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, -10.0, 1.0, ]) self.assertEqual(mat * mat.inverse(), Matrix4(IDENTITY))
def test_look_at(self): res = Matrix4([ 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, -10.0, 1.0, ]) self.assertEqual( Matrix4.look_at(IVec(10, 0, 0), IVec(0, 0, 0), IVec(0, 0, 1)), res)
def test_scale_matrix(self): m = Matrix4.scale_matrix(3) v = m * IVec(1, 0, 0) self.assertEqual(v, IVec(3, 0, 0, 1))
def test_translation_matrix(self): m = Matrix4.translation_matrix(10, 5, 2) v = m * IVec(0, 0, 0, 1) self.assertEqual(v, IVec(10, 5, 2, 1))
def test_bytes(self): mat = Matrix4(IDENTITY) b = mat.bytes() self.assertIsInstance(b, bytes) self.assertGreater(len(b), 15)
def test_multiply_notimpl(self): mat = Matrix4(ZEROS_16) with self.assertRaises(TypeError): 1 * mat with self.assertRaises(TypeError): mat * 1
def test_multiply_vector(self): mat = Matrix4(IDENTITY) vec = MVec(1, 2, 3, 1) self.assertEqual(mat * vec, vec)
def test_multiply_identity(self): mat1 = Matrix4(IDENTITY) mat2 = Matrix4(IDENTITY) mat3 = Matrix4(IDENTITY) self.assertEqual(mat1 * mat2, mat3)
def test_str(self): mat = Matrix4(IDENTITY) v = mat.__str__() self.assertGreater(len(v), 20)