• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pyrr.Matrix44类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyrr.Matrix44的典型用法代码示例。如果您正苦于以下问题:Python Matrix44类的具体用法?Python Matrix44怎么用?Python Matrix44使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Matrix44类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_oo_examples

    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,代码行数:31,代码来源:test_examples.py


示例2: render

    def render(self, time: float, frame_time: float):
        self.ctx.clear(1.0, 1.0, 1.0)
        self.ctx.enable(moderngl.DEPTH_TEST)

        proj = Matrix44.perspective_projection(45.0, self.aspect_ratio, 0.1, 1000.0)
        lookat = Matrix44.look_at(
            (47.697, -8.147, 24.498),
            (0.0, 0.0, 8.0),
            (0.0, 0.0, 1.0),
        )

        rotate = Matrix44.from_z_rotation(np.sin(time) * 0.5 + 0.2)

        self.use_texture.value = False

        self.light.value = (67.69, -8.14, 52.49)
        self.mvp.write((proj * lookat * rotate).astype('f4').tobytes())

        self.color.value = (0.67, 0.49, 0.29)
        self.objects['ground'].render()

        self.color.value = (0.46, 0.67, 0.29)
        self.objects['grass'].render()

        self.color.value = (1.0, 1.0, 1.0)
        self.objects['billboard'].render()

        self.color.value = (0.2, 0.2, 0.2)
        self.objects['billboard-holder'].render()

        self.use_texture.value = True
        self.texture.use()

        self.objects['billboard-image'].render()
开发者ID:cprogrammer1994,项目名称:ModernGL,代码行数:34,代码来源:04_colors_and_texture.py


示例3: update

