def addEnemies2(enemies_collection, amount): global enemy_counter, enemy2_center #se inicializan los valores para el centro de rotacion enemy2_center[0] = 0 enemy2_center[1] = ENEMY2_SPAWN_POSY #angulo para distribuir radialmente a las naves tempTheta = 2 * np.pi / amount # se distribuyen los enemigos en la pantalla segun su cantidad for enemy in range(amount): # se crea el controlador de animaciones y se inicializa enemy_anim = anim.Anim_Controller(enemy2_animations, [ENEMY2_SIZE, ENEMY2_SIZE * WIDTH/HEIGHT, 1], 0) enemy_anim.Play("flying") # se define su posicion temp_posX = enemy2_center[0] + enemy2_radio * math.cos(tempTheta * enemy) * 2.5 temp_posY = enemy2_center[1] + enemy2_radio * math.sin(tempTheta * enemy)* WIDTH / HEIGHT # se crea un nodo que contiene la animacion y que la voltea scaled_enemy = sg.SceneGraphNode("scaled_enemy") scaled_enemy.transform = tr.rotationZ(np.pi) scaled_enemy.childs += [enemy_anim] # se crea un nodo con una gpuShape que servira para detectar las colisiones y verlas si se quiere collision_node = sg.SceneGraphNode("collision_enemy2") collision_node.transform = tr.scale(1, 1* WIDTH / HEIGHT, 1) collision_node.childs += [es.toGPUShape(cl.createCircleHitbox(ENEMY2_HITBOX_RADIO, 10, 0, 1, 0))] # se crea uno nodo/objeto CollisionShape que tiene informacion y metodos para detectar colisiones con respecto de una gpuShape scaled_collision = cl.CollisionShape("scaled_collision", ENEMY2_HITBOX_RADIO, True) scaled_collision.transform = tr.rotationZ(np.pi) scaled_collision.childs += [collision_node] # se crea el objeto enemy que contendra como nodos hijos a la animacion y la hitbox enemy_object = enemyObject("enemy" + str(enemy_counter)) enemy_object.theta = tempTheta * enemy enemy_object.enemy = 2 # es el tercer tipo de enemigos # se traslada la nave en la pantalla a su posicion inicial enemy_object.transform = tr.translate(temp_posX, temp_posY, 0) enemy_object.position[0] = temp_posX enemy_object.position[1] = temp_posY enemy_object.position[2] = 0 enemy_object.velocity = [0, ENEMY2_CENTER_SPEED, 0] #se indica la velocidad del centro de rotacion enemy_object.childs += [scaled_enemy] #se agrega la animacion enemy_object.childs += [scaled_collision] #se agrega la hitbox enemy_object.childs[1].parent = enemy_object # se agrega la referencia de padre al objeto CollisionShape # se le agrega la animacion de su bala correspondiente enemy_object.bullet_animations = bullet2_animation enemy_counter += 1 # se agrega el objeto enemy a la coleccion de enemigos enemies_collection.childs += [enemy_object]
def createFish(r, g, b): gpu_body = es.toGPUShape(bs.createColorCube(r, g, b)) gpu_tail = es.toGPUShape(bs.createColorCube(r, g, b)) # Body of the fish body = sg.SceneGraphNode('body') body.transform = tr.matmul([tr.uniformScale(2), tr.scale(0.6, 0.2, 0.3)]) body.childs += [gpu_body] # Tail of the fish tail = sg.SceneGraphNode('tail') tail.transform = tr.matmul([tr.uniformScale(2), tr.translate(-0.4, 0, 0), tr.scale(0.2, 0.05, 0.2)]) tail.childs += [gpu_tail] tailRotation = sg.SceneGraphNode('tailRotation') tailRotation.childs += [tail] # Creating the fish fish = sg.SceneGraphNode('fish') fish.childs += [body] fish.childs += [tailRotation] return fish
def createShot(): gpuWhiteQuad = es.toGPUShape(bs.createColorQuad(1, 1, 1)) # Creating a single shot shot = sg.SceneGraphNode("shot") shot.transform = tr.matmul([tr.translate(ship.pos_x, ship.pos_y, 0), tr.scale(0.1, 0.3, 0), tr.uniformScale(0.2)]) shot.childs += [gpuWhiteQuad] shots = sg.SceneGraphNode("shots") shots.childs += [shot] shots.pos_x = ship.pos_x shots.pos_y = ship.pos_y return shots
def __init__(self): gpu_egg = es.toGPUShape(bs.createColorQuad(0.7, .7, .7)) egg = sg.SceneGraphNode('egg') width = random.choice([0.1, 0.2]) long = random.choice([0.1, 0.2]) egg.transform = tr.scale(width, long, 1) egg.childs += [gpu_egg] egg_tr = sg.SceneGraphNode('eggTR') egg_tr.childs += [egg] self.pos_y = 1 self.pos_x = random.choice([-1, 0, 1]) # LOGICA self.model = egg_tr
def create_gameover_screen(filename): # filename - File path of game over texture # Load background image gpuGameOver = es.toGPUShape(bs.createTextureQuad(filename), GL_REPEAT, GL_LINEAR) #Create two background copies to have a scrolling effect gameover = sg.SceneGraphNode("gameover") gameover.transform = tr.scale(2, 2, 1) gameover.childs = [gpuGameOver] # Node to control vertical movement of the two gameovers objects gameoverVertical = sg.SceneGraphNode("gameoverVertical") gameoverVertical.childs = [gameover] return gameoverVertical
def game_over(self): gpu_game_over = es.toGPUShape(bs.createTextureQuad("game_over.png"), GL_CLAMP, GL_NEAREST) game_over = sg.SceneGraphNode('game_over_banner') game_over.transform = tr.matmul( [tr.scale(2.3, 1 / 5, 0), tr.translate(0, 0, 0)]) # traslation to top was 4.5 game_over.childs += [gpu_game_over] game_over_tr = sg.SceneGraphNode('game_over_banner_TR') game_over_tr.childs += [game_over] self.g_over = game_over_tr self.alive = False
def setupPlayer(image, main_node): #Se crean los distintos frames para cada animacion, recortando la imagen ship_frames1 = anim.createFrames(image, [128, 128], [0, 0], [2], [0, 0]) #animacion para avanzar ship_frames2 = anim.createFrames(image, [128, 128], [0, 0], [2], [0, 1]) #animacion para retroceder hurt_frames = anim.createFrames(image, [128, 128], [0, 0], [2], [2, 2]) # animacion cuando le llega una bala explode_frames = anim.createFrames(image, [128, 128], [0, 0], [2, 5], [2, 0]) # animacion de explosion #se crea un diccionario con las animaciones ship_animations = {} ship_animations["fast"] = anim.Animation(ship_frames1, 12, True, False) ship_animations["slow"] = anim.Animation(ship_frames2, 12, True, False) ship_animations["hurt"] = anim.Animation(hurt_frames, 12, True, False) ship_animations["explode"] = anim.Animation(explode_frames, 9, False, False) #se crea el controlador de animaciones y se inicializa ship_Anim = anim.Anim_Controller(ship_animations, [PLAYER_SIZE, WIDTH / HEIGHT * PLAYER_SIZE, 1], 0) ship_Anim.Play("slow") #se crea un nodo que contiene la animacion anim_node = sg.SceneGraphNode("anim_player") anim_node.childs += [ship_Anim] # se crea un nodo con una gpuShape que servira para detectar las colisiones y verlas si se quiere collision_node = sg.SceneGraphNode("collision_player") collision_node.childs += [es.toGPUShape(cl.createCircleHitbox(PLAYER_HITBOX_RADIO, 10, 0, 1, 0))] # se crea uno nodo/objeto CollisionShape que tiene informacion y metodos para detectar colisiones con respecto de una gpuShape scaled_collision = cl.CollisionShape("scaled_collision", PLAYER_HITBOX_RADIO, True) # se escala la hitbox para que tenga el mismo tamaño que la textura scaled_collision.transform = tr.scale(1, 1 * WIDTH/HEIGHT, 1) scaled_collision.childs += [collision_node] # se crea el objeto player que contendra como nodos hijos a la animacion y la hitbox player_gameObject = playerObject("player") # se traslada la nave en la pantalla a su posicion inicial player_gameObject.transform = tr.translate(0, -0.5, 0) player_gameObject.position[0] = 0 player_gameObject.position[1] = -0.5 player_gameObject.position[2] = 0 player_gameObject.childs += [anim_node] #se agrega la animacion player_gameObject.childs += [scaled_collision] #se agrega la hitbox player_gameObject.childs[1].parent = player_gameObject # se agrega la referencia de padre al objeto CollisionShape #agrega el objeto player a la escena principal main_node.childs += [player_gameObject] #retorna la referencia al objeto player return go.findNode(main_node, "player")
def createLifeBar(green=True): channel = int(green) vertices = [ # positions colors -0.5, -0.5, 0.0, 1 - channel, channel, 0, 0.5, -0.5, 0.0, 1 - channel, channel, 0, 0.5, 0.5, 0.0, 1, 1, 1, -0.5, 0.5, 0.0, 1 - channel, channel, 0 ] # Defining connections among vertices indices = [0, 1, 2, 2, 3, 0] gpuShape = es.toGPUShape(bs.Shape(vertices, indices)) # Creating an elongated bar scaledBar = sg.SceneGraphNode("scaledBar") scaledBar.transform = tr.scale(0.1, 0.03, 1) scaledBar.childs += [gpuShape] bar = sg.SceneGraphNode("bar") bar.childs += [scaledBar] return bar
def __init__(self): gpu_egg = es.toGPUShape(bs.createColorTriangle(0.47, .19, .0)) #creamos una base y altura aleatoria para las montañas base = random.uniform(0.5, 3) altura = random.uniform(0.5, 2) egg = sg.SceneGraphNode('egg') egg.transform = tr.scale(base, altura, 1) egg.childs += [gpu_egg] egg_tr = sg.SceneGraphNode('eggTR') egg_tr.childs += [egg] self.pos_x = 3 # LOGICA self.pos_y = -0.2 self.model = egg_tr
def __init__(self): gpu_nube = es.toGPUShape(bs.createColorQuad(0.8, 0.8, 0.8)) #creamos una base y altura aleatoria para las montañas base = random.uniform(0.1, 0.5) altura = random.uniform(0.1, 0.5) nube = sg.SceneGraphNode('nube') nube.transform = tr.scale(base, altura, 1) nube.childs += [gpu_nube] nube_tr = sg.SceneGraphNode('nubeTR') nube_tr.childs += [nube] self.pos_x = 2 # LOGICA self.pos_y = random.uniform(0.2, 1.) self.model = nube_tr
def circulo(grab): circulo = sg.SceneGraphNode("") theta = 0 while theta <= np.pi: diff = sg.SceneGraphNode("") diff.transform = tr.matmul([tr.scale(0.05, 1, 0), tr.rotationZ(theta)]) if grab: diff.childs += [createQuad(255, 0, 0, 255, 0, 0)] #ROJO else: diff.childs += [createQuad(0, 255, 0, 0, 255, 0)] #VERDE circulo.childs += [diff] theta += 2 * np.pi / 65 circulo.transform = tr.matmul( [tr.uniformScale(0.5), tr.translate(-0.35, 0, 0)]) return circulo
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 Draw(self, color_pipeline, projection, view): if self.dibujo: self.transform = tr.matmul([ tr.scale(2, 2, 0.3), tr.translate(self.posx, self.posy, self.posz) ]) glUseProgram(color_pipeline.shaderProgram) glUniformMatrix4fv( glGetUniformLocation(color_pipeline.shaderProgram, 'projection'), 1, GL_TRUE, projection) glUniformMatrix4fv( glGetUniformLocation(color_pipeline.shaderProgram, 'view'), 1, GL_TRUE, view) glUniformMatrix4fv( glGetUniformLocation(color_pipeline.shaderProgram, 'model'), 1, GL_TRUE, self.transform) color_pipeline.drawShape(self.model)
def createEnemyShot(): gpuRedQuad = es.toGPUShape(bs.createColorQuad(1, 0, 0)) # Creating a single enemy shot enemyShot = sg.SceneGraphNode("enemyShot") enemyShot.transform = tr.matmul([ tr.translate(enemyShip.pos_x, enemyShip.pos_y, 0), tr.scale(0.1, 0.3, 0), tr.uniformScale(0.2) ]) enemyShot.childs += [gpuRedQuad] enemyShots = sg.SceneGraphNode("enemyShots") enemyShots.childs += [enemyShot] enemyShots.pos_x = enemyShip.pos_x enemyShots.pos_y = enemyShip.pos_y return enemyShots
def __init__(self, frame_width, frame_height, tiles=50): self.tiles = min(50, max(10, tiles)) self.frame_dim = [frame_width, frame_height] self.locationX = int(self.tiles / 2) self.locationY = int(self.tiles / 2) self.last_position = [self.locationX, self.locationY] self.last_direction = "A" # "A" means "left" according to our WASD control buttons self.next_direction = "A" self.face_orientation = "A" self.life_status = True self.body_queue = [] self.movement_queue = [] self.occupied_positions = [[self.last_position]] self.recently_added_body = False self.gpu_body = es.toGPUShape(bs.createTextureQuad("question_box.png"), GL_CLAMP, GL_NEAREST) self.current_apple = None # Aspect ratio ar = frame_height / frame_width self.dimensions = [ar * 0.95 * 2 * 4 / 5, 0.95 * 2 * 4 / 5] gpu_snake = es.toGPUShape(bs.createTextureQuad("boo_l.png"), GL_CLAMP, GL_NEAREST) snake_head = sg.SceneGraphNode('snake_head') snake_head.transform = tr.matmul([ tr.scale(self.dimensions[0] / self.tiles, self.dimensions[1] / self.tiles, 0), tr.translate(-self.tiles / 2 + self.locationX + 0.5, -self.tiles / 2 + self.locationY - 0.5, 0) ]) snake_head.childs += [gpu_snake] snake = sg.SceneGraphNode('snake') snake.childs += [snake_head] snake_tr = sg.SceneGraphNode('snake_TR') snake_tr.childs += [snake] self.model = snake_tr
def addEnemies0(enemies_collection, amount): global enemy_counter #se distribuyen los enemigos en la pantalla segun su cantidad for enemy in range(amount): # se crea el controlador de animaciones y se inicializa enemy_anim = anim.Anim_Controller(enemy0_animations, [ENEMY0_SIZE, ENEMY0_SIZE * WIDTH/HEIGHT, 1], 0) enemy_anim.Play("flying") #se define su posicion horizontal temp_posX = -1 + 1/amount -0.05 + enemy*(2/amount) # se crea un nodo que contiene la animacion y que la voltea scaled_enemy = sg.SceneGraphNode("scaled_enemy") scaled_enemy.transform = tr.rotationZ(np.pi) scaled_enemy.childs += [enemy_anim] # se crea un nodo con una gpuShape que servira para detectar las colisiones y verlas si se quiere collision_node = sg.SceneGraphNode("collision_enemy0") collision_node.transform = tr.scale(1, 1* WIDTH / HEIGHT, 1) collision_node.childs += [es.toGPUShape(cl.createCircleHitbox(ENEMY0_HITBOX_RADIO, 10, 0, 1, 0))] # se crea uno nodo/objeto CollisionShape que tiene informacion y metodos para detectar colisiones con respecto de una gpuShape scaled_collision = cl.CollisionShape("scaled_collision", ENEMY0_HITBOX_RADIO, True) scaled_collision.transform = tr.rotationZ(np.pi) scaled_collision.childs += [collision_node] # se crea el objeto enemy que contendra como nodos hijos a la animacion y la hitbox enemy_object = enemyObject("enemy" + str(enemy_counter)) enemy_object.enemy = 0 # es el primer tipo de enmigos # se traslada la nave en la pantalla a su posicion inicial enemy_object.transform = tr.translate(temp_posX, ENEMY0_SPAWN_POSY, 0) enemy_object.position[0] = temp_posX enemy_object.position[1] = ENEMY0_SPAWN_POSY enemy_object.position[2] = 0 #se indica su velocidad enemy_object.velocity = [0, ENEMY0_SPAWN_SPEED, 0] enemy_object.childs += [scaled_enemy] #se agrega la animacion enemy_object.childs += [scaled_collision] #se agrega la hitbox enemy_object.childs[1].parent = enemy_object # se agrega la referencia de padre al objeto CollisionShape #se le agrega la animacion de su bala correspondiente enemy_object.bullet_animations = bullet0_animation enemy_counter += 1 #se agrega el objeto enemy a la collecion de enemigos enemies_collection.childs += [enemy_object]
def get_transform(self): # return - A matrix tranform for the branch model # Asumes shape of dimension 1 in every axis and centered in origin scale = tr.scale(self.diameter, self.diameter, self.length) # Create rotation matrix up = np.cross(self.side,self.forward) up = up/np.linalg.norm(up) traslation = (self.origin+self.end)/2 look = np.array([ [up[0], self.side[0], self.forward[0], traslation[0]], [up[1], self.side[1], self.forward[1], traslation[1]], [up[2], self.side[2], self.forward[2], traslation[2]], [0,0,0,1] ], dtype = np.float32) return tr.matmul([ look, scale])
def createCannon(): gpuGrayQuad = es.toGPUShape(bs.createColorQuad(0.8, 0.8, 0.8)) gpuDarkQuad = es.toGPUShape(bs.createColorQuad(0.3, 0.3, 0.3)) # A cannon is made of a tunnel section and a head tunnel = sg.SceneGraphNode("tunnel") tunnel.transform = tr.scale(0.1, 0.4, 1) tunnel.childs += [gpuGrayQuad] head = sg.SceneGraphNode("head") head.transform = tr.matmul([tr.translate(0, -0.2, 0), tr.uniformScale(0.15)]) head.childs += [gpuDarkQuad] cannon = sg.SceneGraphNode("simpleCannon") cannon.childs += [tunnel] cannon.childs += [head] return cannon
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 __init__(self, nEnemies, screenWidth, screenHeight, controller): # nenemies - Number of enemies to spawn # screenWidth - Game screen width # screenHeight - Game screen height # controller - Controller instance of the game # Start clock self.ltime = 0.0 # reference to the gaplayerme controller # Create game scene self.gameScene = sg.SceneGraphNode("gameScene") self.gameScene.transform = tr.scale(screenHeight / screenWidth, 1.0, 1.0) # Load game models enemyModel = gs.create_enemy((0.5, 0, 0.38), (0.0, 0.38, 0.5)) enemyModel2 = gs.create_enemy((0.73, 0.42, 0.34), (0.19, 0.28, 0.37)) enemyModel3 = gs.create_enemy((0.03, 25, 0.47), (0.41, 0.45, 0.40)) self.enemyModels = [enemyModel, enemyModel2, enemyModel3] self.playerModel = gs.create_player() self.playerShotModel = gs.create_shot(0.9, 0.5, 0.0) self.enemyShotModel = gs.create_shot(0.4, 0.2, 1.0) self.explosionmodel = gs.create_explosion() self.hpBlockModel = gs.create_hp_block() # Spawn player self.player = Player("player", 0.0, -0.75, self.ltime, controller, self.playerModel) # Objects list self.playerShots = [] self.enemyShots = [] self.enemies = [] # Game status self.state = G_ONGOING self.remainingEnemies = nEnemies self.wave = 0 self.lastEnemyTimer = 0.0 #time of last enemy death self.waitSpawn = False
def setupHearts(image, main_node): #recorta la imagen de los corazones y crea una gpuShape heart_Image =anim.createFrames(image, [128, 128], [0, 0], [1], [1, 2]) heartGPU = heart_Image[0] #se crea la coleccion de corazones hearts_collection = sg.SceneGraphNode("hearts") #se añaden los corazones con los parametros definidos for i in range(3): heart = sg.SceneGraphNode("heart") heart.transform = tr.scale(HEART_SIZE, HEART_SIZE * WIDTH/HEIGHT, 1) heart.childs += [heartGPU] scaledHeart = go.gameObject("scaledHeart") scaledHeart.transform = tr.translate(HEART1_POSX + i*HEARTS_LENGTH/2, HEARTS_POSY, 0) scaledHeart.childs += [heart] hearts_collection.childs += [scaledHeart] #se agregan los corazones al nodo principal main_node.childs += [hearts_collection] #retorna la referencia a la coleccion de corazones return go.findNode(main_node, "hearts")
def add_body(self): posX = self.body_queue[ len(self.body_queue) - 1]["last_position"][0] if len( self.body_queue) > 0 else self.last_position[0] posY = self.body_queue[ len(self.body_queue) - 1]["last_position"][1] if len( self.body_queue) > 0 else self.last_position[1] snake_body = sg.SceneGraphNode(f'snake_body_{len(self.body_queue)}') snake_body.transform = tr.matmul([ tr.scale(self.dimensions[0] / self.tiles, self.dimensions[1] / self.tiles, 0), tr.translate(-self.tiles / 2 + posX + 0.5, -self.tiles / 2 + posY - 0.5, 0) ]) snake_body.childs += [self.gpu_body] self.body_queue.append({ "name": f'snake_body_{len(self.body_queue)}', "position": [posX, posY], "last_position": [posX, posY] }) sg.findNode(self.model, "snake").childs += [snake_body]
def __init__(self, r): gpu_barra = es.toGPUShape(bs.createColorQuad(0.5, 0.5, 0.5)) #creamos un cuadrado barra = sg.SceneGraphNode('barra') #generamos un nodo para el cuadrado barra.transform = tr.scale(0.7,0.1, 1) #lo escalamos al tamaño que queremos barra.childs += [gpu_barra] transform_barra1 = sg.SceneGraphNode('barraTR')# generamos un nodo para el objeto barra transform_barra1.childs += [barra] self.model = transform_barra1 self.pos_y = 1 #con esto se lee el lo que traia el archivo structure.csv y coloca barras en los unos if len(r)!=0: p=r.pop(0) if p[0]=="1": self.pos_x=-0.7 if p[2]=="1": self.pos_x=0 if p[4]=="1": self.pos_x=0.7 self.r=r
def __init__(self): # Figuras básicas gpu_red = es.toGPUShape(bs.createColorQuad(1, 0, 0)) gpu_grey = es.toGPUShape(bs.createColorQuad(0.7, 0.7, 0.7)) gpu_dark_blue = es.toGPUShape(bs.createColorQuad(0., 0.1, 0.4)) #creamos un medidor de revoluciones rojo = sg.SceneGraphNode('rojo') # cuarto de circulo generico rojo.transform = tr.matmul( [tr.translate(0.3, 0, 0), tr.uniformScale(0.15)]) rojo.childs += [gpu_red] dblue = sg.SceneGraphNode('dblue') dblue.transform = tr.matmul( [tr.translate(0.3, -0.3, 0), tr.uniformScale(0.15)]) dblue.childs += [gpu_dark_blue] grey = sg.SceneGraphNode('grey') grey.transform = tr.matmul( [tr.translate(0, -0.3, 0), tr.uniformScale(0.15)]) grey.childs += [gpu_grey] # Ensamblamos el mono bot = sg.SceneGraphNode('bot') bot.transform = tr.matmul( [tr.translate(0.65, -0.55, 0), tr.scale(0.7, 1, 1)]) bot.childs += [rojo, dblue, grey] translate_bot = sg.SceneGraphNode('botTR') translate_bot.childs += [bot] self.model = bot self.pos = 0
def create_scene(): gpu_cuchillo = os.toGPUShape(bs.createColorCuchillo(1, 1, 0)) gpu_green_triangle = os.toGPUShape(bs.createColorTriangle(0, 1, 0)) gpu_yellow_triangle = os.toGPUShape(bs.createColorTriangle(1, 1, 0)) gpu_green_quad = es.toGPUShape(bs.createColorQuad(1, 1, 0)) gpu_yellow_quad = es.toGPUShape(bs.createColorQuad(0, 1, 0)) gpu_yellow_d = es.toGPUShape(bs.createColorD(0, 1, 0)) # El cuchillo cuchillo = sg.SceneGraphNode('cuchillo') cuchillo.transform = tr.matmul([ tr.translate(-8 / 15, -1 / 22, 0), tr.scale(3, 3, 1), tr.rotationZ(180) ]) cuchillo.childs += [gpu_cuchillo] # La mesa mc1 = sg.SceneGraphNode('mc1') mc1.transform = tr.scale(4, 4, 1) mc1.childs += [gpu_yellow_quad] mt1 = sg.SceneGraphNode('mt1') mt1.transform = tr.translate(-1 / 15, -3 / 22, 0) mt1.childs += [gpu_yellow_quad] mt2 = sg.SceneGraphNode('mt2') mt2.transform = tr.translate(1 / 15, -3 / 22, 0) mt2.childs += [gpu_yellow_quad] MesaT = sg.SceneGraphNode('MesaT') MesaT.childs += [mt1, mt2] MesaT.transform = tr.scale(2, 2, 1) Mesa = sg.SceneGraphNode('Mesa') Mesa.childs += [MesaT, mc1] Mesa.transform = tr.matmul([ tr.translate(5 / 15, 8 / 22, 0), tr.scale(2, 1.5, 1), tr.rotationZ(180) ]) # El Árbol ac1 = sg.SceneGraphNode('ac1') ac1.transform = tr.scale(2, 2, 1) ac1.childs += [gpu_green_quad] at1 = sg.SceneGraphNode('at1') at1.transform = tr.translate(-1 / 15, 0, 0) at1.childs += [gpu_green_triangle] at2 = sg.SceneGraphNode('at2') at2.transform = tr.translate(1 / 15, 0, 0) at2.childs += [gpu_green_triangle] Rama1 = sg.SceneGraphNode('Rama1') Rama1.childs += [at1, at2] Rama1.transform = tr.translate(0, 4 / 22, 0) at3 = sg.SceneGraphNode('at3') at3.transform = tr.translate(-1 / 15, 0, 0) at3.childs += [gpu_green_triangle] at4 = sg.SceneGraphNode('at4') at4.transform = tr.translate(1 / 15, 0, 0) at4.childs += [gpu_green_triangle] Rama2 = sg.SceneGraphNode('Rama2') Rama2.childs += [at3, at4] Rama2.transform = tr.translate(0, 2 / 22, 0) ArbolT = sg.SceneGraphNode('ArbolT') ArbolT.childs += [Rama1, Rama2] ArbolT.transform = tr.scale(2, 2, 1) Arbol = sg.SceneGraphNode('Arbol') Arbol.childs += [ArbolT, ac1] Arbol.transform = tr.matmul([ tr.translate(6 / 15, -13 / 22, 0), tr.scale(4, 2, 1), tr.rotationZ(360) ]) # La Firma d = sg.SceneGraphNode('d') d.transform = tr.translate(7 / 22, 0, 0) d.childs += [gpu_yellow_d] i1 = sg.SceneGraphNode('i1') i1.transform = tr.matmul( [tr.translate(-1 / 15, 3.5 / 22, 0), tr.scale(1, 6, 1)]) i1.childs += [gpu_green_quad] i2 = sg.SceneGraphNode('i2') i2.transform = tr.matmul( [tr.translate(-1 / 15, 0.5 / 22, 0), tr.scale(2, 5, 1)]) i2.childs += [gpu_green_quad] i3 = sg.SceneGraphNode('i3') i3.transform = tr.matmul( [tr.translate(-1 / 15, -2.5 / 22, 0), tr.scale(1, 6, 1)]) i3.childs += [gpu_green_quad] i = sg.SceneGraphNode('i') i.childs += [i1, i2, i3] Firma = sg.SceneGraphNode('Firma') Firma.childs += [i, d] Firma.transform = tr.matmul([tr.translate(-10 / 15, 19 / 22, 0)]) # El Cepillo de Dientes ct1 = sg.SceneGraphNode('ct1') ct1.transform = tr.translate(0, 1 / 22, 0) ct1.childs += [gpu_green_triangle] ct2 = sg.SceneGraphNode('ct2') ct2.transform = tr.translate(0, 3 / 22, 0) ct2.childs += [gpu_green_triangle] ct3 = sg.SceneGraphNode('ct3') ct3.transform = tr.translate(0, 5 / 22, 0) ct3.childs += [gpu_green_triangle] CepilloT = sg.SceneGraphNode('CepilloT') CepilloT.childs += [ct1, ct2, ct3] CepilloT.transform = tr.matmul( [tr.translate(-3 / 15, 0, 0), tr.scale(2, 2, 1)]) cc1 = sg.SceneGraphNode('cc1') cc1.transform = tr.translate(0, 5 / 22, 0) cc1.childs += [gpu_green_quad] cc2 = sg.SceneGraphNode('cc2') cc2.transform = tr.translate(0, 3 / 22, 0) cc2.childs += [gpu_green_quad] cc3 = sg.SceneGraphNode('cc3') cc3.transform = tr.translate(0, 1 / 22, 0) cc3.childs += [gpu_green_quad] cc4 = sg.SceneGraphNode('cc4') cc4.transform = tr.translate(0, -1 / 22, 0) cc4.childs += [gpu_green_quad] cc5 = sg.SceneGraphNode('cc5') cc5.transform = tr.translate(0, -3 / 22, 0) cc5.childs += [gpu_green_quad] cc6 = sg.SceneGraphNode('cc6') cc6.transform = tr.translate(0, -5 / 22, 0) cc6.childs += [gpu_green_quad] CepilloC = sg.SceneGraphNode('CepilloC') CepilloC.childs += [ct1, ct2, ct3] CepilloC.transform = tr.matmul( [tr.translate(-1 / 15, 0, 0), tr.scale(2, 2, 1)]) Cepillo = sg.SceneGraphNode('Cepillo') Cepillo.childs += [CepilloT, CepilloC] Cepillo.transform = tr.matmul([ tr.translate(2 / 15, -20 / 22, 0), tr.scale(0.5, 1.5, 1), tr.rotationZ(90) ]) # el Mundo mundo = sg.SceneGraphNode('mundo') mundo.childs += [Mesa, Arbol, Cepillo, cuchillo, Firma] return mundo
def draw(self, pipeline): self.tra= tr.matmul([tr.translate(0, self.pos, 0),tr.uniformScale(2), tr.scale(-1, -1, 1)]) glUseProgram(pipeline.shaderProgram) glUniformMatrix4fv(glGetUniformLocation(pipeline.shaderProgram, "transform"), 1, GL_TRUE, self.tra) pipeline.drawShape(self.model)
def __init__(self, tamaño): self.tamaño = tamaño # Figuras básicas gpu_esquina_quad = es.toGPUShape(bs.createColorQuad(0, 0, 0)) # negro gpu_grilla_quad = es.toGPUShape(bs.createColorQuad(0.9, 0.9, 0.9)) # gris gpu_gameover = es.toGPUShape(bs.createColorQuad(0, 0, 1)) # azul gameover = sg.SceneGraphNode('gameover') gameover.transform = tr.uniformScale(2) gameover.child = [gpu_gameover] esquina_vertical = sg.SceneGraphNode('esquinaVertical') esquina_vertical.transform = tr.scale(d * 4 / self.tamaño, 2, 1) esquina_vertical.childs += [gpu_esquina_quad] esquina_horizontal = sg.SceneGraphNode('esquinaHorizontal') esquina_horizontal.transform = tr.scale(2, d * 4 / self.tamaño, 1) esquina_horizontal.childs += [gpu_esquina_quad] esquina_der = sg.SceneGraphNode('esquinaDerecha') esquina_der.transform = tr.translate(1, 0, 0) esquina_der.childs += [esquina_vertical] esquina_izq = sg.SceneGraphNode('esquinaIzquierda') esquina_izq.transform = tr.translate(-1, 0, 0) esquina_izq.childs += [esquina_vertical] esquina_sup = sg.SceneGraphNode('esquinaIzquierda') esquina_sup.transform = tr.translate(0, 1, 0) esquina_sup.childs += [esquina_horizontal] esquina_inf = sg.SceneGraphNode('esquinaIzquierda') esquina_inf.transform = tr.translate(0, -1, 0) esquina_inf.childs += [esquina_horizontal] cuadrado = sg.SceneGraphNode('cuadrado') cuadrado.transform = tr.uniformScale(d * 2 / self.tamaño) cuadrado.childs += [gpu_grilla_quad] grilla = sg.SceneGraphNode('grilla') grilla.transform = tr.translate(-1 + d * 3 / self.tamaño, 1 - d * 3 / self.tamaño, 1) grilla.childs += [cuadrado] fondo = sg.SceneGraphNode('fondo') baseName = "cuadrado" for i in range(math.ceil(tamaño / 2) - 1): for j in range(tamaño): if j % 2 == 0: x = -1 + d * (3 / self.tamaño + 4 * i / self.tamaño) y = -1 + d * (3 / self.tamaño + 2 * j / self.tamaño) else: x = -1 + d * (5 / self.tamaño + 4 * i / self.tamaño) y = -1 + d * (3 / self.tamaño + 2 * j / self.tamaño) newNode = sg.SceneGraphNode(baseName + str(i)) newNode.transform = tr.translate(x, y, 1) newNode.childs += [cuadrado] fondo.childs += [newNode] fondo.childs += [esquina_der, esquina_izq, esquina_sup, esquina_inf] self.model = fondo
view = tr.lookAt( np.array([0 + x,-0.0015 + y,7 + z]), np.array([x, y,0]), np.array([0,0,1]) ) # Clearing the screen in both, color and depth glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) enzo(embisi) nodoAnterior = sg.findNode(malla, "T" + cursoAnterior.codigo) tapaAnt = nodoAnterior.childs[1] nodoAnterior.childs = [cuboR, tapaAnt] nodoAnterior = sg.findNode(malla, cursoAnterior.codigo) nodoAnterior.transform = tr.scale(1,1,1) for requisitoAnt in cursoAnterior.requisitos: nodoReqAnt = sg.findNode(malla, "T" + requisitoAnt) tapaReqAnt = nodoReqAnt.childs[1] nodoReqAnt.childs = [cuboR, tapaReqAnt] nodoReqAnt = sg.findNode(malla, requisitoAnt) nodoReqAnt.transform = tr.scale(1,1,1) for requisitoDeAnt in cursoAnterior.requisitosDe: nodoReqDeAnt = sg.findNode(malla, "T" + requisitoDeAnt) tapaReqDeAnt = nodoReqDeAnt.childs[1] nodoReqDeAnt.childs = [cuboR, tapaReqDeAnt] nodoReqDeAnt = sg.findNode(malla, requisitoDeAnt)
def createCar(r, g, b, foc=False, turbo=False): if not foc: #El proposito de este if es cambiar las luces delanteras del auto, de manera que si foc != False, los focos estan prendidos (amarillos) rf = 0.8 gf = 0.8 bf = 0.8 else: #Aqui se aplica el color amarillo para el caso de que foc no sea False rf = 0.9686 gf = 0.9412 bf = 0 #Se crean las figuras que se utilizaran para la creacion del auto gpuBlackCirc = es.toGPUShape(bs.createCircle([0, 0, 0])) gpuWhiteCirc = es.toGPUShape(bs.createCircle([0.8, 0.8, 0.8])) gpuBlueQuad = es.toGPUShape( bs.createColorQuad(r, g, b) ) #Se dejan los colores como variables para que Don Pedro pueda elegir el color de auto que mas le gusta gpuFocQuad = es.toGPUShape(bs.createColorQuad(rf, gf, bf)) gpuRedQuad = es.toGPUShape(bs.createColorQuad(1, 0, 0)) gpuSBQuad = es.toGPUShape(bs.createColorQuad(0.5922, 0.9569, 1)) #Se crea la parte interna de la rueda de color blanco little_wheel = sg.SceneGraphNode("little_wheel") little_wheel.transform = tr.uniformScale(0.08) little_wheel.childs += [gpuWhiteCirc] # Se crea la parte negra de la rueda (la más externa) big_wheel = sg.SceneGraphNode("big_wheel") big_wheel.transform = tr.uniformScale(0.2) big_wheel.childs += [gpuBlackCirc] #Se crea la rueda completa compuesta de las dos partes anteriores wheel = sg.SceneGraphNode("wheel") wheel.childs += [big_wheel, little_wheel] wheelRotation = sg.SceneGraphNode("wheelRotation") wheelRotation.childs += [wheel] # Se instalan las dos ruedas en el auto frontWheel = sg.SceneGraphNode("frontWheel") frontWheel.transform = tr.translate(0.5, -0.3, 0) frontWheel.childs += [wheelRotation] backWheel = sg.SceneGraphNode("backWheel") backWheel.transform = tr.translate(-0.5, -0.3, 0) backWheel.childs += [wheelRotation] # Se crear el chasis del auto chasis = sg.SceneGraphNode("chasis") chasis.transform = tr.scale(1.8, 0.5, 1) chasis.childs += [gpuBlueQuad] #Se crea el techo del auto techo = sg.SceneGraphNode("techo") techo.transform = tr.matmul( [tr.translate(0, 0.45, 0), tr.scale(1, 0.5, 1)]) techo.childs += [gpuBlueQuad] #Se crea el foco trasero foco_tras = sg.SceneGraphNode("foco_tras") foco_tras.transform = tr.matmul( [tr.translate(-0.86, 0.21, 0), tr.scale(0.08, 0.08, 1)]) foco_tras.childs += [gpuRedQuad] #Se crea el foco delantero foco_del = sg.SceneGraphNode("foco_del") foco_del.transform = tr.matmul( [tr.translate(0.86, 0.21, 0), tr.scale(0.08, 0.08, 1)]) foco_del.childs += [gpuFocQuad] #Se crean las ventanas del auto vent_der = sg.SceneGraphNode("vent_der") vent_der.transform = tr.matmul( [tr.translate(0.23, 0.45, 0), tr.scale(0.38, 0.37, 1)]) vent_der.childs += [gpuSBQuad] vent_izq = sg.SceneGraphNode("vent_izq") vent_izq.transform = tr.matmul( [tr.translate(-0.23, 0.45, 0), tr.scale(0.38, 0.37, 1)]) vent_izq.childs += [gpuSBQuad] #Se creal auto compuesto de todas las partes anteriormente creadas car = sg.SceneGraphNode("car") car.childs += [ chasis, techo, frontWheel, backWheel, foco_tras, foco_del, vent_der, vent_izq ] #Se traslada y escala el auto scaledCar = sg.SceneGraphNode("scaledCar") scaledCar.transform = tr.matmul( [tr.translate(0, -0.66, 0), tr.uniformScale(0.15)]) scaledCar.childs += [car] #Se crean las figras que se utilizaran para el turbo gpuGrayOv = es.toGPUShape(bs.createSemiCircle([0.7, 0.7, 0.7])) gpuBlackC = es.toGPUShape(bs.createCircle([0.2, 0.2, 0.2])) gpuRYC = es.toGPUShape( bs.create2ColorCircle([1, 0, 0], [1, 0.9961, 0.4392])) #La base de la turbina base = sg.SceneGraphNode("base") base.transform = tr.matmul( [tr.rotationZ(-np.pi / 2), tr.scale(0.04, 0.17, 1)]) base.childs += [gpuGrayOv] baseTr = sg.SceneGraphNode("baseTr") baseTr.transform = tr.translate(-0.07, -0.515, 0) baseTr.childs += [base] #Se crea la parte trasera de la turbina en conjunto con el "fuego" que lo impulsa fin = sg.SceneGraphNode("fin") fin.transform = tr.matmul( [tr.translate(-0.07, -0.515, 0), tr.scale(0.02, 0.04, 1)]) fin.childs += [gpuBlackC] fuego = sg.SceneGraphNode("fuego") fuego.transform = tr.matmul( [tr.translate(-0.07, -0.515, 0), tr.scale(0.01, 0.03, 1)]) fuego.childs = [gpuRYC] #Se crea la turbina turboT = sg.SceneGraphNode("turbo") turboT.childs += [baseTr, fin, fuego] #Creamos una figura que va a ir cambiando los childs dependiendo de si el turbo esta activo o no autoFinal = sg.SceneGraphNode("autoFinal") autoFinal.childs += [] if turbo == False: #en el caso de que el turbo este desactivado se crea solo el auto escalado y trasladado autoFinal.childs = [scaledCar] elif turbo == True: #cuando la turbina esta activa el auto se compone de la turbina y el auto escalado autoFinal.childs = [turboT, scaledCar] else: autoFinal.childs = [] return autoFinal