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


Python Model.draw方法代码示例

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


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

示例1: DrawablePlayer

# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import draw [as 别名]
class DrawablePlayer(object):
    """docstring for DrawablePlayer"""
    def __init__(self, player, batch, fac):
        super(DrawablePlayer, self).__init__()
        self.state = player.state
        # self.rect = player.rect.copy()
        # self.batch = batch
        self.model = Model(path.join('graphics', 'metatest.dae'), fac.x)
        self.model.change_color([c / 255. for c in player.rect.color] + [1.])
        self.weapon = None
        # self.scale(fac)

    def scale(self, fac):
        self.rect.pos *= fac
        self.rect.width *= fac.x
        self.rect.height *= fac.y
        self.rect.add(self.batch)

    def update(self, state, fac):
        pos = vec2(*state.pos) * fac
        # self.rect.update(*pos)
        self.state = state.copy()
        self.state.mpos = state.mpos - state.pos - vec2(16, 54)
        self.state.pos = pos

    def animate(self, dt):
        self.model.update(dt, self.state)

    def update_weapon(self, weapon):
        if weapon != self.weapon:
            self.model.update_weapon(weaponcolors[weapon])
            self.weapon = weapon

    def attack(self):
        self.model.start_attack()

    def draw(self, mvp):
        self.model.draw(mvp)

    def remove(self):
        # self.rect.remove()
        self.model.remove()
开发者ID:mokapharr,项目名称:python_game,代码行数:44,代码来源:views.py

示例2: GLWindow

# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import draw [as 别名]
class GLWindow(QGLWidget):

    def __init__(self, gl_format=None):
        if gl_format is None:
            # using opengl 3.3 core profile
            gformat = QGLFormat()
            gformat.setVersion(3, 3)
            gformat.setProfile(QGLFormat.CoreProfile)
        super(GLWindow, self).__init__(gformat)

        self.__timer = QElapsedTimer()
        self.__timer.start()

        self.camera = camera.Camera(0.0, 0.0, 3.0)
        self.__lastX = 400
        self.__lastY = 300
        self.__firstMouse = True

        self.__deltaTime = 0.0
        self.__lastTime = 0.0

        self.quadVAO = 0
        self.cubeVAO = 0
        self.draw_mode = 1
        self.wireframe = False

        # if you want press mouse button to active camera rotation set it to false
        self.setMouseTracking(True)

    def loadShaders(self, vsf, fsf):
        vertexShaderFile = os.path.join(abPath, vsf)
        fragmentShaderFile = os.path.join(abPath, fsf)
        vertexShaderSource = ''
        with open(vertexShaderFile) as vs:
            vertexShaderSource = vs.read()
        fragmentShaderSource = ''
        with open(fragmentShaderFile) as fg:
            fragmentShaderSource = fg.read()

        vertexShader = shaders.compileShader(vertexShaderSource, GL_VERTEX_SHADER)
        fragmentShader = shaders.compileShader(fragmentShaderSource, GL_FRAGMENT_SHADER)
        return vertexShader, fragmentShader

    def initializeGL(self):
        glViewport(0, 0, self.width(), self.height())
        # setup some OpenGL options
        glEnable(GL_DEPTH_TEST)

        vertexShader, fragmentShader = self.loadShaders('8.g_buffer.vs', '8.g_buffer.frag')
        self.__geometyPassShader = shaders.compileProgram(vertexShader, fragmentShader)
        vertexShader, fragmentShader = self.loadShaders('8.deferred_light_box.vs', '8.deferred_light_box.frag')
        self.__lightBoxShader = shaders.compileProgram(vertexShader, fragmentShader)
        _shaders = self.loadShaders('8.deferred_shading.vs', '8.deferred_shading.frag')
        self.__lightingPassShader = glCreateProgram()
        [glAttachShader(self.__lightingPassShader, s) for s in _shaders if s]
        self.__lightingPassShader = shaders.ShaderProgram(self.__lightingPassShader)
        glLinkProgram(self.__lightingPassShader)
        glUseProgram(self.__lightingPassShader)
        glUniform1i(glGetUniformLocation(self.__lightingPassShader, 'gPosition'), 0)
        glUniform1i(glGetUniformLocation(self.__lightingPassShader, 'gNormal'), 1)
        glUniform1i(glGetUniformLocation(self.__lightingPassShader, 'gAlbedoSpec'), 2)
        self.__lightingPassShader.check_validate()
        self.__lightingPassShader.check_linked()
        [glDeleteShader(s) for s in _shaders if s]

        # models
        modelPath = os.path.join(abPath, '..', '..', 'resources', 'objects', 'nanosuit', 'nanosuit.obj')
        self.cyborg = Model(modelPath)
        self.objectPosition = [
            np.array([-3.0, -3.0, -3.0], np.float32),
            np.array([ 0.0, -3.0, -3.0], np.float32),
            np.array([ 3.0, -3.0, -3.0], np.float32),
            np.array([-3.0, -3.0,  0.0], np.float32),
            np.array([ 0.0, -3.0,  0.0], np.float32),
            np.array([ 3.0, -3.0,  0.0], np.float32),
            np.array([-3.0, -3.0,  3.0], np.float32),
            np.array([ 0.0, -3.0,  3.0], np.float32),
            np.array([ 3.0, -3.0,  3.0], np.float32),
        ]

        # light position
        self.lightPos = []
        self.lightColors = []
        random.seed(13)
        for i in range(32):
            # calculate slightly random offsets
            xpos = (random.randint(0, 99) / 100.0) * 6.0 - 3.0
            ypos = (random.randint(0, 99) / 100.0) * 6.0 - 4.0
            zpos = (random.randint(0, 99) / 100.0) * 6.0 - 3.0
            self.lightPos.append(np.array([xpos, ypos, zpos], np.float32))
            # also calculate random color
            rcolor = (random.randint(0, 99) / 200.0) + 0.5 # Between 0.5 and 1.0
            gcolor = (random.randint(0, 99) / 200.0) + 0.5 # Between 0.5 and 1.0
            bcolor = (random.randint(0, 99) / 200.0) + 0.5 # Between 0.5 and 1.0
            self.lightColors.append(np.array([rcolor, gcolor, bcolor], np.float32))

        # set up G-Buffer
        # 3 textures:
        # 1. Position (RGB)
        # 2. Color (RGB) + Specular (A)
#.........这里部分代码省略.........
开发者ID:mackst,项目名称:LearnPyOpenGL,代码行数:103,代码来源:8.deferred_shading.py

示例3: GLWindow

# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import draw [as 别名]
class GLWindow(QGLWidget):

    def __init__(self, gl_format=None):
        if gl_format is None:
            # using opengl 3.3 core profile
            gformat = QGLFormat()
            gformat.setVersion(3, 3)
            gformat.setProfile(QGLFormat.CoreProfile)
        super(GLWindow, self).__init__(gformat)

        self.__timer = QElapsedTimer()
        self.__timer.start()

        self.camera = camera.Camera(0.0, 0.0, 3.0)
        self.__lastX = 400
        self.__lastY = 300
        self.__firstMouse = True

        self.__deltaTime = 0.0
        self.__lastTime = 0.0

        self.model = None

        # if you want press mouse button to active camera rotation set it to false 
        self.setMouseTracking(True)

    def loadShaders(self):
        vertexShaderFile = os.path.join(abPath, 'shader.vs')
        fragmentShaderFile = os.path.join(abPath, 'shader.frag')
        vertexShaderSource = ''
        with open(vertexShaderFile) as vs:
            vertexShaderSource = vs.read()
        fragmentShaderSource = ''
        with open(fragmentShaderFile) as fg:
            fragmentShaderSource = fg.read()

        vertexShader = shaders.compileShader(vertexShaderSource, GL_VERTEX_SHADER)
        fragmentShader = shaders.compileShader(fragmentShaderSource, GL_FRAGMENT_SHADER)
        return vertexShader, fragmentShader
    
    def initializeGL(self):
        glEnable(GL_DEPTH_TEST)

        vertexShader, fragmentShader = self.loadShaders()
        self.__shaderProgram = shaders.compileProgram(vertexShader, fragmentShader)

        modelPath = os.path.join(abPath, '..', '..', 'resources', 'objects', 'nanosuit', 'nanosuit.obj')
        self.model = Model(modelPath)

        # Draw in wireframe
        #glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

    def resizeGL(self, w, h):
        glViewport(0, 0, w, h)

    def paintGL(self):
        currentTime = self.__timer.elapsed() / 1000.0
        self.__deltaTime = currentTime - self.__lastTime
        self.__lastTime = currentTime

        # Render
        # Clear the colorbuffer
        glClearColor(0.05, 0.05, 0.05, 1.0)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        glUseProgram(self.__shaderProgram)

        view = self.camera.viewMatrix
        #view = glm.translate(view, 0.0, 0.0, -3.0)
        projection = glm.perspective(self.camera.zoom, float(self.width()) / self.height(), 0.1, 100.0)
        # get their uniform location
        modelLoc = glGetUniformLocation(self.__shaderProgram, 'model')
        viewLoc = glGetUniformLocation(self.__shaderProgram, 'view')
        projLoc = glGetUniformLocation(self.__shaderProgram, 'projection')
        glUniformMatrix4fv(viewLoc, 1, GL_FALSE, view)
        glUniformMatrix4fv(projLoc, 1, GL_FALSE, projection)

        model = np.identity(4, np.float32)
        model = glm.scale(model, 0.2, 0.2, 0.2)
        model = glm.translate(model, 0.0, -1.75, 0.0)
        glUniformMatrix4fv(modelLoc, 1, GL_FALSE, model)

        self.model.draw(self.__shaderProgram)

    def keyPressEvent(self, event):
        if event.key() == Qt.Key_Escape:
            qApp.quit()
        if event.key() == Qt.Key_W:
            self.camera.processKeyboard(camera.Camera_Movement.FORWARD, self.__deltaTime)
        if event.key() == Qt.Key_S:
            self.camera.processKeyboard(camera.Camera_Movement.BACKWARED, self.__deltaTime)
        if event.key() == Qt.Key_A:
            self.camera.processKeyboard(camera.Camera_Movement.LEFT, self.__deltaTime)
        if event.key() == Qt.Key_D:
            self.camera.processKeyboard(camera.Camera_Movement.RIGHT, self.__deltaTime)

        self.updateGL()
        return super(GLWindow, self).keyPressEvent(event)

    def mouseMoveEvent(self, event):
