Esempio n. 1
0
    def test_procedural_examples(self):
        from pyrr import quaternion, matrix44, vector3
        import numpy as np

        point = vector3.create(1.,2.,3.)
        orientation = quaternion.create()
        translation = vector3.create()
        scale = vector3.create(1,1,1)

        # translate along X by 1
        translation += [1.0, 0.0, 0.0]

        # rotate about Y by pi/2
        rotation = quaternion.create_from_y_rotation(np.pi / 2.0)
        orientation = quaternion.cross(rotation, orientation)

        # create a matrix
        # start our matrix off using the scale
        matrix = matrix44.create_from_scale(scale)

        # apply our orientation
        orientation = matrix44.create_from_quaternion(orientation)
        matrix = matrix44.multiply(matrix, orientation)

        # apply our translation
        translation_matrix = matrix44.create_from_translation(translation)
        matrix = matrix44.multiply(matrix, translation_matrix)

        # transform our point by the matrix
        point = matrix44.apply_to_vector(matrix, point)
Esempio n. 2
0
    def test_procedural_examples(self):
        from pyrr import quaternion, matrix44, vector3
        import numpy as np

        point = vector3.create(1.,2.,3.)
        orientation = quaternion.create()
        translation = vector3.create()
        scale = vector3.create(1,1,1)

        # translate along X by 1
        translation += [1.0, 0.0, 0.0]

        # rotate about Y by pi/2
        rotation = quaternion.create_from_y_rotation(np.pi / 2.0)
        orientation = quaternion.cross(rotation, orientation)

        # create a matrix
        # start our matrix off using the scale
        matrix = matrix44.create_from_scale(scale)

        # apply our orientation
        orientation = matrix44.create_from_quaternion(orientation)
        matrix = matrix44.multiply(matrix, orientation)

        # apply our translation
        translation_matrix = matrix44.create_from_translation(translation)
        matrix = matrix44.multiply(matrix, translation_matrix)

        # transform our point by the matrix
        point = matrix44.apply_to_vector(matrix, point)
Esempio n. 3
0
    def test_decompose(self):
        # define expectations
        expected_scale = vector3.create(*[1, 1, 2], dtype='f4')
        expected_rotation = quaternion.create_from_y_rotation(np.pi, dtype='f4')
        expected_translation = vector3.create(*[10, 0, -5], dtype='f4')
        expected_model = np.array([
            [-1, 0, 0, 0],
            [0, 1, 0, 0],
            [0, 0, -2, 0],
            [10, 0, -5, 1],
        ], dtype='f4')

        # compose matrix using Pyrr
        s = matrix44.create_from_scale(expected_scale, dtype='f4')
        r = matrix44.create_from_quaternion(expected_rotation, dtype='f4')
        t = matrix44.create_from_translation(expected_translation, dtype='f4')
        model = s.dot(r).dot(t)
        np.testing.assert_almost_equal(model, expected_model)
        self.assertTrue(model.dtype == expected_model.dtype)

        # decompose matrix
        scale, rotation, translation = matrix44.decompose(model)
        np.testing.assert_almost_equal(scale, expected_scale)
        self.assertTrue(scale.dtype == expected_scale.dtype)
        np.testing.assert_almost_equal(rotation, expected_rotation)
        self.assertTrue(rotation.dtype == expected_rotation.dtype)
        np.testing.assert_almost_equal(translation, expected_translation)
        self.assertTrue(translation.dtype == expected_translation.dtype)
Esempio n. 4
0
	def GetWorldMatrix(self):
		if self.worldMatrix is None or self.isDirty:
			self.isDirty = False
			translation = matrix44.create_from_translation(vector3.create(self.position[0], self.position[1], 0.0))
			rotation = matrix44.create_from_z_rotation(self.rotation)
			self.worldMatrix = matrix44.multiply(rotation, translation)

		return self.worldMatrix
    def rotateAboutOrigin(self, xyz, t, p):
        rp = p - math.pi / 2
        rt = -t

        q1 = quaternion.create_from_z_rotation(rp)
        q2 = quaternion.create_from_x_rotation(rt)
        v = vector3.create(xyz[0], xyz[1], xyz[2])

        v = quaternion.apply_to_vector(q1, v)
        v = quaternion.apply_to_vector(q2, v)

        return v
Esempio n. 6
0
    def draw(self, time, frametime, target):
        self.ctx.disable(mgl.DEPTH_TEST)
        self.ctx.enable(mgl.BLEND)
        self.ctx.blend_func = mgl.SRC_ALPHA, mgl.ONE_MINUS_SRC_ALPHA

        m_proj = self.create_projection(90.0, 1.0, 1000.0)

        # Rotate and translate
        m_mv = self.create_transformation(rotation=(time * 0.0, time * 0,
                                                    time * 0),
                                          translation=(0.0, 0.0, -40.0))

        # Apply the rotation and translation from the system camera
        m_mv = matrix44.multiply(m_mv, self.sys_camera.view_matrix)

        gravity_pos = vector3.create(
            math.sin(time) * 5,
            math.cos(time) * 5,
            math.sin(time / 3) * 5)
        gravity_force = math.cos(time / 2) * 3.0 + 3.0
        # gravity_force = 2.0

        # Transform positions
        self.feedback["gravity_pos"].write(gravity_pos.astype('f4').tobytes())
        self.feedback["gravity_force"].value = gravity_force
        self.feedback["timedelta"].value = frametime
        self.particles.transform(self.feedback, self.pos)

        # Draw particles
        self.program["m_proj"].write(m_proj.astype('f4').tobytes())
        self.program["m_mv"].write(m_mv.astype('f4').tobytes())
        self.texture.use(location=0)
        self.program["texture0"].value = 0
        self.particles.render(self.program)

        # Swap buffers
        self.pos = self.pos1 if self.pos == self.pos2 else self.pos2
        self.particles = self.particles1 if self.particles == self.particles2 else self.particles2
Esempio n. 7
0
 def test_create_list(self):
     with self.assertRaises(ValueError):
         vector3.create([1., 2., 3.])
Esempio n. 8
0
 def test_create_values(self):
     result = vector3.create(1., 2., 3., dtype=np.float32)
     np.testing.assert_almost_equal(result, [1., 2., 3.], decimal=5)
     self.assertTrue(result.dtype == np.float32)
Esempio n. 9
0
 def test_create(self):
     result = vector3.create()
     np.testing.assert_almost_equal(result, [0., 0., 0.], decimal=5)
     self.assertTrue(result.dtype == np.float)
Esempio n. 10
0
 def test_create_values(self):
     result = vector3.create(1., 2., 3., dtype=np.float32)
     np.testing.assert_almost_equal(result, [1.,2.,3.], decimal=5)
     self.assertTrue(result.dtype == np.float32)
Esempio n. 11
0
 def test_create(self):
     result = vector3.create()
     np.testing.assert_almost_equal(result, [0.,0.,0.], decimal=5)
     self.assertTrue(result.dtype == np.float)
Esempio n. 12
0
 def test_create_list(self):
     with self.assertRaises(ValueError):
         vector3.create([1., 2., 3.])
Esempio n. 13
0
	def __init__(self, entityName, componentInfo):
		Component.__init__(self, entityName, componentInfo)
		self.position = vector3.create(self.pos[0], self.pos[1], self.pos[2])
		self.rotation = quaternion.create_from_z_rotation(self.rotAngle)
		self.worldMatrix = matrix44.create_identity()
		self.dirty = True