當前位置: 首頁>>代碼示例>>Python>>正文


Python Matrix44.from_x_rotation方法代碼示例

本文整理匯總了Python中pyrr.Matrix44.from_x_rotation方法的典型用法代碼示例。如果您正苦於以下問題:Python Matrix44.from_x_rotation方法的具體用法?Python Matrix44.from_x_rotation怎麽用?Python Matrix44.from_x_rotation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyrr.Matrix44的用法示例。


在下文中一共展示了Matrix44.from_x_rotation方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: getModelMatrix

# 需要導入模塊: from pyrr import Matrix44 [as 別名]
# 或者: from pyrr.Matrix44 import from_x_rotation [as 別名]
  def getModelMatrix(self):
      scale = mat4.from_scale([0.2, 0.2, 0.2])
      
      roty = mat4.from_y_rotation(-self.hAngle)

      vdiff = self.vAngle - self.oldvAngle
      rotx = mat4.from_x_rotation(self.getxRot(vdiff))
      
      zdiff = self.hAngle - self.oldhAngle
      rotz = mat4.from_z_rotation(-self.getzRot(zdiff))

      trans = mat4.from_translation(self.position, dtype='f')
      self.oldhAngle = self.hAngle
      self.oldvAngle = self.vAngle
      
      return scale * rotz * rotx * roty * trans
開發者ID:bogdanteleaga,項目名稱:TSBK07,代碼行數:18,代碼來源:spaceship.py

示例2: test_m44_q_equivalence

# 需要導入模塊: from pyrr import Matrix44 [as 別名]
# 或者: from pyrr.Matrix44 import from_x_rotation [as 別名]
    def test_m44_q_equivalence(self):
        """Test for equivalance of matrix and quaternion rotations.

        Create a matrix and quaternion, rotate each by the same values
        then convert matrix<->quaternion and check the results are the same.
        """
        m = Matrix44.from_x_rotation(np.pi / 2.)
        mq = Quaternion.from_matrix(m)

        q = Quaternion.from_x_rotation(np.pi / 2.)
        qm = Matrix44.from_quaternion(q)

        self.assertTrue(np.allclose(np.dot([1., 0., 0., 1.], m), [1., 0., 0., 1.]))
        self.assertTrue(np.allclose(np.dot([1., 0., 0., 1.], qm), [1., 0., 0., 1.]))

        self.assertTrue(np.allclose(q * Vector4([1., 0., 0., 1.]), [1., 0., 0., 1.]))
        self.assertTrue(np.allclose(mq * Vector4([1., 0., 0., 1.]), [1., 0., 0., 1.]))

        np.testing.assert_almost_equal(np.array(q), np.array(mq), decimal=5)
        np.testing.assert_almost_equal(np.array(m), np.array(qm), decimal=5)
開發者ID:adamlwgriffiths,項目名稱:Pyrr,代碼行數:22,代碼來源:test_equivalence.py

示例3: render

# 需要導入模塊: from pyrr import Matrix44 [as 別名]
# 或者: from pyrr.Matrix44 import from_x_rotation [as 別名]
    def render(self, app, currentTime):
        glBindVertexArray(self._vao.identifier)
        try:
            glUseProgram(self._program.identifier)

            bg_color = (
                math.sin(currentTime) * 0.5 + 0.5,
                math.cos(currentTime) * 0.5 + 0.5,
                0.0,
                1.0
            )
            glClearBufferfv(GL_COLOR, 0, bg_color)
            glClearBufferfv(GL_DEPTH, 0, [1])

            f = currentTime * 0.3
            mv_matrix = Matrix44.identity(dtype='f4')
            mv_matrix *= Matrix44.from_x_rotation(
                currentTime * math.radians(81))
            mv_matrix *= Matrix44.from_y_rotation(
                currentTime * math.radians(45))
            mv_matrix *= Matrix44.from_translation([
                math.sin(2.1 * f) * 0.5,
                math.cos(1.7 * f) * 0.5,
                math.sin(1.3 * f) * math.cos(1.5 * f) * 2.0])
            mv_matrix *= Matrix44.from_translation([0.0, 0.0, -4.0])

            self._uniform_block.mv_matrix[:] = mv_matrix.reshape(16)

            glBufferSubData(
                GL_UNIFORM_BUFFER,
                0,
                ctypes.sizeof(self._uniform_block),
                ctypes.byref(self._uniform_block))

            self._torus_obj.render()

        finally:
            glBindVertexArray(NULL_GL_OBJECT)
開發者ID:nickhutchinson,項目名稱:SB6Python,代碼行數:40,代碼來源:ex1.py

示例4: test_operators

# 需要導入模塊: from pyrr import Matrix44 [as 別名]
# 或者: from pyrr.Matrix44 import from_x_rotation [as 別名]
    def test_operators(self):
        from pyrr import Quaternion, Matrix44, Matrix33, Vector3, Vector4
        import numpy as np

        # matrix multiplication
        m = Matrix44() * Matrix33()
        m = Matrix44() * Quaternion()
        m = Matrix33() * Quaternion()

        # matrix inverse
        m = ~Matrix44.from_x_rotation(np.pi)

        # quaternion multiplication
        q = Quaternion() * Quaternion()
        q = Quaternion() * Matrix44()
        q = Quaternion() * Matrix33()

        # quaternion inverse (conjugate)
        q = ~Quaternion()

        # quaternion dot product
        d = Quaternion() | Quaternion()

        # vector oprations
        v = Vector3() + Vector3()
        v = Vector4() - Vector4()

        # vector transform
        v = Quaternion() * Vector3()
        v = Matrix44() * Vector3()
        v = Matrix44() * Vector4()
        v = Matrix33() * Vector3()

        # dot and cross products
        dot = Vector3() | Vector3()
        cross = Vector3() ^ Vector3()
開發者ID:RazerM,項目名稱:Pyrr,代碼行數:38,代碼來源:test_examples.py


注:本文中的pyrr.Matrix44.from_x_rotation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。