本文整理汇总了Python中box.Box.render方法的典型用法代码示例。如果您正苦于以下问题:Python Box.render方法的具体用法?Python Box.render怎么用?Python Box.render使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类box.Box
的用法示例。
在下文中一共展示了Box.render方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from box import Box [as 别名]
# 或者: from box.Box import render [as 别名]
#.........这里部分代码省略.........
# make a window
self.width, self.height = 640, 480
self.aspect = self.width/float(self.height)
self.win = glfw.glfwCreateWindow(self.width, self.height,
b"Particle System")
# make context current
glfw.glfwMakeContextCurrent(self.win)
# initialize GL
glViewport(0, 0, self.width, self.height)
glEnable(GL_DEPTH_TEST)
glClearColor(0.2, 0.2, 0.2,1.0)
# set window callbacks
glfw.glfwSetMouseButtonCallback(self.win, self.onMouseButton)
glfw.glfwSetKeyCallback(self.win, self.onKeyboard)
glfw.glfwSetWindowSizeCallback(self.win, self.onSize)
# create 3D
self.psys = ParticleSystem(self.numP)
self.box = Box(1.0)
# exit flag
self.exitNow = False
def onMouseButton(self, win, button, action, mods):
#print 'mouse button: ', win, button, action, mods
pass
def onKeyboard(self, win, key, scancode, action, mods):
#print 'keyboard: ', win, key, scancode, action, mods
if action == glfw.GLFW_PRESS:
# ESC to quit
if key == glfw.GLFW_KEY_ESCAPE:
self.exitNow = True
elif key == glfw.GLFW_KEY_R:
self.rotate = not self.rotate
elif key == glfw.GLFW_KEY_B:
# toggle billboarding
self.psys.enableBillboard = not self.psys.enableBillboard
elif key == glfw.GLFW_KEY_D:
# toggle depth mask
self.psys.disableDepthMask = not self.psys.disableDepthMask
elif key == glfw.GLFW_KEY_T:
# toggle transparency
self.psys.enableBlend = not self.psys.enableBlend
def onSize(self, win, width, height):
#print 'onsize: ', win, width, height
self.width = width
self.height = height
self.aspect = width/float(height)
glViewport(0, 0, self.width, self.height)
def step(self):
# inc time
self.t += 10
self.psys.step()
# rotate eye
if self.rotate:
self.camera.rotate()
# restart every 5 seconds
if not int(self.t) % 5000:
self.psys.restart(self.numP)
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()