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


Python Matrix44.from_translation方法代碼示例

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


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

示例1: test_oo_examples

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

        point = Vector3([1.,2.,3.])
        orientation = Quaternion()
        translation = Vector3()
        scale = Vector3([1.,1.,1.])

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

        # rotate about Y by pi/2
        rotation = Quaternion.from_y_rotation(np.pi / 2.0)
        orientation = rotation * orientation

        # create a matrix
        # start our matrix off using the scale
        matrix = Matrix44.from_scale(scale)

        # apply our orientation
        # we can multiply matricies and quaternions directly!
        matrix = matrix * orientation

        # apply our translation
        translation = Matrix44.from_translation(translation)
        matrix = matrix * translation

        # transform our point by the matrix
        # vectors are transformable by matrices and quaternions directly
        point = matrix * point
開發者ID:RazerM,項目名稱:Pyrr,代碼行數:33,代碼來源:test_examples.py

示例2: mouseMoveEvent

# 需要導入模塊: from pyrr import Matrix44 [as 別名]
# 或者: from pyrr.Matrix44 import from_translation [as 別名]
 def mouseMoveEvent(self, event):
     pos = event.pos()
     # compute point on sphere under pointer
     (w, h) = self.viewport
     t = (2*self.old_pos.x() - w) / float(w)
     u = -(2*self.old_pos.y() - h) / float(h)
     # compute inverse of view transform ignoring rotation
     m = Matrix44.from_translation(Vector3([0, 0, -self.zoom])) * self.projTransform
     m = matrix44.inverse(m)
     rayOri = m * Vector3([t, u, -1])
     rayEnd = m * Vector3([t, u, 1])
     rayDir = rayEnd - rayOri
     self.picked = intersectRayUnitSphere(rayOri, rayDir)
     # rotate on left-drag
     if event.buttons() & QtCore.Qt.LeftButton > 0:
         # the rotation vector is the displacement vector rotated by 90 degrees
         dx = pos.x() - self.old_pos.x()
         dy = pos.y() - self.old_pos.y()
         if dx == 0 and dy == 0:
             return
         v = Vector3([dy, dx, 0])
         # update the current orientation
         self.layers.multiplyOrientation(Quaternion.from_axis_rotation(
             -v.normalised,
             -v.length * 0.002,
         ))
     elif event.buttons() & QtCore.Qt.RightButton > 0:
         dz = pos.y() - self.old_pos.y()
         self.zoom = max(0, self.zoom + dz / 100.0)
     self.old_pos = pos
     self.update()
開發者ID:mkovacs,項目名稱:sphaira,代碼行數:33,代碼來源:view.py

示例3: resize

# 需要導入模塊: from pyrr import Matrix44 [as 別名]
# 或者: from pyrr.Matrix44 import from_translation [as 別名]
    def resize (self: 'GLQuadRenderer', width: int, height: int) -> None:
        super ().resize (width, height)

        if not self.__loaded:
            return

        y = self.__image_height / self.__image_width * \
            self.gl_widget.width / self.gl_widget.height

        x = self.__image_width / self.__image_height * \
            self.gl_widget.height / self.gl_widget.width

        if self.gl_widget.height * self.__image_width / self.__image_height > self.gl_widget.width:
            self.world = Matrix44.from_scale ([1, y, 1]) * \
                         Matrix44.from_translation ([0, (1 - y) / 2, 0])
        else:
            self.world = Matrix44.from_scale ([x, 1, 1]) * \
                         Matrix44.from_translation ([(1 - x) / 2, 0, 0])

        GL.glUniformMatrix4fv (self.__uniform_world, 1, False, self.world)
開發者ID:fin-ger,項目名稱:color-harmonization,代碼行數:22,代碼來源:gl_quad_renderer.py

示例4: render

# 需要導入模塊: from pyrr import Matrix44 [as 別名]
# 或者: from pyrr.Matrix44 import from_translation [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

示例5: init

# 需要導入模塊: from pyrr import Matrix44 [as 別名]
# 或者: from pyrr.Matrix44 import from_translation [as 別名]
def init(wid, hig):
    """Initialises the display."""
    global modelmtx, chaem
    GL.glClearColor(0.0, 0.2, 0.15, 0.0)
    GL.glClearDepth(1.0)
    GL.glDepthFunc(GL.GL_LESS)
    GL.glEnable(GL.GL_DEPTH_TEST)
    GL.glShadeModel(GL.GL_SMOOTH)
    shades()
    rematr(wid, hig)
    modelmtx = matrix.from_scale([2, 2, 2]) * matrix.from_translation([0, 0, -.5])
    chaem = Raimv((), deltam)
    chaem.rotspe = 2*pi
    GL.glUniformMatrix4fv(GL.glGetUniformLocation(shaderp, 'viewmatrix'), 1, False, chaem.lookat())
    GL.glUniformMatrix4fv(GL.glGetUniformLocation(shaderp, 'modelmatrix'), 1, False, modelmtx)
開發者ID:bzalakos,項目名稱:inscma,代碼行數:17,代碼來源:win.py

示例6: getModelMatrix

# 需要導入模塊: from pyrr import Matrix44 [as 別名]
# 或者: from pyrr.Matrix44 import from_translation [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

示例7: init

# 需要導入模塊: from pyrr import Matrix44 [as 別名]
# 或者: from pyrr.Matrix44 import from_translation [as 別名]
def init():
    """Initialises the display."""
    global projectmatrix, modelmatrix, chaem
    GL.glClearColor(0.0, 0.2, 0.15, 0.0)
    GL.glClearDepth(1.0)
    GL.glDepthFunc(GL.GL_LESS)
    GL.glEnable(GL.GL_DEPTH_TEST)
    GL.glShadeModel(GL.GL_SMOOTH)
    shades()
    chaem = Fremv((), deltam)
    GL.glUniform3f(GL.glGetUniformLocation(shaderp, 'lightColour'), *[1.0, 1.0, 1.0])
    modelmatrix = matrix.from_scale([2, 2, 2]) * matrix.from_translation([0, 0, -1])
    wid, hig = window.get_size()
    hig = hig or 1
    projectmatrix = matrix.perspective_projection(whel, wid/hig, 0.01, 100)
    rematr()
開發者ID:bzalakos,項目名稱:inscma,代碼行數:18,代碼來源:won.py

示例8: draw

# 需要導入模塊: from pyrr import Matrix44 [as 別名]
# 或者: from pyrr.Matrix44 import from_translation [as 別名]
def draw():
    """Put the main drawing code in here."""
    global luxp
    chaem.mochae(timedelta)
    GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
    GL.glEnable(GL.GL_TEXTURE_2D)

    GL.glUseProgram(shaderp)
    luxp = [sin(lasttime) * 5, cos(lasttime) * 5, 0.0]
    GL.glUniform3f(GL.glGetUniformLocation(shaderp, 'lightPos'), *luxp)
    GL.glUniform3f(GL.glGetUniformLocation(shaderp, 'viewpos'), *chaem.pos)
    rematr()
    architincture.draw()
    mmoodd = modelmatrix * matrix.from_scale([0.2, 0.2, 0.2]) * matrix.from_translation(luxp) * \
        matrix.from_eulers([lasttime, lasttime, lasttime])
    lux.draw(rematr, mmoodd)
開發者ID:bzalakos,項目名稱:inscma,代碼行數:18,代碼來源:won.py

示例9: paintGL

# 需要導入模塊: from pyrr import Matrix44 [as 別名]
# 或者: from pyrr.Matrix44 import from_translation [as 別名]
 def paintGL(self):
     glClearColor(0, 0, 0, 1);
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
     glEnable(GL_DEPTH_TEST)
     glDepthFunc(GL_LEQUAL)
     glEnable(GL_BLEND)
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
     glEnable(GL_CULL_FACE)
     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
     glFrontFace(GL_CCW)
     glCullFace(GL_BACK if self.zoom > 1.0 else GL_FRONT)
     self.mesh.bind()
     for layer in self.layers:
         layer.shader.bind()
         # show picked point
         array = (GLdouble * 3)()
         if layer.picked is None:
             array[0] = 0
             array[1] = 0
             array[2] = 0
         else:
             p = layer.orientation.conjugate.matrix33 * layer.picked
             array[0] = p.x
             array[1] = p.y
             array[2] = p.z
         layer.shader.uniformf_vec3('picked', array)
         layer.shader.uniformf('alphaFactor', layer.alpha())
         m = layer.orientation.matrix33
         array = (GLdouble * 9)()
         for i in xrange(3):
             for j in xrange(3):
                 array[3*i + j] = m[i,j]
         layer.shader.uniformf_m3x3('orientation', array)
         # setup view transform
         m = self.projTransform
         m = Matrix44.from_translation(Vector3([0, 0, -self.zoom])) * m
         array = (GLdouble * 16)()
         for i in xrange(4):
             for j in xrange(4):
                 array[4*i + j] = m[i,j]
         layer.shader.uniformf_m4x4('viewTransform', array)
         glActiveTexture(GL_TEXTURE0 + layer.texture_id)
         layer.sphere.bind_glsl_texture(layer.texture_id, layer.shader)
         self.mesh.draw_triangles(layer.shader.handle)
開發者ID:mkovacs,項目名稱:sphaira,代碼行數:46,代碼來源:view.py

示例10: matrix

# 需要導入模塊: from pyrr import Matrix44 [as 別名]
# 或者: from pyrr.Matrix44 import from_translation [as 別名]
 def matrix(self):
     return (Matrix44.from_translation(self._translation) *
             self._rotation.matrix44)
開發者ID:nicholasbishop,項目名稱:bel,代碼行數:5,代碼來源:transform.py

示例11: getModelMatrix

# 需要導入模塊: from pyrr import Matrix44 [as 別名]
# 或者: from pyrr.Matrix44 import from_translation [as 別名]
 def getModelMatrix(self):
     # TODO: maybe spin planet around another axis and add scaling
     rot = mat4.from_y_rotation(self.rot, dtype='f')
     trans = mat4.from_translation(self.position, dtype='f')
     return rot * trans
開發者ID:bogdanteleaga,項目名稱:TSBK07,代碼行數:7,代碼來源:planet.py


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