#.........这里部分代码省略.........
开发者ID:mackst,项目名称:LearnPyOpenGL,代码行数:103,代码来源:1.model_rendered.py

示例4: GLWindow

# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import draw [as 别名]
class GLWindow(QGLWidget):

    def __init__(self, gl_format=None):
        if gl_format is None:
            # using opengl 3.3 core profile
            gformat = QGLFormat()
            gformat.setVersion(3, 3)
            gformat.setProfile(QGLFormat.CoreProfile)
        super(GLWindow, self).__init__(gformat)

        self.__timer = QElapsedTimer()
        self.__timer.start()

        self.camera = camera.Camera(0.0, 0.0, 3.0)
        self.__lastX = 400
        self.__lastY = 300
        self.__firstMouse = True

        self.__deltaTime = 0.0
        self.__lastTime = 0.0

        self.quadVAO = 0
        self.cubeVAO = 0
        self.draw_mode = 1

        # if you want press mouse button to active camera rotation set it to false
        self.setMouseTracking(True)

    def loadShaders(self, vsf, fsf):
        vertexShaderFile = os.path.join(abPath, vsf)
        fragmentShaderFile = os.path.join(abPath, fsf)
        vertexShaderSource = ''
        with open(vertexShaderFile) as vs:
            vertexShaderSource = vs.read()
        fragmentShaderSource = ''
        with open(fragmentShaderFile) as fg:
            fragmentShaderSource = fg.read()

        vertexShader = shaders.compileShader(vertexShaderSource, GL_VERTEX_SHADER)
        fragmentShader = shaders.compileShader(fragmentShaderSource, GL_FRAGMENT_SHADER)
        return vertexShader, fragmentShader

    def initializeGL(self):
        glViewport(0, 0, self.width(), self.height())
        # setup some OpenGL options
        glEnable(GL_DEPTH_TEST)

        vertexShader, fragmentShader = self.loadShaders('9.ssao_geometry.vs', '9.ssao_geometry.frag')
        self.__geometyPassShader = shaders.compileProgram(vertexShader, fragmentShader)
        vertexShader, fragmentShader = self.loadShaders('9.ssao.vs', '9.ssao_blur.frag')
        self.__ssaoBlurShader = shaders.compileProgram(vertexShader, fragmentShader)
        _shaders = self.loadShaders('9.ssao.vs', '9.ssao_lighting.frag')
        self.__lightingPassShader = glCreateProgram()
        [glAttachShader(self.__lightingPassShader, s) for s in _shaders if s]
        self.__lightingPassShader = shaders.ShaderProgram(self.__lightingPassShader)
        glLinkProgram(self.__lightingPassShader)
        glUseProgram(self.__lightingPassShader)
        glUniform1i(glGetUniformLocation(self.__lightingPassShader, 'gPositionDepth'), 0)
        glUniform1i(glGetUniformLocation(self.__lightingPassShader, 'gNormal'), 1)
        glUniform1i(glGetUniformLocation(self.__lightingPassShader, 'gAlbedo'), 2)
        glUniform1i(glGetUniformLocation(self.__lightingPassShader, 'ssao'), 3)
        self.__lightingPassShader.check_validate()
        self.__lightingPassShader.check_linked()
        [glDeleteShader(s) for s in _shaders if s]
        _shaders = self.loadShaders('9.ssao.vs', '9.ssao.frag')
        self.__ssaoShader = glCreateProgram()
        [glAttachShader(self.__ssaoShader, s) for s in _shaders if s]
        self.__ssaoShader = shaders.ShaderProgram(self.__ssaoShader)
        glLinkProgram(self.__ssaoShader)
        glUseProgram(self.__ssaoShader)
        glUniform1i(glGetUniformLocation(self.__ssaoShader, 'gPositionDepth'), 0)
        glUniform1i(glGetUniformLocation(self.__ssaoShader, 'gNormal'), 1)
        glUniform1i(glGetUniformLocation(self.__ssaoShader, 'texNoise'), 2)
        self.__ssaoShader.check_validate()
        self.__ssaoShader.check_linked()
        [glDeleteShader(s) for s in _shaders if s]

        # models
        modelPath = os.path.join(abPath, '..', '..', 'resources', 'objects', 'nanosuit', 'nanosuit.obj')
        self.cyborg = Model(modelPath)

        # light position
        self.lightPos = np.array([2.0, 4.0, -2.0], np.float32)
        self.lightColor = np.array([0.2, 0.2, 0.7], np.float32)

        # set up G-Buffer
        # 3 textures:
        # 1. Position (RGB)
        # 2. Color (RGB) + Specular (A)
        # 3. Normals (RGB)
        self.gbuffer = glGenFramebuffers(1)
        glBindFramebuffer(GL_FRAMEBUFFER, self.gbuffer)
        self.gPositionDepth, self.gNormal, self.gAlbedo = glGenTextures(3)
        # position color buffer
        glBindTexture(GL_TEXTURE_2D, self.gPositionDepth)
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, self.width(), self.height(), 0, GL_RGBA, GL_FLOAT, None)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
#.........这里部分代码省略.........
开发者ID:mackst,项目名称:LearnPyOpenGL,代码行数:103,代码来源:9.ssao.py


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