当前位置: 首页>>代码示例>>Python>>正文


Python Shader.uniform_matrixf方法代码示例

本文整理汇总了Python中shader.Shader.uniform_matrixf方法的典型用法代码示例。如果您正苦于以下问题:Python Shader.uniform_matrixf方法的具体用法?Python Shader.uniform_matrixf怎么用?Python Shader.uniform_matrixf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在shader.Shader的用法示例。


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

示例1: Scene

# 需要导入模块: from shader import Shader [as 别名]
# 或者: from shader.Shader import uniform_matrixf [as 别名]
class Scene(object):
    
    PAUSED = 0
    PLAYING = 1
    
    vertex_shader = '''
    uniform mat4 modelview;
    uniform mat4 projection;
    void main() {
        gl_FrontColor = gl_Color;
        
        vec4 modelSpacePos = modelview * gl_Vertex;
        gl_Position = projection * modelSpacePos;
    }
    '''

    def __init__(self):
        self.objects = []
        self.camera = None
        
        self.playback = Parameter(default=self.PAUSED, enum=[('Play',self.PLAYING),('Pause',self.PAUSED)])
        #self.playback = self.PLAYING
        self.fps = 24.0
        self.time = 0   # in seconds?
        self.frame = Parameter(default=1, vmin=0, vmax=100, title='Frame', update=self.update_time)
        self.sframe = Parameter(default=1, vmin=0, vmax=100, title='Start Frame')
        self.eframe = Parameter(default=100, vmin=0, vmax=100, title='End Frame')

        self.ui3d_shader = Shader(self.vertex_shader)
        self.ui3d_batch = pyglet.graphics.Batch()

        self.grid = Grid(10, 10, self.ui3d_batch )
        self.axes = Axes(0.5, self.ui3d_batch )

        self.bbmin = None
        self.bbmax = None
    
    def calculate_bounds(self):
        self.bbmin = None
        self.bbmax = None

        for ob in self.objects:
            if hasattr(ob, "bbmin") and hasattr(ob, "bbmax"):
                if self.bbmin is None and self.bbmax is None:
                    self.bbmin = ob.bbmin
                    self.bbmax = ob.bbmax
                else:
                    self.bbmin.x = min(ob.bbmin.x, self.bbmin.x)
                    self.bbmin.y = min(ob.bbmin.y, self.bbmin.y)
                    self.bbmin.z = min(ob.bbmin.z, self.bbmin.z)

                    self.bbmax.x = max(ob.bbmax.x, self.bbmax.x)
                    self.bbmax.y = max(ob.bbmax.y, self.bbmax.y)
                    self.bbmax.z = max(ob.bbmax.z, self.bbmax.z)

                self.grid.delete()
                del self.grid
                diam = self.bbmax - self.bbmin
                center = self.bbmin + diam*0.5
                self.grid = Grid(10, 10, self.ui3d_batch, center=center[:])


    def on_key_press(self, symbol, modifiers):
        if symbol == pyglet.window.key.H:
            self.calculate_bounds()
            self.camera.focus(self)
        if symbol == pyglet.window.key.RIGHT:
            self.frame.value += 1
        if symbol == pyglet.window.key.LEFT:
            self.frame.value -= 1

    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        if not (modifiers & pyglet.window.key.MOD_ALT or \
                modifiers & pyglet.window.key.MOD_CTRL or \
                modifiers & pyglet.window.key.MOD_SHIFT or \
                keys[pyglet.window.key.SPACE]):
            if buttons & mouse.MIDDLE:
                self.frame.value +=  dx*0.05
                return pyglet.event.EVENT_HANDLED


    def on_draw(self):
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        
        # 3D Geometry
        for ob in self.objects:
            ob.draw(time=self.time, camera=self.camera)

        # 3D UI elements
        glEnable(GL_LINE_SMOOTH)
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
        
        self.ui3d_shader.bind()
        self.ui3d_shader.uniform_matrixf('modelview', self.camera.matrixinv)
        self.ui3d_shader.uniform_matrixf('projection', self.camera.persp_matrix)
        self.ui3d_batch.draw()
        self.ui3d_shader.unbind()

#.........这里部分代码省略.........
开发者ID:UIKit0,项目名称:pyglet-bits,代码行数:103,代码来源:object3d.py


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