예제 #1
0
    def run(self):
        # initializer timer
        glfw.glfwSetTime(0)
        t = 0.0
        while not glfw.glfwWindowShouldClose(self.win) and not self.exitNow:
            # update every x seconds
            currT = glfw.glfwGetTime()
            if currT - t > 0.1:
                # update time
                t = currT
                # clear
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
                
                # build projection matrix
                pMatrix = glutils.perspective(45.0, self.aspect, 0.1, 100.0)
                
                mvMatrix = glutils.lookAt([0.0, 0.0, -2.0], [0.0, 0.0, 0.0],
                                          [0.0, 1.0, 0.0])
                # render
                self.scene.render(pMatrix, mvMatrix)
                # step 
                self.scene.step()

                glfw.glfwSwapBuffers(self.win)
                # Poll for and process events
                glfw.glfwPollEvents()
        # end
        glfw.glfwTerminate()
예제 #2
0
    def run(self):
        # initializer timer
        glfw.glfwSetTime(0)
        t = 0.0
        while not glfw.glfwWindowShouldClose(self.win) and not self.exitNow:
            # update every x seconds
            currT = glfw.glfwGetTime()
            if currT - t > 0.01:
                # update time
                t = currT

                # clear
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

                # render
                pMatrix = glutils.perspective(100.0, self.aspect, 0.1, 100.0)
                # modelview matrix
                mvMatrix = glutils.lookAt(self.camera.eye, self.camera.center,
                                          self.camera.up)

                # draw non-transparent object first
                self.box.render(pMatrix, mvMatrix)

                # render
                self.psys.render(pMatrix, mvMatrix, self.camera)

                # step
                self.step()

                glfw.glfwSwapBuffers(self.win)
                # Poll for and process events
                glfw.glfwPollEvents()
        # end
        glfw.glfwTerminate()
예제 #3
0
파일: psmain.py 프로젝트: diopib/pp
    def run(self):
        # initializer timer
        glfw.glfwSetTime(0)
        t = 0.0
        while not glfw.glfwWindowShouldClose(self.win) and not self.exitNow:
            # update every x seconds
            currT = glfw.glfwGetTime()
            if currT - t > 0.01:
                # update time
                t = currT

                # clear
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

                # render
                pMatrix = glutils.perspective(100.0, self.aspect, 0.1, 100.0)
                # modelview matrix
                mvMatrix = glutils.lookAt(self.camera.eye, self.camera.center, 
                                          self.camera.up)
                
                # draw non-transparent object first
                self.box.render(pMatrix, mvMatrix)

                # render
                self.psys.render(pMatrix, mvMatrix, self.camera)

                # step 
                self.step()

                glfw.glfwSwapBuffers(self.win)
                # Poll for and process events
                glfw.glfwPollEvents()
        # end
        glfw.glfwTerminate()
예제 #4
0
    def run(self):
        glfw.glfwSetTime(0)          # timer initialization
        t = 0.0
        while not glfw.glfwWindowShouldClose(self.win) and not self.exit_now:
            current_t = glfw.glfwGetTime()
            if current_t -t > 0.1:
                t = current_t         # time updated
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)                  # | = bitwise or

                # build projection matrix
                p_matrix = glutils.perspective(45.0, self.aspect, 0.1, 100.0)
                mv_matrix = glutils.lookAt([0.0, 0.0, -2.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0])
                # model-view matrix: [[eye pos], [look at {origin in this case)], [direction vector]]

                self.scene.render(p_matrix, mv_matrix)                        # render
                self.scene.step()                                             # step

                glfw.glfwSwapBuffers(self.win)
                glfw.glfwPollEvents()
예제 #5
0
 def run(self):
     glfw.glfwSetTime(0)
     t = 0.0
     while not glfw.glfwWindowShouldClose(self.win) and not self.exitNow:
         currT = glfw.glfwGetTime()
         #每隔0.1s绘一次图
         if currT - t > 0.1:
             t = currT
             #清除深度和颜色缓冲区
             glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
             #计算投影矩阵,45度视场,近/远裁剪平面的距离为0.1/100.0
             pMatrix = glutils.perspective(45.0, self.aspect, 0.1, 100.0)
             #设置模型视图矩阵,眼睛位置设置在(0,0,-2),用一个向上的矢量(0,1,0)看向原点(0,0,0)
             mvMatirx = glutils.lookAt([0.0, 0.0, -2.0], [0.0, 0.0, 0.0],
                                       [0.0, 1.0, 0.0])
             self.scene.render(pMatrix, mvMatirx)
             self.scene.step()
             #交换前后缓冲区, 显示更新的三维图像(双缓冲,更加流畅的视觉效果)
             glfw.glfwSwapBuffers(self.win)
             #调用检查所有UI事件,将控制返回给while循环
             glfw.glfwPollEvents()
     glfw.glfwTerminate()