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 crearfondoDia(): gpuGrayQuad = es.toGPUShape(bs.createColorQuad(0.2, 0.2, 0.2)) gpuSkyQuad = es.toGPUShape(bs.create2ColorQuad(1,1,1, 0.7373, 0.9961, 1)) gpuGreenQuad = es.toGPUShape(bs.createColorQuad(0.6706,1,0.7137)) gpuYellowCirc = es.toGPUShape(bs.create2ColorCircle([1,0.9961,0.4392],[1,1,1])) #Creamos el cielo con un degradado de blanco a celeste cielo = sg.SceneGraphNode("cielo") cielo.transform = tr.matmul([tr.translate(0,0.5,0),tr.scale(6,1.75,1)]) cielo.childs += [gpuSkyQuad] #Creamos el camino para el auto asfalto = sg.SceneGraphNode("asfalto") asfalto.transform = tr.matmul([tr.translate(0,-0.75,0),tr.scale(6,0.5,1)]) asfalto.childs += [gpuGrayQuad] #Se crea el pasto que se vera entre los arboles pasto = sg.SceneGraphNode("pasto") pasto.transform = tr.matmul([tr.translate(0,-0.2,0) , tr.scale(6,0.7,1)]) pasto.childs += [gpuGreenQuad] #Creamos un sol en la esquina de la pantalla sol = sg.SceneGraphNode("sol") sol.transform = tr.matmul([tr.translate(1,1,0), tr.uniformScale(0.3)]) sol.childs += [gpuYellowCirc] fondo = sg.SceneGraphNode("fondo") fondo.childs += [cielo, asfalto, pasto, sol] return fondo
def createTextureDeathStar(filename): gpuSphere = es.toGPUShape(bs.createTextureSphere(filename), GL_MIRRORED_REPEAT, GL_NEAREST) gpuInside = es.toGPUShape(bs.createInsideSphere("textures/dsInside.jpg"), GL_MIRRORED_REPEAT, GL_NEAREST) gpuCone = es.toGPUShape(bs.createTextureCone("textures/laser.png"), GL_MIRRORED_REPEAT, GL_NEAREST) star_base = sg.SceneGraphNode("star_base") star_base.transform = tr2.scale(0.5, 0.5, 0.5) star_base.childs += [gpuSphere] star_inside = sg.SceneGraphNode("star_inside") star_inside.transform = tr2.scale(0.5, 0.5, 0.5) star_inside.childs += [gpuInside] star_aerial = sg.SceneGraphNode("star_aerial") star_aerial.transform = np.matmul( tr2.translate(0, -np.sin(3 * np.pi / 8) / 2, np.cos(3 * np.pi / 8) / 2), tr2.rotationX(3 * np.pi / 8)) star_aerial.transform = np.matmul(star_aerial.transform, tr2.scale(0.15, 0.15, 0.05)) star_aerial.childs += [gpuCone] star = sg.SceneGraphNode("star") star.transform = tr2.rotationY(np.pi / 32) star.childs += [star_inside, star_base, star_aerial] return star
def __init__(self, frame_width, frame_height, tiles=50): self.tiles = min(50, max(10, tiles)) self.frame_dim = [frame_width, frame_height] # Aspect ratio ar = frame_height / frame_width #aspect_ratio_tr = tr.scale(ar, 1, 0) self.dimensions = [ar * 0.95 * 2 * 4 / 5, 0.95 * 2 * 4 / 5] gpu_tiles = [ es.toGPUShape(bs.createColorQuad(1, 0.91, 0.84)), es.toGPUShape(bs.createColorQuad(0.99, 0.84, 0.61)) ] tiles = [] count = 0 for x in range(self.tiles): tiles.append([]) for y in range(self.tiles): tiles[x].append(sg.SceneGraphNode(f'tile{x}_{y}')) tiles[x][y].transform = tr.matmul([ tr.scale(self.dimensions[0] / self.tiles, self.dimensions[1] / self.tiles, 0), tr.translate(-self.tiles / 2 + x + 0.5, self.tiles / 2 - y - 0.5, 0) ]) tiles[x][y].childs += [gpu_tiles[(x + y) % 2]] board_TR = sg.SceneGraphNode('board_TR') for i in range(len(tiles)): board_TR.childs += tiles[i] self.model = board_TR
def crearArbol(): #Se crean las figuras que se utilizaran gpuGreenTriangle = es.toGPUShape(bs.create2ColorTriangle(0.0549, 0.4549, 0.41, 0, 0.8, 0)) gpuBrownQuad = es.toGPUShape(bs.createColorQuad(0.502, 0.251, 0)) #Aqui se crean las partes de la copa del pino copa1 = sg.SceneGraphNode("copa1") copa1.transform = tr.uniformScale(0.5) copa1.childs += [gpuGreenTriangle] copa2 = sg.SceneGraphNode("copa2") copa2.transform = tr.matmul([tr.uniformScale(0.4), tr.translate(0,0.3,0)]) copa2.childs += [gpuGreenTriangle] copa3 = sg.SceneGraphNode("copa3") copa3.transform = tr.matmul([tr.uniformScale(0.3), tr.translate(0,0.8,0)]) copa3.childs += [gpuGreenTriangle] #Aqui se crea el tronco del arbol tronco = sg.SceneGraphNode("tronco") tronco.transform = tr.matmul ([tr.scale(0.1,0.5,0), tr.translate(0, -0.4, 0)]) tronco.childs += [gpuBrownQuad] #Se juntan las partes para crear el arbol arbol = sg.SceneGraphNode("car") arbol.childs += [tronco, copa1, copa2, copa3] return arbol
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 createMotor(): gpuGrayTrapeze = es.toGPUShape(ve.createColorTrapeze(0.6, 0.6, 0.6)) gpuBlueTriangle = es.toGPUShape(ve.createColorTriangle(0.2, 0.5, 1)) gpuWhiteTriangle = es.toGPUShape(ve.createColorTriangle(1, 1, 1)) # A motor is made of a body and an animated flame blueFlame = sg.SceneGraphNode("blueFlame") blueFlame.transform = tr.matmul([tr.translate(0, 0.18, 1), tr.uniformScale(0.5)]) blueFlame.childs += [gpuBlueTriangle] whiteFlame = sg.SceneGraphNode("whiteFlame") whiteFlame.transform = tr.matmul([tr.translate(0, 0.05, 1), tr.uniformScale(0.3)]) whiteFlame.childs += [gpuWhiteTriangle] # This flame is animated in the main script animatedFlame = sg.SceneGraphNode("animatedFlame") animatedFlame.childs += [blueFlame] animatedFlame.childs += [whiteFlame] body = sg.SceneGraphNode("body") body.transform = tr.scale(1, 0.25, 1) body.childs += [gpuGrayTrapeze] # Joining both parts motor = sg.SceneGraphNode("simpleMotor") motor.childs += [animatedFlame] motor.childs += [body] return motor
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 draw(self, pipeline, texture1, texture2, texture3): if self.jump: #cuando esta saltando self.monkey = es.toGPUShape(bs.createTextureQuad(texture2), GL_REPEAT, GL_LINEAR) glUseProgram(pipeline.shaderProgram) glUniformMatrix4fv( glGetUniformLocation(pipeline.shaderProgram, "transform"), 1, GL_TRUE, self.transmonkey) pipeline.drawShape(self.monkey) elif self.winner: self.monkey = es.toGPUShape(bs.createTextureQuad(texture3), GL_REPEAT, GL_LINEAR) glUseProgram(pipeline.shaderProgram) glUniformMatrix4fv( glGetUniformLocation(pipeline.shaderProgram, "transform"), 1, GL_TRUE, self.transmonkey) pipeline.drawShape(self.monkey) else: #cuando se encuentra en reposo self.monkey = es.toGPUShape(bs.createTextureQuad(texture1), GL_REPEAT, GL_LINEAR) glUseProgram(pipeline.shaderProgram) glUniformMatrix4fv( glGetUniformLocation(pipeline.shaderProgram, "transform"), 1, GL_TRUE, self.transmonkey) pipeline.drawShape(self.monkey)
def crearfondoNoche(): gpuGrayQuad = es.toGPUShape(bs.createColorQuad(0.1, 0.1, 0.1)) gpuSkyQuad = es.toGPUShape(bs.create2ColorQuad(1,1,1, 0.1451, 0.1569, 0.3137)) gpuGreenQuad = es.toGPUShape(bs.createColorQuad(0.3059,0.651,0.3294)) gpuGrayCirc = es.toGPUShape(bs.create2ColorCircle([0.6941,0.7216,0.7218],[0.8784,0.8902,0.8902])) #Creamos el cielo con un degradado de blanco a azul cielo cielo = sg.SceneGraphNode("cielo") cielo.transform = tr.matmul([tr.translate(0,0.5,0),tr.scale(6,1.75,1)]) cielo.childs += [gpuSkyQuad] #Creamos el camino para el auto asfalto = sg.SceneGraphNode("asfalto") asfalto.transform = tr.matmul([tr.translate(0,-0.75,0),tr.scale(6,0.5,1)]) asfalto.childs += [gpuGrayQuad] #Se crea el pasto que se vera entre los arboles pasto = sg.SceneGraphNode("pasto") pasto.transform = tr.matmul([tr.translate(0,-0.2,0) , tr.scale(6,0.7,1)]) pasto.childs += [gpuGreenQuad] #Creamos una luna en la esquina de la pantalla luna = sg.SceneGraphNode("luna") luna.transform = tr.matmul([tr.translate(1,1,0), tr.uniformScale(0.3)]) luna.childs += [gpuGrayCirc] fondo = sg.SceneGraphNode("fondo") fondo.childs += [cielo, asfalto, pasto, luna] return fondo
def create_player(): # Generate player model # Body gpuBody = es.toGPUShape(player_body_shape(0.8, 0, 0.07)) # WingUp gpuWingUp = es.toGPUShape(player_upper_wing_shape(0.427, 0.447, 0.458)) # WingDown gpuWingDown = es.toGPUShape(player_lower_wing_shape(0.427, 0.447, 0.458)) #Flame gpuFlame = es.toGPUShape(flame_shape()) playerBody = sg.SceneGraphNode("body") playerBody.childs = [gpuBody] playerUpWing = sg.SceneGraphNode("wing1") playerUpWing.childs = [gpuWingUp] playerDownWing = sg.SceneGraphNode("wing2") playerDownWing.childs = [gpuWingDown] playerEngine = sg.SceneGraphNode("engine") playerEngine.transform = tr.matmul( [tr.translate(0.0, -0.525, 0.0), tr.uniformScale(0.9)]) playerEngine.childs = [gpuFlame] player = sg.SceneGraphNode("playerModel") player.transform = tr.uniformScale(0.1) player.childs = [playerUpWing, playerDownWing, playerBody, playerEngine] return player
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 create_enemy(bodyColor, wingColor): # Generate enemy model # bodyColor - tuple (r, g, b) # wingColor - tuple (r, g, b) # Body gpuBody = es.toGPUShape(bs.createColorQuad(*bodyColor)) # Wing gpuWing = es.toGPUShape(enemy_wing_shape(*wingColor)) enemyBody = sg.SceneGraphNode("body") enemyBody.childs = [gpuBody] enemyWing1 = sg.SceneGraphNode("wing1") enemyWing1.transform = tr.translate(0.5, 0, 0) enemyWing1.childs = [gpuWing] enemyWing2 = sg.SceneGraphNode("wing2") enemyWing2.transform = tr.matmul( [tr.translate(-0.5, 0, 0), tr.scale(-1, 1, 1)]) enemyWing2.childs = [gpuWing] enemy = sg.SceneGraphNode("enemyModel") enemy.transform = tr.uniformScale(0.08) enemy.childs = [enemyBody, enemyWing1, enemyWing2] return enemy
def createCar(r,g,b): gpuBlackQuad = es.toGPUShape(bs.createColorCube(0,0,0)) gpuChasisQuad = es.toGPUShape(bs.createColorCube(r,g,b)) # Cheating a single wheel wheel = sg.SceneGraphNode("wheel") wheel.transform = tr.scale(0.2, 0.8, 0.2) wheel.childs += [gpuBlackQuad] wheelRotation = sg.SceneGraphNode("wheelRotation") wheelRotation.childs += [wheel] # Instanciating 2 wheels, for the front and back parts frontWheel = sg.SceneGraphNode("frontWheel") frontWheel.transform = tr.translate(0.3,0,-0.3) frontWheel.childs += [wheelRotation] backWheel = sg.SceneGraphNode("backWheel") backWheel.transform = tr.translate(-0.3,0,-0.3) backWheel.childs += [wheelRotation] # Creating the chasis of the car chasis = sg.SceneGraphNode("chasis") chasis.transform = tr.scale(1,0.7,0.5) chasis.childs += [gpuChasisQuad] # All pieces together car = sg.SceneGraphNode("car") car.childs += [chasis] car.childs += [frontWheel] car.childs += [backWheel] return car
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 __init__(self): # Figuras básicas gpu_body_quad = es.toGPUShape(bs.createColorQuad(1, 0.8, 0.8)) # rosado gpu_leg_quad = es.toGPUShape(bs.createColorQuad(1, 0.5, 1)) # rosado fuerte gpu_eye_quad = es.toGPUShape(bs.createColorQuad(1, 1, 1)) # blanco # ... triangulos body = sg.SceneGraphNode('body') body.transform = tr.uniformScale(1) body.childs += [gpu_body_quad] # Creamos las piernas leg = sg.SceneGraphNode('leg') # pierna generica leg.transform = tr.scale(0.25, 0.25, 1) leg.childs += [gpu_leg_quad] # Izquierda leg_izq = sg.SceneGraphNode('legLeft') leg_izq.transform = tr.translate(-0.5, -0.5, 0) # tr.matmul([]).. leg_izq.childs += [leg] leg_der = sg.SceneGraphNode('legRight') leg_der.transform = tr.translate(0.5, -.5, 0) leg_der.childs += [leg] # Ojitos eye = sg.SceneGraphNode('eye') eye.transform = tr.scale(0.25, 0.25, 1) eye.childs += [gpu_eye_quad] eye_izq = sg.SceneGraphNode('eyeLeft') eye_izq.transform = tr.translate(-0.3, 0.5, 0) eye_izq.childs += [eye] eye_der = sg.SceneGraphNode('eyeRight') eye_der.transform = tr.translate(0.3, 0.5, 0) eye_der.childs += [eye] # Ensamblamos el mono mono = sg.SceneGraphNode('chansey') mono.transform = tr.matmul( [tr.scale(0.4, 0.4, 0), tr.translate(0, -1.25, 0)]) mono.childs += [body, leg_izq, leg_der, eye_izq, eye_der] transform_mono = sg.SceneGraphNode('chanseyTR') transform_mono.childs += [mono] self.model = transform_mono self.pos = 0 self.lives = 3 self.killer_eggs = []
def __init__(self, tamaño): self.tamaño = tamaño #centra la cabeza de la serpiente al comienzo if self.tamaño % 2 == 0: self.pos = [[d / self.tamaño, d / self.tamaño], [d * 3 / self.tamaño, d / self.tamaño], [d * 5 / tamaño, d / self.tamaño], [d * 7 / tamaño, d / self.tamaño]] #self.pos = [[1/self.tamaño,1/self.tamaño],[3/self.tamaño,1/self.tamaño],[5/tamaño,1/self.tamaño]] else: self.pos = [[0, 0], [d * 2 / self.tamaño, 0], [d * 4 / self.tamaño, 0], [d * 6 / self.tamaño, 0]] #self.pos = [[0,0],[2/self.tamaño,0],[4/self.tamaño,0]] #self.dir = [['left','left'],['left','left'],['left','left']] self.dir = [['left', 'left'], ['left', 'left'], ['left', 'left'], ['left', 'left']] self.die = False self.comio = False self.comio_cola = False self.comiendo = False # Figuras básicas #gpu_trozo = es.toGPUShape(bs.createColorQuad(0, 0.3, 0)) # verde gpu_trozo = es.toGPUShape(bs.createTextureQuad('cuerpo.png'), GL_REPEAT, GL_NEAREST) gpu_trozo_cabeza = es.toGPUShape(bs.createTextureQuad('cabeza.png'), GL_REPEAT, GL_NEAREST) trozo = sg.SceneGraphNode('trozo') trozo.transform = tr.uniformScale(d * 2 / self.tamaño) trozo.childs += [gpu_trozo] trozo_cabeza = sg.SceneGraphNode('trozo') trozo_cabeza.transform = tr.uniformScale(d * 2 / self.tamaño) trozo_cabeza.childs += [gpu_trozo_cabeza] cuerpo = sg.SceneGraphNode('cuerpo') cuerpo.childs += [trozo] cuerpo2 = sg.SceneGraphNode('cuerpo2') cuerpo2.childs += [trozo] cola = sg.SceneGraphNode('cola') cola.childs += [trozo] cabeza = sg.SceneGraphNode('cabeza') cabeza.childs += [trozo_cabeza] self.serpiente = [cabeza, cuerpo, cuerpo2, cola] #self.serpiente =[cabeza,cuerpo,cola] self.tiempo = 0
def draw(self, pipeline): if self.last_direction == "D": self.face_orientation = "D" new_gpu_snake = es.toGPUShape(bs.createTextureQuad("boo_r.png"), GL_CLAMP, GL_NEAREST) sg.findNode(self.model, "snake_head").childs = [new_gpu_snake] elif self.last_direction == "A": self.face_orientation = "A" new_gpu_snake = es.toGPUShape(bs.createTextureQuad("boo_l.png"), GL_CLAMP, GL_NEAREST) sg.findNode(self.model, "snake_head").childs = [new_gpu_snake] sg.drawSceneGraphNode(self.model, pipeline, "transform")
def createCilindro(): h = 1 r = 0.03 lat = 20 lon = 20 dang = 2 * np.pi / lat color = { 'r': 0.6, # Red 'g': 0.6, # Green 'b': 0.6, # Blue } cylinder_shape = [] for i in range(lon): # Vertical component for j in range(lat): # Horizontal component # Angle on step j ang = dang * j # Here we create a quad from 4 vertices # # a/---- b/ # | | # d ---- c a = [r * np.cos(ang), r * np.sin(ang), h / lon * (i + 1)] b = [r * np.cos(ang + dang), r * np.sin(ang + dang), h / lon * (i + 1)] c = [r * np.cos(ang + dang), r * np.sin(ang + dang), h / lon * i] d = [r * np.cos(ang), r * np.sin(ang), h / lon * i] # Create quad shape = bs_ext.create4VertexColor(a, b, c, d, color['r'], color['g'], color['b']) cylinder_shape.append(es.toGPUShape(shape)) # Add the two covers for j in range(lat): ang = dang * j # Bottom a = [0, 0, 0] b = [r * np.cos(ang), r * np.sin(ang), 0] c = [r * np.cos(ang + dang), r * np.sin(ang + dang), 0] shape = bs_ext.createTriangleColor(c, b, a, color['r'], color['g'], color['b']) cylinder_shape.append(es.toGPUShape(shape)) # Top a = [0, 0, h] b = [r * np.cos(ang), r * np.sin(ang), h] c = [r * np.cos(ang + dang), r * np.sin(ang + dang), h] shape = bs_ext.createTriangleColor(c, b, a, color['r'], color['g'], color['b']) cylinder_shape.append(es.toGPUShape(shape)) return cylinder_shape
def __init__(self): # Figuras básicas gpu_black_back = es.toGPUShape(bs.createColorQuad(0, 0, 0)) gpu_blue_mid = es.toGPUShape(bs.createColorQuad(0, 1, 0.9)) gpu_white_sq = es.toGPUShape(bs.createColorQuad(1, 1, 1)) #creamos un medidor de revoluciones back = sg.SceneGraphNode('back') # cuarto de circulo generico back.transform = tr.scale(0.25, 1, 1) back.childs += [gpu_black_back] blue = sg.SceneGraphNode('blue') blue.transform = tr.scale(0.23, 0.98, 0) blue.childs += [gpu_blue_mid] white = sg.SceneGraphNode('white') white.transform = tr.scale(0.23, 0.18, 1) white.childs += [gpu_white_sq] white1 = sg.SceneGraphNode('white1') white1.transform = tr.translate(0, 0.4, 0) white1.childs += [white] white2 = sg.SceneGraphNode('white2') white2.transform = tr.translate(0, 0.2, 0) white2.childs += [white] white3 = sg.SceneGraphNode('white3') white3.transform = tr.translate(0, 0, 0) white3.childs += [white] white4 = sg.SceneGraphNode('white4') white4.transform = tr.translate(0, -0.2, 0) white4.childs += [white] white5 = sg.SceneGraphNode('white5') white5.transform = tr.translate(0, -0.4, 0) white5.childs += [white] # Ensamblamos el mono alt = sg.SceneGraphNode('alt') alt.transform = tr.matmul( [tr.translate(-0.53, -0.7, 0), tr.scale(0.35, 0.5, 1)]) alt.childs += [back, blue, white1, white2, white3, white4, white5] translate_alt = sg.SceneGraphNode('altTR') translate_alt.childs += [alt] self.model = alt self.pos = 0
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 = random.randint(0, self.tiles - 1) self.locationY = random.randint(1, self.tiles) # Aspect ratio ar = frame_height / frame_width #aspect_ratio_tr = tr.scale(ar, 1, 0) self.dimensions = [ar * 0.95 * 2 * 4 / 5, 0.95 * 2 * 4 / 5] gpu_apple = es.toGPUShape(my_shapes.apple()) apple = sg.SceneGraphNode('apple') apple.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) ]) apple.childs += [gpu_apple] apple_tr = sg.SceneGraphNode('apple_TR') apple_tr.childs += [apple] self.model = apple_tr
def __init__(self, texture): self.notice = es.toGPUShape(bs.createTextureQuad(texture), GL_REPEAT, GL_LINEAR) self.transnotice = np.matmul(tr2.translate(0, 0.4, 0), tr2.scale(-1, 1, 1)) self.winner = False self.loser = False
def shoot(self, bullet_collection, counter, speed): # se crea el controlador de animaciones y se inicializa con la textura bullet_anim = anim.Anim_Controller(self.bullet_animations, [BULLET_SIZE, BULLET_SIZE * WIDTH / HEIGHT, 1], 0) bullet_anim.Play("shooted") # se pone la textura de la bala #se crea un nodo que contiene la animacion scaled_bullet = sg.SceneGraphNode("scaled_bullet") scaled_bullet.transform = tr.rotationZ(np.pi) scaled_bullet.childs += [bullet_anim] # se crea un nodo con una gpuShape que servira para detectar las colisiones y verlas si se quiere collision_node = sg.SceneGraphNode("collision_enemyBullet") # se escala la hitbox para que tenga el mismo tamaño que la textura collision_node.transform = tr.scale(1, 1 * WIDTH / HEIGHT, 1) collision_node.childs += [es.toGPUShape(cl.createCircleHitbox(BULLET_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", BULLET_HITBOX_RADIO, True) scaled_collision.transform = tr.rotationZ(np.pi) #se voltea scaled_collision.childs += [collision_node] #posicion donde aparece la bala tempPos = self.position + self.bullet_pos # se crea el objeto bullet que contendra como nodos hijos a la animacion y la hitbox bullet_object = go.bulletObject("bullet" + str(counter)) bullet_object.fromEnemy = True #es bala enemiga # se traslada la bala en la pantalla a su posicion inicial bullet_object.transform = tr.translate(tempPos[0], tempPos[1], tempPos[2]) bullet_object.position = tempPos bullet_object.velocity[1] = -speed #se indica su velocidad bullet_object.childs += [scaled_bullet] #se agrega la animacion bullet_object.childs += [scaled_collision] #se agrega la hitbox bullet_object.childs[1].parent = bullet_object # se agrega la referencia de padre al objeto CollisionShape #se agrega el objeto bullet a la collecion de balas enemigas bullet_collection.childs += [bullet_object]
def __init__(self, width, height): # Frame dimensions self.width = width self.height = height self.alive = True self.g_over = None # Outer board dimensions self.dimensions = [ 0.5 * self.width * 9 / 16 * 16 / 9 * 2, 0.5 * self.height * 2 * 4 / 5 ] aspect_ratio_tr = tr.scale(self.height / self.width, 1, 0) gpu_bground = es.toGPUShape(bs.createColorQuad(0.05, 0.55, 0.23)) bground = sg.SceneGraphNode('background') bground.transform = tr.matmul([ aspect_ratio_tr, tr.scale(2 * self.width / self.height, 2 * 4 / 5, 0) ]) bground.childs += [gpu_bground] bground_tr = sg.SceneGraphNode('background_TR') bground_tr.childs += [bground] self.model = bground_tr
def __init__(self, pos, orientation): fondo = es.toGPUShape(bs.createTextureQuad("liana.jpg", 1, 1), GL_REPEAT, GL_LINEAR) fondoTransform= tr.uniformScale(2) self.model = fondo self.tra = fondoTransform self.pos = pos self.orientation = orientation
def shoot(self, bullet_collection, counter): #se crea un nodo que contiene la gpushape de la bala(con textura) y se escala bullet = sg.SceneGraphNode("bullet") bullet.transform = tr.scale(self.bullet_size, self.bullet_size * WIDTH/HEIGHT, 1) bullet.childs += [self.bullet] #se crea un nodo con una gpuShape que servira para detectar las colisiones(hitbox) collision_node = sg.SceneGraphNode("collision_bullet") collision_node.childs += [es.toGPUShape(cl.createCircleHitbox(BULLET_HITBOX_RADIO, 10, 0, 1, 0))] #posicion de donde sale la bala tempPos = self.position + self.bullet_pos #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", BULLET_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 bala que contendra en como nods hijos a la textura y la hitbox bullet_object = go.bulletObject("playerBullet" + str(counter)) bullet_object.fromEnemy = False #bool para saber si es una bala enemiga bullet_object.transform = tr.translate(tempPos[0], tempPos[1], tempPos[2]) # se ubica en la posicion inicial bullet_object.position = tempPos bullet_object.velocity[1] = BULLET_SPEED # se le asigna la velocidad vertical bullet_object.childs += [bullet] #se le agrega la textura bullet_object.childs += [scaled_collision] # se le agrega la hitbox bullet_object.childs[1].parent = bullet_object # se le agrega la referencia del padre al objeto CollisoinShape #se agrega la bala a la coleccion de balas bullet_collection.childs += [bullet_object]
def crece(self): tamaño_snake = len(self.dir) direccion_cola = self.dir[-1][1] #self.pos += [self.pos[-1]] if direccion_cola == 'left': self.pos += [[self.pos[-1][0], self.pos[-1][1]]] elif direccion_cola == 'right': self.pos += [[self.pos[-1][0], self.pos[-1][1]]] elif direccion_cola == 'up': self.pos += [[self.pos[-1][0], self.pos[-1][1]]] else: self.pos += [[self.pos[-1][0], self.pos[-1][1]]] self.dir += [['stop', 'stop']] gpu_trozo = es.toGPUShape(bs.createTextureQuad('cuerpo.png'), GL_REPEAT, GL_NEAREST) trozo = sg.SceneGraphNode('trozo') trozo.transform = tr.uniformScale(d * 2 / self.tamaño) trozo.childs += [gpu_trozo] aum = sg.SceneGraphNode(str(tamaño_snake)) aum.childs += [trozo] self.serpiente += [aum]
def createExplosion(): gpuWhiteTriangle = es.toGPUShape(createColorTriangle(1, 1, 1)) gpuOrangeTriangle = es.toGPUShape(createColorTriangle(1, 0.5, 0)) whitePart = sg.SceneGraphNode("whitePart") whitePart.transform = tr.uniformScale(0.7) orangePart = sg.SceneGraphNode("orangePart") theta = math.pi # Creating the white part tri0 = sg.SceneGraphNode("tri0") tri0.transform = tr.matmul( [tr.translate(0, -0.15, 0), tr.rotationZ(theta)]) tri0.childs += [gpuWhiteTriangle] tri1 = sg.SceneGraphNode("tri1") tri1.transform = tr.matmul( [tr.translate(0, 0.15, 0), tr.rotationZ(theta * 2)]) tri1.childs += [gpuWhiteTriangle] whitePart.childs += [tri0, tri1] # Creating the orange part angle0 = sg.SceneGraphNode("angle0") angle0.transform = tr.matmul( [tr.translate(0, -0.15, 0), tr.rotationZ(theta)]) angle0.childs += [gpuOrangeTriangle] angle1 = sg.SceneGraphNode("angle1") angle1.transform = tr.matmul( [tr.translate(0, 0.15, 0), tr.rotationZ(theta * 2)]) angle1.childs += [gpuOrangeTriangle] orangePart.childs += [angle0, angle1] # Joining both parts explosion = sg.SceneGraphNode("explosion") explosion.childs = [orangePart, whitePart] return explosion
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 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