本文整理匯總了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()