def update(dt):
    ctx.viewport = (0, 0, wnd.width, wnd.height)
    ctx.clear(0.9, 0.9, 0.9)
    ctx.enable(ModernGL.DEPTH_TEST)

    proj = Matrix44.perspective_projection(45.0, wnd.width / wnd.height, 0.1, 1000.0)
    lookat = Matrix44.look_at(
        (40.0, 30.0, 20.0),
        (0.0, 0.0, 0.0),
        (0.0, 0.0, 1.0),
开发者ID:cprogrammer1994,项目名称:ModernGL,代码行数:10,代码来源:perspective_projection.py


示例4: draw

    def draw(self, *args):
        width, height = Window.size
        self.ctx.viewport = (0, 0, width, height)
        self.ctx.clear(0.9, 0.9, 0.9)
        self.ctx.enable(ModernGL.DEPTH_TEST)

        proj = Matrix44.perspective_projection(45.0, width / height, 0.1, 1000.0)
        lookat = Matrix44.look_at(
            (40.0, 30.0, 20.0),
            (0.0, 0.0, 0.0),
            (0.0, 0.0, 1.0),
开发者ID:cprogrammer1994,项目名称:ModernGL,代码行数:11,代码来源:perspective_projection.py


示例5: render

    def render(self):
        self.ctx.screen.viewport = self.wnd.viewport
        self.ctx.clear(1.0, 1.0, 1.0)
        with self.ctx.scope(mgl.DEPTH_TEST):
            proj = Matrix44.perspective_projection(45.0, self.wnd.ratio, 0.1, 1000.0)
            lookat = Matrix44.look_at(
                (40.0, 30.0, 30.0),
                (0.0, 0.0, 0.0),
                (0.0, 0.0, 1.0),
            )

            self.prog['Mvp'] = (proj * lookat).astype('f4').tobytes()
            self.vao.render(mgl.LINES)
开发者ID:cprogrammer1994,项目名称:ModernGL,代码行数:13,代码来源:simple_grid.py


示例6: render

    def render(self, time, frame_time):
        self.ctx.clear(1.0, 1.0, 1.0)
        self.ctx.enable(moderngl.DEPTH_TEST)

        proj = Matrix44.perspective_projection(45.0, self.aspect_ratio, 0.1, 1000.0)
        lookat = Matrix44.look_at(
            (40.0, 30.0, 30.0),
            (0.0, 0.0, 0.0),
            (0.0, 0.0, 1.0),
        )

        self.mvp.write((proj * lookat).astype('f4').tobytes())
        self.vao.render(moderngl.LINES)
开发者ID:cprogrammer1994,项目名称:ModernGL,代码行数:13,代码来源:simple_grid.py


示例7: render

    def render(self, time, frame_time):
        angle = time * 0.2
        self.ctx.clear(1.0, 1.0, 1.0)
        self.ctx.enable(moderngl.DEPTH_TEST)

        proj = Matrix44.perspective_projection(45.0, self.aspect_ratio, 0.1, 1000.0)
        lookat = Matrix44.look_at(
            (np.cos(angle), np.sin(angle), 0.8),
            (0.0, 0.0, 0.1),
            (0.0, 0.0, 1.0),
        )

        self.mvp.write((proj * lookat).astype('f4').tobytes())
        self.vao.render(moderngl.TRIANGLE_STRIP)
开发者ID:cprogrammer1994,项目名称:ModernGL,代码行数:14,代码来源:multi_texture_terrain.py


示例8: render

    def render(self, time: float, frame_time: float):
        camera_pos = (np.cos(time) * 300.0, np.sin(time) * 300.0, 120.0)
        proj = Matrix44.perspective_projection(45.0, self.aspect_ratio, 0.1, 1000.0)
        lookat = Matrix44.look_at(
            camera_pos,
            (0.0, 0.0, 50.0),
            (0.0, 0.0, 1.0),
        )

        with self.scope:
            self.prog['Mvp'] = (proj * lookat).astype('f4').tobytes()
            self.prog['Eye'] = camera_pos
            self.ctx.clear(1.0, 1.0, 1.0)
            self.vao.render()
开发者ID:cprogrammer1994,项目名称:ModernGL,代码行数:14,代码来源:texture_cube.py


示例9: mouseMoveEvent

 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,代码行数:31,代码来源:view.py


示例10: resizeGL

 def resizeGL(self, w, h):
     glViewport(0, 0, w, h)
     self.viewport = (w, h)
     self.projTransform = Matrix44.perspective_projection(
         50, float(w) / h,
         0.01, 100.0,
     )
开发者ID:mkovacs,项目名称:sphaira,代码行数:7,代码来源:view.py


示例11: render

    def render(self, time, frame_time):
        angle = time
        self.ctx.clear(1.0, 1.0, 1.0)

        camera_pos = (np.cos(angle) * 5.0, np.sin(angle) * 5.0, 2.0)

        proj = Matrix44.perspective_projection(45.0, self.aspect_ratio, 0.1, 1000.0)
        lookat = Matrix44.look_at(
            camera_pos,
            (0.0, 0.0, 0.0),
            (0.0, 0.0, 1.0),
        )

        self.prog['Mvp'] = (proj * lookat).astype('f4').tobytes()
        self.prog['Light'] = camera_pos
        self.vao.render()
开发者ID:cprogrammer1994,项目名称:ModernGL,代码行数:16,代码来源:texture_3d_visual_test.py


示例12: render

    def render(self):
        angle = self.wnd.time
        self.ctx.screen.viewport = self.wnd.viewport

        camera_pos = (np.cos(angle) * 5.0, np.sin(angle) * 5.0, 2.0)

        proj = Matrix44.perspective_projection(45.0, self.wnd.ratio, 0.1, 1000.0)
        lookat = Matrix44.look_at(
            camera_pos,
            (0.0, 0.0, 0.5),
            (0.0, 0.0, 1.0),
        )

        self.prog['Mvp'] = (proj * lookat).astype('f4').tobytes()
        self.prog['Light'] = camera_pos

        self.ctx.replay(self.bytecode)
开发者ID:cprogrammer1994,项目名称:ModernGL,代码行数:17,代码来源:crate_render_batch.py


示例13: render

    def render(self, time, frame_time):
        self.ctx.clear(1.0, 1.0, 1.0)
        self.ctx.enable(moderngl.DEPTH_TEST)

        proj = Matrix44.perspective_projection(45.0, self.aspect_ratio, 0.1, 1000.0)
        lookat = Matrix44.look_at(
            (-85, -180, 140),
            (0.0, 0.0, 65.0),
            (0.0, 0.0, 1.0),
        )

        self.light.value = (-140.0, -300.0, 350.0)
        self.color.value = (1.0, 1.0, 1.0, 0.25)
        self.mvp.write((proj * lookat).astype('f4').tobytes())

        self.texture.use()
        self.vao.render()
开发者ID:cprogrammer1994,项目名称:ModernGL,代码行数:17,代码来源:loading_obj_files.py


示例14: render

    def render(self, time, frame_time):
        self.ctx.clear(1.0, 1.0, 1.0)
        # self.ctx.enable(mgl.DEPTH_TEST)
        proj = Matrix44.perspective_projection(45.0, self.aspect_ratio, 0.1, 1000.0)
        lookat = Matrix44.look_at(
            (47.697, -8.147, 24.498),
            (0.0, 0.0, 8.0),
            (0.0, 0.0, 1.0),
        )

        rotate = Matrix44.from_z_rotation(np.sin(time) * 0.5 + 0.2)

        w, h = self.texture.size
        gw, gh = 16, 16
        nx, ny, nz = int(w/gw), int(h/gh), 1

        print('=' * 50)

        self.compute['time'] = time
        GL_WRITE_ONLY = 0x88B9
        GL_R32F = 0x822E
        self.texture.bind_to_image(0,GL_WRITE_ONLY, GL_R32F)
        self.compute.run(nx, ny, nz)
        print('-' * 50)

        with self.scope:
            self.prog['UseTexture'] = False

            self.prog['Light'] = (67.69, -8.14, 52.49)
            self.prog['Mvp'] = (proj * lookat * rotate).astype('f4').tobytes()

            self.prog['Color'] = (0.67, 0.49, 0.29)
            self.objects['ground'].render()

            self.prog['Color'] = (0.46, 0.67, 0.29)
            self.objects['grass'].render()

            self.prog['Color'] = (1.0, 1.0, 1.0)
            self.objects['billboard'].render()

            self.prog['Color'] = (0.2, 0.2, 0.2)
            self.objects['billboard-holder'].render()

            self.prog['UseTexture'] = True

            self.objects['billboard-image'].render()
开发者ID:cprogrammer1994,项目名称:ModernGL,代码行数:46,代码来源:render_texture_compute_shader.py


示例15: resize

    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,代码行数:20,代码来源:gl_quad_renderer.py


示例16: test_m44_q_equivalence

    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,代码行数:20,代码来源:test_equivalence.py


示例17: render

    def render(self, time, frame_time):
        self.ctx.clear(1.0, 1.0, 1.0)
        self.bg_texture.use()
        self.ctx.enable_only(moderngl.BLEND)
        self.canvas_vao.render(moderngl.TRIANGLE_STRIP)
        self.ctx.enable_only(moderngl.DEPTH_TEST)

        proj = Matrix44.perspective_projection(30.0, self.aspect_ratio, 1.0, 1000.0)
        lookat = Matrix44.look_at(
            (46.748, -280.619, 154.391),
            (-23.844, 2.698, 44.493),
            (0.0, 0.0, 1.0),
        )

        self.mvp.write((proj * lookat).astype('f4').tobytes())
        self.light.value = (-143.438, -159.072, 213.268)
        self.mug_texture.use()
        self.mug_vao.render()
        self.ctx.enable_only(moderngl.DEPTH_TEST | moderngl.BLEND)
        self.sticker_texture.use()
        self.sticker_vao.render(moderngl.TRIANGLE_STRIP)
开发者ID:cprogrammer1994,项目名称:ModernGL,代码行数:21,代码来源:mug_mockup.py


示例18: render

    def render(self, time, frame_time):
        angle = time * 0.2
        self.ctx.clear(1.0, 1.0, 1.0)
        self.ctx.enable(moderngl.DEPTH_TEST)

        camera_pos = (np.cos(angle) * 5.0, np.sin(angle) * 5.0, 2.0)

        proj = Matrix44.perspective_projection(45.0, self.aspect_ratio, 0.1, 1000.0)
        lookat = Matrix44.look_at(
            camera_pos,
            (0.0, 0.0, 0.5),
            (0.0, 0.0, 1.0),
        )

        self.mvp.write((proj * lookat).astype('f4').tobytes())
        self.light.value = camera_pos

        crate_z = np.sin(self.crate_a * time + self.crate_b) * 0.2
        coordinates = np.dstack([self.crate_x, self.crate_y, crate_z])

        self.vbo2.write(coordinates.astype('f4').tobytes())
        self.vao.render(instances=1024)
开发者ID:cprogrammer1994,项目名称:ModernGL,代码行数:22,代码来源:instanced_rendering_crates.py


示例19: render

    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,代码行数:38,代码来源:ex1.py


示例20: render

    def render(self):
        angle = self.wnd.time
        self.ctx.screen.viewport = self.wnd.viewport
        self.ctx.clear(1.0, 1.0, 1.0)

        with self.ctx.scope(mgl.DEPTH_TEST):
            camera_pos = (np.cos(angle) * 20.0, np.sin(angle) * 20.0, 5.0)

            proj = Matrix44.perspective_projection(45.0, self.wnd.ratio, 0.1, 1000.0)
            lookat = Matrix44.look_at(
                camera_pos,
                (0.0, 0.0, 0.5),
                (0.0, 0.0, 1.0),
            )

            self.prog['Mvp'] = (proj * lookat).astype('f4').tobytes()
            self.prog['Light'] = camera_pos

            # self.vbo2.write(Matrix33.from_z_rotation(self.wnd.time).astype('f4').tobytes(), offset=24)
            self.vbo2.write(b''.join(struct.pack(
                '15f',
                *car['color'],
                *car['pos'],
                1.0, 0.0, 0.0,
                0.0, 1.0, 0.0,
                0.0, 0.0, 1.0,
            ) for car in cars))
            self.vao.render(instances=len(cars))
            self.vbo2.write(b''.join(struct.pack(
                '15f',
                0.0, 0.0, 0.0,
                *car['pos'],
                1.0, 0.0, 0.0,
                0.0, 1.0, 0.0,
                0.3, 0.6, 0.0,
            ) for car in cars))
            self.vao.render(instances=len(cars))
开发者ID:cprogrammer1994,项目名称:ModernGL,代码行数:37,代码来源:toy_cars_with_vector_shadow.py



注:本文中的pyrr.Matrix44类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python quaternion.Quaternion类代码示例发布时间:2022-05-27
下一篇:
Python netns.remove函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap