当前位置: 首页>>代码示例>>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;未经允许,请勿转载。