# Creating shapes on GPU memory cars = createCars(pipeline, 5) # Our shapes here are always fully painted glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) while not glfw.window_should_close(window): # Using GLFW to check for input events glfw.poll_events() # Clearing the screen in both, color and depth glClear(GL_COLOR_BUFFER_BIT) # Modifying only a specific node in the scene graph wheelRotationNode = sg.findNode(cars, "wheelRotation") theta = -10 * glfw.get_time() wheelRotationNode.transform = tr.rotationZ(theta) # Modifying only car 3 car3 = sg.findNode(cars, "scaledCar3") car3.transform = tr.translate(0.3, 0.5 * np.sin(0.1 * theta), 0) # Uncomment to see the position of scaledCar_3, it will fill your terminal #print("car3Position =", sg.findPosition(cars, "scaledCar3")) # Drawing the Car sg.drawSceneGraphNode(cars, pipeline, "transform") # Once the render is done, buffers are swapped, showing only the complete scene. glfw.swap_buffers(window)
while not glfw.window_should_close(window): # Using GLFW to check for input events glfw.poll_events() if (controller.fillPolygon): glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) else: glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) # Clearing the screen in both, color and depth glClear(GL_COLOR_BUFFER_BIT) theta = np.sin(3.0 * glfw.get_time()) leftArm = sg.findNode(snowman, "leftArm") leftArm.transform = tr.matmul([ tr.translate(-7, 7, 0), tr.rotationZ(theta), #tr.scale(1, 1, 1) ]) rightArm = sg.findNode(snowman, "rightArm") rightArm.transform = tr.matmul([ tr.translate(7, 7, 0), tr.rotationZ(theta), #tr.scale(1, 1, 1) ]) # Drawing the Car sg.drawSceneGraphNode(
# Creacion humanos gpuHuman = createHumanModel(tex_pipeline) # Creacion tienda store_scene = createStoreModel(pipeline) store = Store([-0.8, 1.5]) store.setModel(store_scene) fullStoreNode = csg.CustomSceneGraphNode("fullStore") fullStoreNode.childs = [store_scene] # Creacion texto victoria y derrota textScene = createText(tex_pipeline) gameOverScene = sg.findNode(textScene, "gameOver") gameOverScene.transform = tr.translate(game_over_pos, 0, 0) victoryScene = sg.findNode(textScene, "victory") # glfw will swap buffers as soon as possible glfw.swap_interval(0) t0 = glfw.get_time() ### Test # Application loop while not glfw.window_should_close(window): # Variables del tiempo t1 = glfw.get_time() delta = t1 - t0 t0 = t1
# Filling or not the shapes depending on the controller state if (controller.fillPolygon): glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) else: glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) if controller.showAxis: glUniformMatrix4fv( glGetUniformLocation(mvpPipeline.shaderProgram, "model"), 1, GL_TRUE, tr.identity()) mvpPipeline.drawCall(gpuAxis, GL_LINES) # Moving the red car and rotating its wheels redCarNode.transform = tr.translate(3 * np.sin(glfw.get_time()), 0, 0.5) redWheelRotationNode = sg.findNode(redCarNode, "wheelRotation") redWheelRotationNode.transform = tr.rotationY(-10 * glfw.get_time()) # Uncomment to print the red car position on every iteration #print(sg.findPosition(redCarNode, "car")) # Drawing the Car sg.drawSceneGraphNode(redCarNode, mvpPipeline, "model") sg.drawSceneGraphNode(blueCarNode, mvpPipeline, "model") # Once the render is done, buffers are swapped, showing only the complete scene. glfw.swap_buffers(window) # freeing GPU memory gpuAxis.clear() redCarNode.clear()