def __init__(self): self.models = [] self.transform = [] #crea el "manto de un cubo fondo1 = bs.createTextureCube('fondo.jpg') gpufondo1 = es.toGPUShape(fondo1, GL_REPEAT, GL_NEAREST) self.models.append(gpufondo1) self.transform.append( tr.matmul([tr.uniformScale(24), tr.translate(-1, 0, 0.4)])) fondo2 = bs.createTextureCube('fondo.jpg') gpufondo2 = es.toGPUShape(fondo2, GL_REPEAT, GL_NEAREST) self.models.append(gpufondo1) self.transform.append( tr.matmul([tr.uniformScale(24), tr.translate(0, -1, 0.4)])) fondo3 = bs.createTextureCube('fondo.jpg') gpufondo3 = es.toGPUShape(fondo3, GL_REPEAT, GL_NEAREST) self.models.append(gpufondo1) self.transform.append( tr.matmul([tr.uniformScale(24), tr.translate(0, 1, 0.4)])) fondo4 = bs.createTextureCube('fondo.jpg') gpufondo4 = es.toGPUShape(fondo4, GL_REPEAT, GL_NEAREST) self.models.append(gpufondo1) self.transform.append( tr.matmul([tr.uniformScale(24), tr.translate(1, 0, 0.4)]))
def __init__(self, texture_1, texture_2, texture_3, texture_4, texture_5): # Creating shapes on GPU memory gpu_end_game_1 = es.toGPUShape(bs.createTextureCube(texture_1), GL_REPEAT, GL_LINEAR) gpu_end_game_2 = es.toGPUShape(bs.createTextureCube(texture_2), GL_REPEAT, GL_LINEAR) gpu_end_game_3 = es.toGPUShape(bs.createTextureCube(texture_3), GL_REPEAT, GL_LINEAR) gpu_end_game_4 = es.toGPUShape(bs.createTextureCube(texture_4), GL_REPEAT, GL_LINEAR) gpu_end_game_5 = es.toGPUShape(bs.createTextureCube(texture_5), GL_REPEAT, GL_LINEAR) # Saving textures self.texture_1 = gpu_end_game_1 self.texture_2 = gpu_end_game_2 self.texture_3 = gpu_end_game_3 self.texture_4 = gpu_end_game_4 self.texture_5 = gpu_end_game_5 # Setting Graph scene = sg.SceneGraphNode('scene') scene.transform = tr.uniformScale(2) scene.childs += [gpu_end_game_1] total_scene = sg.SceneGraphNode('total_scene') total_scene.childs += [scene] self.model = total_scene
def __init__(self, count, fondo): fondoa1 = bs.createTextureCube('azul.jpg') gpufondoa1 = es.toGPUShape(fondoa1, GL_REPEAT, GL_NEAREST) fondo.models.append(gpufondoa1) fondo.transform.append( tr.matmul([tr.uniformScale(24), tr.translate(-1, 0, 0.4 + count)])) fondoa2 = bs.createTextureCube('azul.jpg') gpufondoa2 = es.toGPUShape(fondoa2, GL_REPEAT, GL_NEAREST) fondo.models.append(gpufondoa2) fondo.transform.append( tr.matmul([tr.uniformScale(24), tr.translate(0, -1, 0.4 + count)])) fondoa3 = bs.createTextureCube('azul.jpg') gpufondoa3 = es.toGPUShape(fondoa3, GL_REPEAT, GL_NEAREST) fondo.models.append(gpufondoa3) fondo.transform.append( tr.matmul([tr.uniformScale(24), tr.translate(0, 1, 0.4 + count)])) fondoa4 = bs.createTextureCube('azul.jpg') gpufondoa4 = es.toGPUShape(fondoa4, GL_REPEAT, GL_NEAREST) fondo.models.append(gpufondoa4) fondo.transform.append( tr.matmul([tr.uniformScale(24), tr.translate(1, 0, 0.4 + count)]))
def Fondo(fondoE): color = es.toGPUShape(bs.createTextureCube("fondo2.jpg"),GL_REPEAT, GL_NEAREST) obama = es.toGPUShape(bs.createTextureCube("marco.png"),GL_REPEAT, GL_NEAREST) ricardo = es.toGPUShape(bs.createTextureCube("ricardo.jpg"),GL_REPEAT, GL_NEAREST) fondo1 = sg.SceneGraphNode("fondo1") fondo1.transform = tr.matmul([tr.translate(0,0,1) ,tr.uniformScale (15)]) fondo1.childs = [color] fondo2 = sg.SceneGraphNode("fondo2") fondo2.transform = tr.matmul([tr.translate(0,0,1) ,tr.uniformScale (15)]) fondo2.childs = [ricardo] fondo3 = sg.SceneGraphNode("fondo3") fondo3.transform = tr.matmul([tr.translate(0,0,1) ,tr.uniformScale (15)]) fondo3.childs = [obama] fondo = sg.SceneGraphNode("fondo") if fondoE == "C" : fondo.childs = [fondo1] if fondoE == "O" : fondo.childs = [fondo3] if fondoE == "R" : fondo.childs = [fondo2] return fondo
def crearCubos(): NormalCube = es.toGPUShape(bs.createTextureCube("base.png"),GL_REPEAT, GL_NEAREST) RequisitoDeCube = es.toGPUShape(bs.createTextureCube("base1.png"),GL_REPEAT, GL_NEAREST) SelectedCube = es.toGPUShape(bs.createTextureCube("base4.png"),GL_REPEAT, GL_NEAREST) RequisitoCube = es.toGPUShape(bs.createTextureCube("base3.png"),GL_REPEAT, GL_NEAREST) #Aqui se comienzan a crear los cubos de base CuboMorado = sg.SceneGraphNode("CuboMorado") #Se crea la base para el cubo morado CuboMorado.transform = tr.matmul([tr.translate(0.8,0,0), tr.uniformScale(0.5)]) CuboMorado.childs += [NormalCube] CuboTurquesa = sg.SceneGraphNode("CuboTurquesa") CuboTurquesa.transform = tr.matmul([tr.translate(0.27,0,0),tr.uniformScale(0.5)]) CuboTurquesa.childs += [RequisitoDeCube] CuboCeleste = sg.SceneGraphNode("CuboCeleste") CuboCeleste.transform = tr.matmul([tr.translate(-0.27,0,0),tr.uniformScale(0.5)]) CuboCeleste.childs += [RequisitoCube] CuboNaranjo = sg.SceneGraphNode("CuboNaranjo") CuboNaranjo.transform = tr.matmul([tr.translate(-0.8,0,0),tr.uniformScale(0.5)]) CuboNaranjo.childs += [SelectedCube] return CuboMorado,CuboTurquesa,CuboCeleste,CuboNaranjo
def __init__(self, texture_monkey, texture_monkey_jumping, texture_monkey_left, texture_monkey_right): # Creating shapes on GPU memory gpu_monkey_texture = es.toGPUShape( bs.createTextureCube(texture_monkey), GL_REPEAT, GL_LINEAR) gpu_monkey_texture_jumping = es.toGPUShape( bs.createTextureCube(texture_monkey_jumping), GL_REPEAT, GL_LINEAR) gpu_monkey_texture_left = es.toGPUShape( bs.createTextureCube(texture_monkey_left), GL_REPEAT, GL_LINEAR) gpu_monkey_texture_right = es.toGPUShape( bs.createTextureCube(texture_monkey_right), GL_REPEAT, GL_LINEAR) # Saving textures self.gpu_texture_monkey = gpu_monkey_texture self.gpu_texture_jumping = gpu_monkey_texture_jumping self.gpu_texture_left = gpu_monkey_texture_left self.gpu_texture_right = gpu_monkey_texture_right # Setting positions self.position_x = 0 self.position_y = -1 + 0.1 + 0.2 self.position_y_original = self.position_y self.position_x_original = self.position_x # Setting Graph body = sg.SceneGraphNode('body') body.transform = tr.uniformScale(1) body.childs += [gpu_monkey_texture] monkey = sg.SceneGraphNode('monkey') monkey.transform = tr.matmul([ tr.translate(self.position_x, self.position_y, 0), tr.scale(0.4, 0.4, 0) ]) monkey.childs += [body] transform_monkey = sg.SceneGraphNode('monkeyTR') transform_monkey.childs += [monkey] # Setting other useful variables self.model = transform_monkey self.aiming_x = self.position_x self.aiming_y = self.position_y self.is_falling = False self.is_jumping = False
def createBox(filename): gpuCube = es.toGPUShape(bs.createTextureCube(filename), GL_MIRRORED_REPEAT, GL_NEAREST) bgCube_scaled = sg.SceneGraphNode("bgCube_scaled") bgCube_scaled.transform = tr2.scale(9, 9, 9) bgCube_scaled.childs += [gpuCube] bgCube = sg.SceneGraphNode("bgCube_scaled") bgCube.transform = tr2.translate(0, 0, 0) bgCube.childs += [bgCube_scaled] return bgCube
def draw(self, pipeline_color, pipeline_texture, projection, view): # Dibujamos el mono de color con el pipeline_color glUseProgram(pipeline_color.shaderProgram) glUniformMatrix4fv( glGetUniformLocation(pipeline_color.shaderProgram, 'projection'), 1, GL_TRUE, projection) glUniformMatrix4fv( glGetUniformLocation(pipeline_color.shaderProgram, 'view'), 1, GL_TRUE, view) sg.drawSceneGraphNode(sg.findNode(self.model, 'body'), pipeline_color) # Dibujamos la cara (texturas) if self.show_face: glUseProgram(pipeline_texture.shaderProgram) glUniformMatrix4fv( glGetUniformLocation(pipeline_texture.shaderProgram, 'projection'), 1, GL_TRUE, projection) glUniformMatrix4fv( glGetUniformLocation(pipeline_texture.shaderProgram, 'view'), 1, GL_TRUE, view) if self.face_state == "feliz": gpu_head = es.toGPUShape(bs.createTextureCube(self.happy_face), GL_REPEAT, GL_LINEAR) sg.findNode(self.model, 'face').childs = [gpu_head] sg.drawSceneGraphNode(sg.findNode(self.model, 'face'), pipeline_texture) elif self.face_state == "triste": gpu_head = es.toGPUShape(bs.createTextureCube(self.sad_face), GL_REPEAT, GL_LINEAR) sg.findNode(self.model, 'face').childs = [gpu_head] sg.drawSceneGraphNode(sg.findNode(self.model, 'face'), pipeline_texture) else: gpu_head = es.toGPUShape( bs.createTextureCube(self.neutral_face), GL_REPEAT, GL_LINEAR) sg.findNode(self.model, 'face').childs = [gpu_head] sg.drawSceneGraphNode(sg.findNode(self.model, 'face'), pipeline_texture)
def createSpaceShip(): gpuCenterShip = es.toGPUShape( bs.createTextureSphere("textures/ssCenter.jpg"), GL_MIRRORED_REPEAT, GL_NEAREST) gpuBlock = es.toGPUShape(bs.createTextureCube("textures/ssBlock.jpg"), GL_REPEAT, GL_NEAREST) gpuPlane = es.toGPUShape(bs.createTextureHex("textures/ssWings.jpg"), GL_REPEAT, GL_NEAREST) spaceShipCenter = sg.SceneGraphNode("spaceShipCenter") spaceShipCenter.transform = tr2.scale(0.1, 0.1, 0.1) spaceShipCenter.childs += [gpuCenterShip] spaceShipBlock = sg.SceneGraphNode("spaceShipBlock") spaceShipBlock.transform = tr2.scale(0.02, 0.4, 0.02) spaceShipBlock.childs += [gpuBlock] spaceShipWingL = sg.SceneGraphNode("spaceShipLeftWing") spaceShipWingL.transform = np.matmul( tr2.translate(0.02, -0.2, 0.02), np.matmul(tr2.rotationX(np.pi / 2), tr2.scale(0.3, 0.3, 0.3))) spaceShipWingL.childs += [gpuPlane] spaceShipWingR = sg.SceneGraphNode("spaceShipRightWing") spaceShipWingR.transform = np.matmul( tr2.translate(0.02, 0.2, 0.02), np.matmul(tr2.rotationX(np.pi / 2), tr2.scale(0.3, 0.3, 0.3))) spaceShipWingR.childs += [gpuPlane] spaceShip_rotated = sg.SceneGraphNode("spaceShip_rotated") spaceShip_rotated.transform = np.matmul(tr2.rotationZ(0), tr2.rotationY(np.pi / 2)) spaceShip_rotated.childs += [ spaceShipCenter, spaceShipBlock, spaceShipWingR, spaceShipWingL ] spaceShip_scaled = sg.SceneGraphNode("spaceShip_scaled") spaceShip_scaled.transform = tr2.scale(0.5, 0.5, 0.5) spaceShip_scaled.childs += [spaceShip_rotated] spaceShip = sg.SceneGraphNode("spaceShip") spaceShip.transform = tr2.translate(0, 0, 0) spaceShip.childs += [spaceShip_scaled] return spaceShip
def __init__(self, texture, position_x, position_y): # Creating shapes on GPU memory gpu_structure = es.toGPUShape(bs.createTextureCube(texture), GL_REPEAT, GL_LINEAR) # Setting Graph structure = sg.SceneGraphNode('structure') width = 2 / 3 length = 0.1 structure.transform = tr.scale(width, length, 1) structure.childs += [gpu_structure] structure_tr = sg.SceneGraphNode('structureTR') structure_tr.childs += [structure] # Setting positions self.pos_y = position_y + 0.05 # -1, -0.5, 0, 0.5 self.pos_x = position_x # -2/3, 0, 2/3 self.model = structure_tr self.model.transform = tr.translate(self.pos_x, self.pos_y, 0)
def __init__(self, texture, position_x, position_y): # Creating shape on GPU memory gpu_banana = es.toGPUShape(bs.createTextureCube(texture), GL_REPEAT, GL_LINEAR) # Setting Graph banana = sg.SceneGraphNode('banana') width = 2 / 3 length = 0.3 banana.transform = tr.scale(width, length, 1) banana.childs += [gpu_banana] banana_tr = sg.SceneGraphNode('bananaTR') banana_tr.childs += [banana] # Setting positions self.pos_y = position_y + 0.05 + 0.17 # -1, -0.5, 0, 0.5 / + 0.5 +0.1 self.pos_x = position_x # -2/3, 0, 2/3 self.model = banana_tr self.model.transform = tr.translate(self.pos_x, self.pos_y, 0)
def createCar(r1, g1, b1, r2, g2, b2, isNormal): gpuBlackQuad = es.toGPUShape(bs.createCilindro(0, 0, 0), GL_REPEAT, GL_NEAREST) gpuChasisQuad_color1 = es.toGPUShape(bs.createTextureCube("militar.jpg"), GL_REPEAT, GL_NEAREST) gpuChasisQuad_color2 = es.toGPUShape(bs.createTextureCube("auto2.png"), GL_REPEAT, GL_NEAREST) gpuChasisPrism = es.toGPUShape( bs.createColorTriangularPrism(153 / 255, 204 / 255, 255 / 255)) # Cheating a single rueda auto = sg.SceneGraphNode("auto") auto.transform = tr2.scale(0.2, 0.8, 0.2) auto.childs += [gpuBlackQuad] rueda = sg.SceneGraphNode("rueda") rueda.transform = tr2.scale(0.2 / 6, 0.8 / 6, 0.2 / 6) rueda.childs += [gpuBlackQuad] ruedaRotation = sg.SceneGraphNode("ruedaRotation") ruedaRotation.childs += [rueda] # Instanciating 2 ruedas, for the front and back parts frontrueda = sg.SceneGraphNode("frontrueda") frontrueda.transform = tr2.translate(0.05, 0, -0.45) frontrueda.childs += [ruedaRotation] backrueda = sg.SceneGraphNode("backrueda") backrueda.transform = tr2.translate(-0.05, 0, -0.45) backrueda.childs += [ruedaRotation] # Creating the bottom chasis of the car bot_chasis = sg.SceneGraphNode("bot_chasis") bot_chasis.transform = tr2.scale(1 / 5, 0.5 / 5, 0.5 / 6) bot_chasis.childs += [gpuChasisQuad_color1] # Moving bottom chasis moved_b_chasis = sg.SceneGraphNode("moved_b_chasis") moved_b_chasis.transform = tr2.translate(0, 0, -0.4) moved_b_chasis.childs += [bot_chasis] ventana = sg.SceneGraphNode("ventana") ventana.transform = np.matmul(tr2.scale(0.6 / 4, 0.3 / 4, 0.3 / 4), tr2.translate(0, 0, -4.5)) ventana.childs += [gpuChasisQuad_color1] palito = sg.SceneGraphNode("palito") palito.transform = np.matmul(tr2.scale(0.2, 0.01, 0.01), tr2.translate(0.3, -0, -35), tr2.rotationY(np.pi / 6)) palito.childs += [gpuChasisQuad_color1] # Joining chasis parts complete_chasis = sg.SceneGraphNode("complete_chasis") complete_chasis.childs += [moved_b_chasis] complete_chasis.childs += [ventana] complete_chasis.childs += [palito] # All pieces together car = sg.SceneGraphNode("car") car.childs += [complete_chasis] car.childs += [frontrueda] car.childs += [backrueda] return car
# and which one is at the back glEnable(GL_DEPTH_TEST) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) # Using the same view and projection matrices in the whole application projection = tr.perspective(45, float(width) / float(height), 0.1, 100) # Generaremos diversas cámaras. static_view = tr.lookAt( np.array([10, 10, 5]), # eye np.array([0, 0, 0]), # at np.array([0, 0, 1]) # up ) view = static_view skyBox = bs.createTextureCube('skybox.png') sun = model.generateSphereShapeNormals(20, 20) GPUsun = es.toGPUShape(sun) GPUSkyBox = es.toGPUShape(skyBox, GL_REPEAT, GL_LINEAR) skybox_transform = tr.uniformScale(20) t0 = glfw.get_time() while not glfw.window_should_close(window): # Using GLFW to check for input events glfw.poll_events() t1 = glfw.get_time() dt = t1 - t0 t0 = t1 ctrl.updatePos(t0)
def __init__(self, texture_head): gpu_body = es.toGPUShape(bs.createColorCube(1, 0, 0)) gpu_leg = es.toGPUShape(bs.createColorCube(0, 0, 1)) gpu_skin = es.toGPUShape(bs.createColorCube(1, 1, 0)) gpu_head = es.toGPUShape(bs.createTextureCube(texture_head), GL_REPEAT, GL_LINEAR) # Creamos el nucleo core = sg.SceneGraphNode('core') core.transform = tr.scale(0.32, 0.5, 0.6) core.childs += [gpu_body] # Piernas leg = sg.SceneGraphNode('leg') leg.transform = tr.scale(0.14, 0.14, 0.5) leg.childs += [gpu_leg] leg_left = sg.SceneGraphNode('leg_left') leg_left.transform = tr.translate(0, -0.17, -0.5) leg_left.childs += [leg] leg_right = sg.SceneGraphNode('leg_right') leg_right.transform = tr.translate(0, 0.17, -0.5) leg_right.childs += [leg] # Brazos arm = sg.SceneGraphNode('arm') arm.transform = tr.scale(0.13, 0.5, 0.13) arm.childs += [gpu_skin] arm_left = sg.SceneGraphNode('arm_left') arm_left.transform = tr.translate(0, -0.4, 0.23) arm_left.childs += [arm] arm_right = sg.SceneGraphNode('arm_right') arm_right.transform = tr.translate(0, 0.4, 0.23) arm_right.childs += [arm] # Cuello neck = sg.SceneGraphNode('neck') neck.transform = tr.matmul( [tr.scale(0.12, 0.12, 0.2), tr.translate(0, 0, 1.6)]) neck.childs += [gpu_skin] # Cabeza head = sg.SceneGraphNode('head') head.transform = tr.matmul( [tr.scale(0.35, 0.35, 0.35), tr.translate(-0.08, 0, 1.75)]) head.childs += [gpu_skin] body = sg.SceneGraphNode('body') body.childs += [ arm_left, arm_right, leg_left, leg_right, core, neck, head ] face = sg.SceneGraphNode('face') face.transform = tr.matmul( [tr.scale(0.3, 0.3, 0.3), tr.translate(0, 0, 2)]) face.childs += [gpu_head] body_tr = sg.SceneGraphNode('bodyTR') body_tr.childs += [body, face] self.face = face self.body = body self.model = body_tr self.show_face = True
# Telling OpenGL to use our shader program glUseProgram(pipeline.shaderProgram) # Setting up the clear screen color glClearColor(0.15, 0.15, 0.15, 1.0) # As we work in 3D, we need to check which part is in front, # and which one is at the back glEnable(GL_DEPTH_TEST) # Creating shapes on GPU memory gpuAxis = es.toGPUShape(bs.createAxis(7)) gpuRedCube = es.toGPUShape(bs.createColorCube(1, 0, 0)) gpuGreenCube = es.toGPUShape(bs.createTextureCube("dice_blue.jpg"), GL_REPEAT, GL_NEAREST) gpuBlueCube = es.toGPUShape(bs.createColorCube(0, 0, 1)) gpuYellowCube = es.toGPUShape(bs.createColorCube(1, 1, 0)) gpuCyanCube = es.toGPUShape(bs.createColorCube(0, 1, 1)) gpuPurpleCube = es.toGPUShape(bs.createColorCube(1, 0, 1)) gpuRainbowCube = es.toGPUShape(bs.createRainbowCube()) t0 = glfw.get_time() camera_theta = np.pi / 4 while not glfw.window_should_close(window): # Using GLFW to check for input events glfw.poll_events() # Getting the time difference from the previous iteration
def Amy_jump(estructura): if __name__ == "__main__": # Initialize glfw if not glfw.init(): sys.exit() width = 700 height = 700 window = glfw.create_window(width, height, "Amy Jump", None, None) if not window: glfw.terminate() sys.exit() glfw.make_context_current(window) # Connecting the callback function 'on_key' to handle keyboard events glfw.set_key_callback(window, on_key) # Defining shader programs pipeline = ls.SimpleGouraudShaderProgram() texture_pipeline = es.SimpleTextureModelViewProjectionShaderProgram() color_pipeline = es.SimpleModelViewProjectionShaderProgram() tex_pipeline = es.SimpleTextureTransformShaderProgram() # Telling OpenGL to use our shader program glUseProgram(pipeline.shaderProgram) # Setting up the clear screen color glClearColor(0.85, 0.85, 0.85, 1.0) # As we work in 3D, we need to check which part is in front, # and which one is at the back glEnable(GL_DEPTH_TEST) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) # Creamos los objetos # Amy gpuAmy = es.toGPUShape(shape=readOBJ('amy.obj', (1, 0, 0.5))) # Anillo (trofeo) gpuAnillo = es.toGPUShape(shape=readOBJ('ring.obj', (0.9, 0.9, 0))) # Fondo fondo = Fondo() #Piso piso = bs.createTextureCube('piso.jpg') gpupiso = es.toGPUShape(piso, GL_REPEAT, GL_LINEAR) piso_transform = tr.matmul( [tr.uniformScale(24), tr.translate(0, 0, -0.53)]) # Pantalla de inicio amyi = es.toGPUShape(bs.createTextureQuad("amy2.png", 1, 1), GL_REPEAT, GL_LINEAR) # Pantala de perdida eggman = es.toGPUShape(bs.createTextureQuad("eggman.png", 1, 1), GL_REPEAT, GL_LINEAR) # Pantalla de ganador amyf = es.toGPUShape(bs.createTextureQuad("am.png", 1, 1), GL_REPEAT, GL_LINEAR) # Barras barras = CreateBarras() barras.create(estructura) #Revisamos el tiempo t0 = glfw.get_time() # Posiciones de Amy posX = 0 posY = 0 posZ = 0.5 #Cuenta los fondo que ya se crearon count = 1 # Indica hasta que altura se debe llegar al saltar alt = 0 # Dice si se puede saltar o no salto = True #Indica cuando se "pierde" por saltar mal perder = False #Indica cuando se pierde por una flecha perder2 = False # Dice si se debe mandar una flecha de ataque arrow = True #Se crea la flecha con las posiciones hacia Amy flechas = Flecha(posX, posY, posZ) #Tamaño inicial de la imagen de partida, de perdida y de ganador ag = 2 eg = 0 af = 0 # rotaciones de Amy rotz = np.pi rotx = np.pi / 2 roty = 0 #Indica si ya estuvo en una barra bt = False #Rotaciones y posiciones del aro ra = 0 x = 0 y = 0 #Indica si gana o pierde ganar = False while not glfw.window_should_close(window): # Using GLFW to check for input events glfw.poll_events() # Getting the time difference from the previous iteration t1 = glfw.get_time() dt = t1 - t0 t0 = t1 #Se define la vista "fija" del juego view = tr.lookAt(np.array([12, -5, 8 + (posZ - 0.5)]), np.array([posX * 0.4, posY * 0.4, posZ]), np.array([0, 0, 1])) #Cambia la vista mientras se mantengan apretadas las teclas if (glfw.get_key(window, glfw.KEY_B) == glfw.PRESS): view = tr.lookAt(np.array([0, 1, 17.5 + (posZ)]), np.array([0, 0, 0]), np.array([0, 0, 1])) if (glfw.get_key(window, glfw.KEY_N) == glfw.PRESS): view = tr.lookAt(np.array([-12, -5, 7.5 + posZ]), np.array([posX, posY, posZ]), np.array([0, 0, 1])) if (glfw.get_key(window, glfw.KEY_M) == glfw.PRESS): view = tr.lookAt(np.array([0, 10, -0.5 + posZ]), np.array([posX, posY, posZ]), np.array([0, 0, 1])) # Setting up the projection transform projection = tr.perspective(60, float(width) / float(height), 0.1, 100) # Clearing the screen in both, color and depth glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) #Dibujamos el fondo fondo.Draw(texture_pipeline, projection, view) # Revisamos si se debe crear otro fondo if posZ > 13 * count: fondoazul = FondoAzul(count, fondo) count += 1 #Dibujamos el piso glUseProgram(texture_pipeline.shaderProgram) glUniformMatrix4fv( glGetUniformLocation(texture_pipeline.shaderProgram, "model"), 1, GL_TRUE, piso_transform) glUniformMatrix4fv( glGetUniformLocation(texture_pipeline.shaderProgram, "projection"), 1, GL_TRUE, projection) glUniformMatrix4fv( glGetUniformLocation(texture_pipeline.shaderProgram, "view"), 1, GL_TRUE, view) texture_pipeline.drawShape(gpupiso) # Luz glUseProgram(pipeline.shaderProgram) glUniform3f(glGetUniformLocation(pipeline.shaderProgram, "La"), 1.0, 1.0, 1.0) glUniform3f(glGetUniformLocation(pipeline.shaderProgram, "Ld"), 1.0, 1.0, 1.0) glUniform3f(glGetUniformLocation(pipeline.shaderProgram, "Ls"), 1.0, 1.0, 1.0) glUniform3f(glGetUniformLocation(pipeline.shaderProgram, "Ka"), 0.3, 0.3, 0.3) glUniform3f(glGetUniformLocation(pipeline.shaderProgram, "Kd"), 0.9, 0.9, 0.9) glUniform3f(glGetUniformLocation(pipeline.shaderProgram, "Ks"), 0.2, 0.2, 0.2) glUniform3f( glGetUniformLocation(pipeline.shaderProgram, "lightPosition"), 0, 0, posZ + 5) glUniform3f( glGetUniformLocation(pipeline.shaderProgram, "viewPosition"), 0, 0, posZ + 5) glUniform1ui( glGetUniformLocation(pipeline.shaderProgram, "shininess"), 1000) glUniform1f( glGetUniformLocation(pipeline.shaderProgram, "constantAttenuation"), 0.01) glUniform1f( glGetUniformLocation(pipeline.shaderProgram, "linearAttenuation"), 0.1) glUniform1f( glGetUniformLocation(pipeline.shaderProgram, "quadraticAttenuation"), 0.01) #Dibujamos a Amy glUniformMatrix4fv( glGetUniformLocation(pipeline.shaderProgram, "projection"), 1, GL_TRUE, projection) glUniformMatrix4fv( glGetUniformLocation(pipeline.shaderProgram, "view"), 1, GL_TRUE, view) glUniformMatrix4fv( glGetUniformLocation(pipeline.shaderProgram, "model"), 1, GL_TRUE, tr.matmul([ tr.translate(posX, posY, posZ), tr.rotationZ(rotz), tr.rotationX(rotx), tr.rotationY(roty), tr.uniformScale(0.4) ])) pipeline.drawShape(gpuAmy) #Dibujamos el anillo a la altura de la ultima barra glUniformMatrix4fv( glGetUniformLocation(pipeline.shaderProgram, "model"), 1, GL_TRUE, tr.matmul([ tr.translate(x, y, barras.altura * 2), tr.rotationZ(ra), tr.uniformScale(0.5) ])) pipeline.drawShape(gpuAnillo) # Dibujamos la pantalla inicial glUseProgram(tex_pipeline.shaderProgram) glUniformMatrix4fv( glGetUniformLocation(tex_pipeline.shaderProgram, "transform"), 1, GL_TRUE, tr.matmul([tr.translate(0, 0, 0), tr.uniformScale(ag)])) tex_pipeline.drawShape(amyi) # Dibujamos la pantalla de perdida glUniformMatrix4fv( glGetUniformLocation(tex_pipeline.shaderProgram, "transform"), 1, GL_TRUE, tr.matmul([tr.translate(0, 0, 0), tr.uniformScale(eg)])) tex_pipeline.drawShape(eggman) # Dibujamos la pantalla de ganador glUniformMatrix4fv( glGetUniformLocation(tex_pipeline.shaderProgram, "transform"), 1, GL_TRUE, tr.matmul([tr.translate(0, 0, 0), tr.uniformScale(af)])) tex_pipeline.drawShape(amyf) # Hace una copia de la lista de barras b = barras.barras #Indica que hay gravedad por lo cual amy va a caer mientras no este en una plataforma grav = True #Cambia el angulo de de rotación del aro ra -= 2 * dt #Revisa que la posición de las barras calza con Amy for i in range(len(b)): if posX <= 2 * b[i].posx + 1 and posX >= 2 * b[ i].posx - 1 and posY <= 2 * b[ i].posy + 1 and posY >= 2 * b[ i].posy - 1 and posZ <= b[ i].posz * 0.3 + 1.4 and posZ >= b[ i].posz * 0.3 + 1.25: if b[i].real == False: #Revisa si la barra es real, de serlo no la dibuja y no apaga la gravedad b[i].dibujo = False else: grav = False #si no, apaga la gravedad bt = True #indica que ya se subio una barra # Implementa la gravedad if posZ > 0.6 and grav == True: posZ -= 3 * dt #Mueve a Amy dependiendo de la tecla que se precione if (glfw.get_key(window, glfw.KEY_A) == glfw.PRESS): if posX > -6: posX -= 5 * dt if (glfw.get_key(window, glfw.KEY_D) == glfw.PRESS): if posX < 6: posX += 5 * dt if (glfw.get_key(window, glfw.KEY_W) == glfw.PRESS): if posY < 6: posY += 5 * dt if (glfw.get_key(window, glfw.KEY_S) == glfw.PRESS): if posY > -6: posY -= 5 * dt #Implementa los saltos if (glfw.get_key(window, glfw.KEY_SPACE) == glfw.PRESS): #si se puede saltar if salto == True: salto = False #se bloquea otro salto alt = 2 + posZ #calcula hasta donde debe llegar #si no pierde y no llega al limite de altura if alt >= posZ and perder == False: posZ += 5 * dt #salta #Si esta en una barra y aún no pierde if grav == False and perder2 == False: salto = True #Puede volver a saltar perder = False #aún no pierde #Inidica que perdio if alt < posZ + 0.01: perder = True # Si es que se puede hacer una flecha if arrow == True: ti = t1 #Revisamos el tiempo actual arrow = False #decimos que no se pueden hacer mas flechas flechas = Flecha(posX, posY, posZ) #se indica las posicones de la flecha # Si ya pasa un tiempo especifico if ti + 3 < t1: arrow = True # se puede hacer otra flecha #Revisamos que una flecha toca a Amy if flechas.posx <= posX + 0.1 and flechas.posx >= posX - 0.1 and flechas.posy <= -posY * 0.2 + 0.1 and flechas.posy >= -posY * 0.2 - 0.1 and flechas.posz <= posZ * 0.2 + 0.1 and flechas.posz >= posZ * 0.2 - 0.1: perder2 = True #Pierde #Mueve las flechas a partir de un tiempo en especifico if t1 > 8: flechas.update(4 * dt) flechas.draw(pipeline, projection, view) #Hace el movimiento de la imagen inicial if t1 < 8: if ag > 0: ag -= dt #Si pierde genera la imagen de game over y Amy empieza a rotar if ((posZ >= 0.5 and posZ <= 0.6 and grav and bt) or perder2 or (salto == False and posZ >= 0.5 and posZ <= 0.6)) and ganar == False: if eg < 2: eg += 0.8 * dt rotx -= 2 * dt rotz -= 2 * dt #Indica cuando gana if barras.altura * 2 - posZ <= 0.5 and barras.altura * 2 - posZ >= 0 and grav == False: ganar = True #Mueve el aro a Amy if x < 1.7 * posX: x += 5 * dt elif x >= 1.7 * posX: x -= 5 * dt if y < 1 * posY: y += 5 * dt elif y >= 1 * posY: y -= 5 * dt #Hace el movimiento de la imagen de ganador if af < 2: af += 0.8 * dt #Dibuja las barras barras.draw(color_pipeline, projection, view) # Once the drawing is rendered, buffers are swap so an uncomplete drawing is never seen. glfw.swap_buffers(window) glfw.terminate()
def __init__(self, texture0, texture1, texture2, texture3, texture4, texture5, texture6, texture7, texture8, texture9, texture10, position_x, position_y): # Creating shapes on GPU memory gpu_background_top = es.toGPUShape(bs.createTextureCube(texture0), GL_REPEAT, GL_LINEAR) gpu_background1 = es.toGPUShape(bs.createTextureCube(texture1), GL_REPEAT, GL_LINEAR) gpu_background2 = es.toGPUShape(bs.createTextureCube(texture2), GL_REPEAT, GL_LINEAR) gpu_background3 = es.toGPUShape(bs.createTextureCube(texture3), GL_REPEAT, GL_LINEAR) gpu_background4 = es.toGPUShape(bs.createTextureCube(texture4), GL_REPEAT, GL_LINEAR) gpu_background5 = es.toGPUShape(bs.createTextureCube(texture5), GL_REPEAT, GL_LINEAR) gpu_background6 = es.toGPUShape(bs.createTextureCube(texture6), GL_REPEAT, GL_LINEAR) gpu_background7 = es.toGPUShape(bs.createTextureCube(texture7), GL_REPEAT, GL_LINEAR) gpu_background8 = es.toGPUShape(bs.createTextureCube(texture8), GL_REPEAT, GL_LINEAR) gpu_background9 = es.toGPUShape(bs.createTextureCube(texture9), GL_REPEAT, GL_LINEAR) gpu_background_bottom = es.toGPUShape(bs.createTextureCube(texture10), GL_REPEAT, GL_LINEAR) # Saving textures self.texture_0 = gpu_background_top self.texture_1 = gpu_background1 self.texture_2 = gpu_background2 self.texture_3 = gpu_background3 self.texture_4 = gpu_background4 self.texture_5 = gpu_background5 self.texture_6 = gpu_background6 self.texture_7 = gpu_background7 self.texture_8 = gpu_background8 self.texture_9 = gpu_background9 self.texture_10 = gpu_background_bottom # Setting Graph background = sg.SceneGraphNode('background') width = 2 length = 2 / 4 background.transform = tr.scale(width, length, 1) background.childs += [gpu_background_top] background_tr = sg.SceneGraphNode('backgroundTR') background_tr.childs += [background] # Setting positions self.pos_y = position_y self.pos_x = position_x self.model = background_tr self.model.transform = tr.translate(self.pos_x, self.pos_y + 0.25, 0)
def createEdificio(): gpuBase = es.toGPUShape(bs.createTextureCube("textura.jpg"), GL_REPEAT, GL_NEAREST) gpuLados = es.toGPUShape(bs.createTextureCube("textura.jpg"), GL_REPEAT, GL_NEAREST) gpuBase2 = es.toGPUShape(bs.createTextureCube("techo.jpg"), GL_REPEAT, GL_NEAREST) gpuAntena = es.toGPUShape(bs.createTextureCube("metal.jpg"), GL_REPEAT, GL_NEAREST) gpuAntena1 = es.toGPUShape(bs.createCilindro(0, 0, 0)) base = sg.SceneGraphNode("base") base.transform = np.matmul(tr2.scale(0.8 / 2, 0.7 / 2, 0.1875 / 2), tr2.translate(0, 0, 0.5)) base.childs += [gpuBase] lados = sg.SceneGraphNode("lados") lados.transform = np.matmul(tr2.translate(0.15, 0, 0.2), tr2.scale(0.0875 / 2, 0.468 / 2, 0.625 / 2)) lados.childs += [gpuLados] lados1 = sg.SceneGraphNode("lados1") lados1.transform = np.matmul(tr2.translate(-0.15, 0, 0.2), tr2.scale(0.0875 / 2, 0.468 / 2, 0.625 / 2)) lados1.childs += [gpuLados] base2 = sg.SceneGraphNode("base2") base2.transform = np.matmul(tr2.scale(0.495 / 2, 0.545 / 2, 0.645 / 2), tr2.translate(0, 0, 0.7)) base2.childs += [gpuBase] base3 = sg.SceneGraphNode("base3") base3.transform = np.matmul(tr2.scale(0.32 / 2, 0.32 / 2, 2 / 2), tr2.translate(0, 0, 0.8)) base3.childs += [gpuBase] base4 = sg.SceneGraphNode("base4") base4.transform = np.matmul(tr2.scale(0.25 / 2, 0.25 / 2, 0.05 / 2), tr2.translate(0, 0, 52.5)) base4.childs += [gpuBase2] base5 = sg.SceneGraphNode("base4") base5.transform = np.matmul(tr2.scale(0.2 / 2, 0.2 / 2, 0.05 / 2), tr2.translate(0, 0, 53.5)) base5.childs += [gpuBase2] base6 = sg.SceneGraphNode("base4") base6.transform = np.matmul(tr2.scale(0.15 / 2, 0.15 / 2, 0.05 / 2), tr2.translate(0, 0, 54.5)) base6.childs += [gpuBase2] antena = sg.SceneGraphNode("antena") antena.transform = np.matmul(tr2.scale(0.015, 0.015, 0.3), tr2.translate(0, 0, 4.5)) antena.childs += [gpuAntena] antena1 = sg.SceneGraphNode("antena1") antena1.transform = np.matmul(tr2.scale(0.01, 0.01, 0.3), tr2.translate(0, 0, 5)) antena1.childs += [gpuAntena] antena2 = sg.SceneGraphNode("antena2") antena2.transform = np.matmul(tr2.scale(0.005, 0.005, 0.3), tr2.translate(0, 0, 6)) antena2.childs += [gpuAntena] lados_1 = sg.SceneGraphNode("lado_1") lados_1.transform = np.matmul(tr2.scale(0.1 / 2, 0.5 / 2, 1.2 / 2), tr2.translate(1.55, 0, 1.15)) lados_1.childs += [gpuLados] lados_2 = sg.SceneGraphNode("lado_2") lados_2.transform = np.matmul(tr2.scale(0.1 / 2, 0.5 / 2, 1.2 / 2), tr2.translate(-1.55, 0, 1.15)) lados_2.childs += [gpuLados] lados_3 = sg.SceneGraphNode("lado_2") lados_3.transform = np.matmul(tr2.scale(0.09 / 2, 0.4 / 2, 0.4 / 2), tr2.translate(1.65, 0, 5.4)) lados_3.childs += [gpuLados] lados_4 = sg.SceneGraphNode("lado_2") lados_4.transform = np.matmul(tr2.scale(0.09 / 2, 0.4 / 2, 0.4 / 2), tr2.translate(-1.65, 0, 5.4)) lados_4.childs += [gpuLados] edificio = sg.SceneGraphNode("edificio") edificio.childs += [lados] edificio.childs += [lados1] edificio.childs += [base] edificio.childs += [base2] edificio.childs += [base3] edificio.childs += [base4] edificio.childs += [base5] edificio.childs += [base6] edificio.childs += [lados_1] edificio.childs += [lados_2] edificio.childs += [lados_3] edificio.childs += [lados_4] edificio.childs += [antena] edificio.childs += [antena1] edificio.childs += [antena2] return edificio