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 getTransform(showTransform, theta): if showTransform == TR_STANDARD: return tr.identity() elif showTransform == TR_ROTATE_ZP: return tr.rotationZ(theta) elif showTransform == TR_ROTATE_ZM: return tr.rotationZ(-theta) elif showTransform == TR_TRANSLATE: return tr.translate(0.3 * np.cos(theta), 0.3 * np.cos(theta), 0) elif showTransform == TR_UNIFORM_SCALE: return tr.uniformScale(0.7 + 0.5 * np.cos(theta)) elif showTransform == TR_NONUNIF_SCALE: return tr.scale(1.0 - 0.5 * np.cos(1.5 * theta), 1.0 + 0.5 * np.cos(2 * theta), 1.0) elif showTransform == TR_REFLEX_Y: return tr.scale(1, -1, 1) elif showTransform == TR_SHEARING_XY: return tr.shearing(0.3 * np.cos(theta), 0, 0, 0, 0, 0) else: # This should NEVER happend raise Exception()
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 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 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 createBullet(player = True): gpuVariantQuad = es.toGPUShape(bs.createColorQuad(int(player), 1, 0)) littleBullet = sg.SceneGraphNode("littleBullet") littleBullet.transform = tr.matmul([tr.rotationZ(math.pi / 4), tr.uniformScale(0.05)]) littleBullet.childs += [gpuVariantQuad] bullet = sg.SceneGraphNode("bullet") bullet.childs += [littleBullet] return bullet
def draw(self, pipeline, projection, view): glUseProgram(pipeline.shaderProgram) 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.rotationZ(-np.pi / 2), tr.uniformScale(4), tr.translate(self.posy, self.posx, self.posz) ])) pipeline.drawShape(self.model)
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 createCircleHitbox(radio, sides, r, g, b): vertices = [0, 0, 0, r, g, b] indices = [] xt = np.array([radio, 0, 0, 1]) vertices += [xt[0], xt[1], xt[2], r, g, b] indices += [0, 1, 2] for i in range(1, sides + 1): xtp = np.matmul(tr.rotationZ((2 / sides) * i * np.pi), xt) xtr = np.array([xtp[0], xtp[1], xtp[2]]) / xtp[3] vertices += [xtr[0], xtr[1], xtr[2], r, g, b] if i == (sides): indices += [0, i + 1, 1] else: indices += [0, i + 1, i + 2] return bs.Shape(vertices, indices)
def AddNebulae(neb_collection): #se define un tamaño random scale = NEBULA_MIN_SCALE + random.random() * (NEBULA_MAX_SCALE - NEBULA_MIN_SCALE) size = scale #se define una rotacion random randRotInt = random.randint(0, 3) rotation = randRotInt * math.pi / 2 #posicion horizontal random posX = random.randint(-1, 1) * random.random() * scale * 0.5 #posicion vertical definida por las otras nebulosas posY = 0 if len(neb_collection.childs) == 0: posY = -1 + size / 2 else: last_posY = neb_collection.childs[-1].position[1] last_size = neb_collection.childs[-1].size posY = last_posY + last_size / 2 + size / 2 #se crea un nodo que contiene una nebula random y se escal nebula = sg.SceneGraphNode("nebula") nebula.transform = tr.matmul([tr.uniformScale(scale)]) rand_nebula = random.randint(0, len(nebulae_images) - 1) nebula.childs += [nebulae_images[rand_nebula]] #nodo que se rota scaledNebula = sg.SceneGraphNode("scaledNebula") scaledNebula.transform = tr.rotationZ(rotation) scaledNebula.childs += [nebula] #gameObject que se posiciona en la pantalla neb_object = gameObject("neb_object") neb_object.transform = tr.translate(posX, posY, 0) neb_object.size = size neb_object.position[0] = posX neb_object.position[1] = posY neb_object.childs += [scaledNebula] #se agrega a la coleccion de nodos neb_collection.childs += [neb_object]
def crearNube(): gpuWhiteCirc = es.toGPUShape(bs.createCircle([0.95, 0.95, 0.95])) #Se crea la base de la nube circulito = sg.SceneGraphNode("circulito") circulito.transform = tr.uniformScale(0.02) circulito.childs += [gpuWhiteCirc] base = sg.SceneGraphNode("base") baseName = "base" for i in range(-5, 4): #Se utiliza esto para crear la parte inicial de la nube newNode = sg.SceneGraphNode(baseName + str(i)) newNode.transform = tr.translate(0.015 * i, 0.011 * (-1)**i, 0) newNode.childs += [circulito] base.childs += [newNode] nube = sg.SceneGraphNode("nube") baseName1 = "nube" for i in range(0, 2): #Se crea la parte de abajo de la nube newNode = sg.SceneGraphNode(baseName1 + str(i)) newNode.transform = tr.matmul([ tr.translate(-0.03 * (i - 1), -0.04 * i, 0), tr.rotationZ(np.pi * i) ]) newNode.childs += [base] nube.childs += [newNode] nubeAlta = sg.SceneGraphNode("nubeAlta") nubeAlta.transform = tr.translate(0, 0.8, 0) nubeAlta.childs += [nube] return nubeAlta
def createShip(): gpuWhiteQuad = es.toGPUShape(bs.createColorQuad(1, 1, 1)) gpuGreyTriangle = es.toGPUShape(bs.createColorTriangle(0.5, 0.5, 0.5)) gpuOrangeTriangle = es.toGPUShape(bs.createColorTriangle(1, 112 / 255, 40 / 255)) gpuYellowTriangle = es.toGPUShape(bs.createColorTriangle(1, 1, 0)) gpuRedTriangle = es.toGPUShape(bs.createColorTriangle(1, 0, 0)) # Creating a single orange flame orangeFlame = sg.SceneGraphNode("orangeFlame") orangeFlame.transform = tr.matmul([tr.rotationZ(np.pi), tr.uniformScale(0.1)]) orangeFlame.childs += [gpuOrangeTriangle] # Instanciating 6 orange flames, for the wings and back parts backLeftOrangeFlame = sg.SceneGraphNode("backLeftOrangeFlame") backLeftOrangeFlame.transform = tr.translate(-0.11,-0.55, 0.0 ) backLeftOrangeFlame.childs += [orangeFlame] backRightOrangeFlame = sg.SceneGraphNode("backRightOrangeFlame") backRightOrangeFlame.transform = tr.translate(0.11, -0.55, 0.0) backRightOrangeFlame.childs += [orangeFlame] leftWingLeftOrangeFlame = sg.SceneGraphNode("leftWingLeftOrangeFlame") leftWingLeftOrangeFlame.transform = tr.matmul([tr.translate(-0.45, -0.07, 0.0), tr.uniformScale(0.5)]) leftWingLeftOrangeFlame.childs += [orangeFlame] leftWingRightOrangeFlame = sg.SceneGraphNode("leftWingRightOrangeFlame") leftWingRightOrangeFlame.transform = tr.matmul([tr.translate(-0.3, -0.07, 0.0), tr.uniformScale(0.5)]) leftWingRightOrangeFlame.childs += [orangeFlame] rightWingLeftOrangeFlame = sg.SceneGraphNode("rightWingLeftOrangeFlame") rightWingLeftOrangeFlame.transform = tr.matmul([tr.translate(0.3, -0.07, 0.0), tr.uniformScale(0.5)]) rightWingLeftOrangeFlame.childs += [orangeFlame] rightWingRightOrangeFlame = sg.SceneGraphNode("rightWingRightOrangeFlame") rightWingRightOrangeFlame.transform = tr.matmul([tr.translate(0.45, -0.07, 0.0), tr.uniformScale(0.5)]) rightWingRightOrangeFlame.childs += [orangeFlame] # Creating a single yellow flame yellowFlame = sg.SceneGraphNode("yellowFlame") yellowFlame.transform = tr.matmul([tr.rotationZ(np.pi), tr.uniformScale(0.2)]) yellowFlame.childs += [gpuYellowTriangle] # Instanciating 6 yellow flames, for the wings and back parts backLeftYellowFlame = sg.SceneGraphNode("backLeftYellowFlame") backLeftYellowFlame.transform = tr.translate(-0.11, -0.6, 0.0) backLeftYellowFlame.childs += [yellowFlame] backRightYellowFlame = sg.SceneGraphNode("backRightYellowFlame") backRightYellowFlame.transform = tr.translate(0.11, -0.6, 0.0) backRightYellowFlame.childs += [yellowFlame] leftWingLeftYellowFlame = sg.SceneGraphNode("leftWingLeftYellowFlame") leftWingLeftYellowFlame.transform = tr.matmul([tr.translate(-0.45, -0.1, 0.0), tr.uniformScale(0.5)]) leftWingLeftYellowFlame.childs += [yellowFlame] leftWingRightYellowFlame = sg.SceneGraphNode("leftWingRightYellowFlame") leftWingRightYellowFlame.transform = tr.matmul([tr.translate(-0.3, -0.1, 0.0), tr.uniformScale(0.5)]) leftWingRightYellowFlame.childs += [yellowFlame] rightWingLeftYellowFlame = sg.SceneGraphNode("rightWingLeftYellowFlame") rightWingLeftYellowFlame.transform = tr.matmul([tr.translate(0.3, -0.1, 0.0), tr.uniformScale(0.5)]) rightWingLeftYellowFlame.childs += [yellowFlame] rightWingRightYellowFlame = sg.SceneGraphNode("rightWingRightYellowFlame") rightWingRightYellowFlame.transform = tr.matmul([tr.translate(0.45, -0.1, 0.0), tr.uniformScale(0.5)]) rightWingRightYellowFlame.childs += [yellowFlame] # Creating a single wing wing = sg.SceneGraphNode("wing") wing.transform = tr.matmul([tr.translate(0, 0.3, 0), tr.scale(1.1, 0.7, 1)]) wing.childs += [gpuGreyTriangle] # Creating the upper part upper = sg.SceneGraphNode("upper") upper.transform = tr.matmul([tr.translate(0, 0.7, 0), tr.uniformScale(0.5)]) upper.childs += [gpuRedTriangle] # Creating the chasis of the ship chasis = sg.SceneGraphNode("chasis") chasis.transform = tr.scale(0.5, 1, 1) chasis.childs += [gpuWhiteQuad] ship = sg.SceneGraphNode("ship") ship.transform = tr.matmul([tr.translate(0, -0.8, 0), tr.uniformScale(0.2)]) ship.childs += [backLeftYellowFlame] ship.childs += [backRightYellowFlame] ship.childs += [leftWingLeftYellowFlame] ship.childs += [leftWingRightYellowFlame] ship.childs += [rightWingLeftYellowFlame] ship.childs += [rightWingRightYellowFlame] ship.childs += [backLeftOrangeFlame] ship.childs += [backRightOrangeFlame] ship.childs += [leftWingLeftOrangeFlame] ship.childs += [leftWingRightOrangeFlame] ship.childs += [rightWingLeftOrangeFlame] ship.childs += [rightWingRightOrangeFlame] ship.childs += [wing] ship.childs += [upper] ship.childs += [chasis] translatedShip = sg.SceneGraphNode("translatedShip") translatedShip.childs += [ship] translatedShip.pos_x = controller.x translatedShip.pos_y = controller.y return translatedShip
def createEnemyShip(): gpuGreenQuad = es.toGPUShape(bs.createColorQuad(0, 1, 0)) gpuBlueTriangle = es.toGPUShape(bs.createColorTriangle(0, 0, 1)) gpuGreyTriangle = es.toGPUShape(bs.createColorTriangle(0.5, 0.5, 0.5)) gpuOrangeTriangle = es.toGPUShape(bs.createColorTriangle(1, 112 / 255, 40 / 255)) gpuYellowTriangle = es.toGPUShape(bs.createColorTriangle(1, 1, 0)) # Creating a single orange flame orangeFlame = sg.SceneGraphNode("orangeFlame") orangeFlame.transform = tr.matmul([tr.rotationZ(np.pi), tr.uniformScale(0.1)]) orangeFlame.childs += [gpuOrangeTriangle] # Instanciating 2 orange flames, for the back part backLeftOrangeFlame = sg.SceneGraphNode("backLeftOrangeFlame") backLeftOrangeFlame.transform = tr.translate(-0.11, -0.35, 0.0) backLeftOrangeFlame.childs += [orangeFlame] backRightOrangeFlame = sg.SceneGraphNode("backRightOrangeFlame") backRightOrangeFlame.transform = tr.translate(0.11, -0.35, 0.0) backRightOrangeFlame.childs += [orangeFlame] # Creating a single yellow flame yellowFlame = sg.SceneGraphNode("yellowFlame") yellowFlame.transform = tr.matmul([tr.rotationZ(np.pi), tr.uniformScale(0.2)]) yellowFlame.childs += [gpuYellowTriangle] # Instanciating 2 yellow flames, for the back part backLeftYellowFlame = sg.SceneGraphNode("backLeftYellowFlame") backLeftYellowFlame.transform = tr.translate(-0.11, -0.4, 0.0) backLeftYellowFlame.childs += [yellowFlame] backRightYellowFlame = sg.SceneGraphNode("backRightYellowFlame") backRightYellowFlame.transform = tr.translate(0.11, -0.4, 0.0) backRightYellowFlame.childs += [yellowFlame] # Creating the back part back = sg.SceneGraphNode("wing") back.transform = tr.uniformScale(0.7) back.childs += [gpuGreyTriangle] # Creating the upper part upper = sg.SceneGraphNode("upper") upper.transform = tr.matmul([tr.translate(0, 0.5, 0), tr.uniformScale(0.5)]) upper.childs += [gpuBlueTriangle] # Creating the chasis of the ship chasis = sg.SceneGraphNode("chasis") chasis.transform = tr.uniformScale(0.5) chasis.childs += [gpuGreenQuad] enemyShip = sg.SceneGraphNode("enemyShip") enemyShip.transform = tr.matmul([tr.translate(0, 2, 0), tr.rotationZ(np.pi), tr.uniformScale(0.2)]) enemyShip.childs += [backLeftYellowFlame] enemyShip.childs += [backRightYellowFlame] enemyShip.childs += [backLeftOrangeFlame] enemyShip.childs += [backRightOrangeFlame] enemyShip.childs += [back] enemyShip.childs += [upper] enemyShip.childs += [chasis] translatedEnemyShip = sg.SceneGraphNode("translatedEnemyShip") translatedEnemyShip.childs += [enemyShip] translatedEnemyShip.pos_x = 1 translatedEnemyShip.pos_y = 2 return translatedEnemyShip
glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "transform"), 1, GL_TRUE, quadTransform2) drawShape(shaderProgram, gpuQuad) # Quad quadTransform = tr.matmul( [tr.translate(0, 0.4, 0), tr.scale(0.25, 0.25, 0)]) glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "transform"), 1, GL_TRUE, quadTransform) drawShape(shaderProgram, gpuCirc) # Quad quadTransform = tr.matmul([ tr.translate(0.25, 0.4, 0), tr.rotationZ(-3 * pi / 4), tr.uniformScale(0.21) ]) glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "transform"), 1, GL_TRUE, quadTransform) drawShape(shaderProgram, gpuQuad) # Quad quadTransform = tr.matmul([ tr.translate(-0.25, 0.4, 0), tr.rotationZ(pi / 4), tr.uniformScale(0.21) ]) glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "transform"), 1, GL_TRUE, quadTransform) drawShape(shaderProgram, gpuQuad)
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) # Creating shapes on GPU memory # Landscape gpuHills = es.toGPUShape(bs.createTextureNormalsCube('hills.png'), GL_REPEAT, GL_LINEAR) gpuGrass = es.toGPUShape(bs.createTextureNormalsCube('grass.jpg'), GL_REPEAT, GL_LINEAR) gpuSky = es.toGPUShape(bs.createTextureNormalsCube('sky.jpg'), GL_REPEAT, GL_LINEAR) # Transformations of the landscape leftHills = tr.matmul([tr.translate(25, -25, 0), tr.scale(0.1, 100, 20)]) frontHills = tr.matmul([ tr.translate(0, -50, 0), tr.rotationZ(np.pi / 2), tr.scale(0.1, 100, 20) ]) rightHills = tr.matmul([tr.translate(-25, -25, 0), tr.scale(0.1, 100, 20)]) grass = tr.matmul([tr.translate(0, -30, -10), tr.scale(50, 100, 0.1)]) sky = tr.matmul([tr.translate(0, -30, 10), tr.scale(50, 100, 0.1)]) # Birds bird = Bird() birdNode1 = bird.get_bird() birdNode2 = bird.get_bird() birdNode3 = bird.get_bird() birdNode4 = bird.get_bird() birdNode5 = bird.get_bird() birdNodes = [birdNode1, birdNode2, birdNode3, birdNode4, birdNode5]
def crearNave(): gpuBCirc = es.toGPUShape(bs.createCircle([0,0.4627,0.4118])) gpuBlackCirc = es.toGPUShape(bs.createCircle([0,0,0])) gpuSBCirc = es.toGPUShape(bs.createSemiCircle([0,0,0])) gpuSGreenCirc = es.toGPUShape(bs.createSemiCircle([0.4392,1,0.4078])) gpuGreenCirc = es.toGPUShape(bs.createCircle([0.4392,1,0.4078])) gpuBlackQuad = es.toGPUShape(bs.createColorQuad(0,0,0)) gpuGreenQuad = es.toGPUShape(bs.createColorQuad(0.4392,1,0.4078)) #Se crea la parte mas grande de la nave (asi como el chasis de auto) base = sg.SceneGraphNode("base") base.transform = tr.scale(0.5,0.08,0) base.childs += [gpuBCirc] #Creamos el "vidrio" de la nave, que es la parte donde podemos ver al marcianito, se crea negro para que sea mas facil ver la nave #y al marciano debido a que con los colores del fondo la nave se pierde vidrio = sg.SceneGraphNode("vidrio") vidrio.transform = tr.matmul([tr.translate(0,0.02,0),tr.scale(0.2,0.35,0)]) vidrio.childs += [gpuSBCirc] #Se crean las patas de la nave, compuestas por una bolita negra y un rectangulo del mismo color pataIzq = sg.SceneGraphNode("pataIzq") pataIzq.transform = tr.matmul([tr.rotationZ(np.pi/5) ,tr.scale(0.02,0.25,0)]) pataIzq.childs += [gpuBlackQuad] pataDer = sg.SceneGraphNode("pataDer") pataDer.transform = tr.matmul([tr.rotationZ(-(np.pi/5)) ,tr.scale(0.02,0.25,0)]) pataDer.childs += [gpuBlackQuad] pataItras = sg.SceneGraphNode("pataItras") pataItras.transform = tr.translate(0.3,-0.1,0) pataItras.childs += [pataIzq] pataDtras = sg.SceneGraphNode("pataDtras") pataDtras.transform = tr.translate(-0.3,-0.1,0) pataDtras.childs += [pataDer] finPataI = sg.SceneGraphNode("finPataI") finPataI.transform = tr.matmul([tr.translate(0.375,-0.2,0) ,tr.uniformScale(0.025)]) finPataI.childs += [gpuBlackCirc] finPataD = sg.SceneGraphNode("finPataD") finPataD.transform = tr.matmul([tr.translate(-0.375,-0.2,0) ,tr.uniformScale(0.025)]) finPataD.childs += [gpuBlackCirc] pataD = sg.SceneGraphNode("pataD") pataD.childs += [pataDtras, finPataD] pataI = sg.SceneGraphNode("pataI") pataI.childs += [pataItras, finPataI] #Creamos al marcianito #Se crea primero el cuerpo cuerpoTripulacion = sg.SceneGraphNode("cuerpoTripulacion") cuerpoTripulacion.transform = tr.matmul([tr.translate(0,0.02,0), tr.scale(0.03,0.06,0)]) cuerpoTripulacion.childs += [gpuSGreenCirc] #Creamos la cabeza cabezaTripulacion = sg.SceneGraphNode("cabezaTripulacion") cabezaTripulacion.transform = tr.matmul([tr.translate(0,0.12,0) , tr.uniformScale(0.04)]) cabezaTripulacion.childs += [gpuGreenCirc] #Aqui creamos las antenas completas del marcianito, con una idea muy parecida a las patas de la nave antenaD = sg.SceneGraphNode("antenaD") antenaD.transform = tr.matmul([tr.translate(0.017,0.165,0) ,tr.scale(0.01,0.025,0)]) antenaD.childs += [gpuGreenQuad] antenaI = sg.SceneGraphNode("antenaI") antenaI.transform = tr.matmul([tr.translate(-0.017,0.165,0),tr.scale(0.01,0.025,0)]) antenaI.childs += [gpuGreenQuad] finAnD = sg.SceneGraphNode("finAnD") finAnD.transform = tr.matmul([tr.translate(0.017,0.19,0) , tr.uniformScale(0.015)]) finAnD.childs = [gpuGreenCirc] finAnI = sg.SceneGraphNode("finAnI") finAnI.transform = tr.matmul([tr.translate(-0.017,0.19,0) , tr.uniformScale(0.015)]) finAnI.childs = [gpuGreenCirc] #Se crea la nave en conjunto con la tripulacion nave = sg.SceneGraphNode("nave") nave.transform = tr.matmul([tr.translate(0,0.7,0) , tr.uniformScale(0.1)]) nave.childs += [pataI, pataD, base, vidrio, cuerpoTripulacion, cabezaTripulacion, antenaD, antenaI, finAnD, finAnI] #Se crea esto para luego poder trasladar la nave en la parte final navef = sg.SceneGraphNode("navef") navef.childs += [nave] return navef
def createTree(rule="F[RF]F[LF]F", order=1, size=1.0, skip=0): # The different parts of the tree with different materials woodGraph = sg.SceneGraphNode("wood") leavesGraph = sg.SceneGraphNode("leaves") # Scene graph that will contain the whole tree treeGraph = sg.SceneGraphNode("tree") treeGraph.childs += [woodGraph, leavesGraph] # String used to construct the tree blueprint = "F" # Variables used to keep the size consistent counter = 0 lockCounter = 0 # Applies the rule to the blueprint, increasing the complexity for _ in range(order): newBlueprint = "" for character in blueprint: newBlueprint += rule if character == "F" else character blueprint = newBlueprint blueprint += "]" # Counts how many times the rule is applied, reducing the size of the # branches in order to make a tree of the given size for character in rule: if character == "F" and lockCounter == 0: counter += 1 elif character == "[": lockCounter += 1 elif character == "]": lockCounter -= 1 size /= counter**order # Base gpu shapes gpuBranch = es.toGPUShape(createBranch(size, 0.05)) gpuLeaf = es.toGPUShape(createLeaf()) # Lists that store the information necessary to put new branches phiList = [0] thetaList = [0] decayList = [0.8] xList = [0] yList = [0] zList = [0] allLists = [phiList, thetaList, decayList, xList, yList, zList] # Creating the tree for character in blueprint: # Creating a new branch considering the lists of properties if character == "F": phi = phiList[-1] theta = thetaList[-1] decay = decayList[-1] x = xList[-1] y = yList[-1] z = zList[-1] # Adding the wood branchGraph = sg.SceneGraphNode("branch") branchGraph.childs += [gpuBranch] rotation = tr.matmul([tr.rotationZ(theta), tr.rotationY(phi)]) branchGraph.transform = tr.matmul( [rotation, tr.uniformScale(decay)]) branchGraph.transform = tr.matmul( [tr.translate(x, y, z), branchGraph.transform]) woodGraph.childs += [branchGraph] # Changing the position of the next branch localSize = size * decay xList[-1] += localSize * np.sin(phi) * np.cos(theta) yList[-1] += localSize * np.sin(phi) * np.sin(theta) zList[-1] += localSize * np.cos(phi) # Changing the angle of the next branch using a spherical system elif character == "L": phiList[-1] += BRANCH_ANGLE elif character == "R": phiList[-1] -= BRANCH_ANGLE elif character == "U": thetaList[-1] += BRANCH_ANGLE elif character == "D": thetaList[-1] -= BRANCH_ANGLE # Setting up a new path for the branches elif character == "[": for ls in allLists: ls.append(ls[-1]) decayList[-1] **= 2 # Closing a path, sometimes with a leaf elif character == "]": if skip > 0: skip -= 1 else: x = xList[-1] y = yList[-1] z = zList[-1] # Adding a leaf at the end of a path leafGraph = sg.SceneGraphNode("leaf") leafGraph.childs += [gpuLeaf] leafSize = tr.uniformScale(0.2 * size * decayList[-1]) leafGraph.transform = tr.matmul( [tr.translate(x, y, z), leafSize]) leavesGraph.childs += [leafGraph] for ls in allLists: ls.pop() return treeGraph
def createBackground(): gpuFarQuad = es.toGPUShape(bs.createColorQuad(0.1, 0.1, 0.1)) gpuMediumQuad = es.toGPUShape(bs.createColorQuad(0.2, 0.2, 0.2)) gpuCloseQuad = es.toGPUShape(bs.createColorQuad(0.3, 0.3, 0.3)) # Creating the shape of the stars farQuad = sg.SceneGraphNode("farQuad") farQuad.transform = tr.matmul( [tr.rotationZ(math.pi / 4), tr.uniformScale(0.04)]) farQuad.transform = tr.matmul([tr.scale(0.8, 1, 0), farQuad.transform]) farQuad.childs += [gpuFarQuad] mediumQuad = sg.SceneGraphNode("mediumQuad") mediumQuad.transform = farQuad.transform mediumQuad.childs += [gpuMediumQuad] closeQuad = sg.SceneGraphNode("closeQuad") closeQuad.transform = farQuad.transform closeQuad.childs += [gpuCloseQuad] farLayer = sg.SceneGraphNode("farLayer") mediumLayer = sg.SceneGraphNode("mediumLayer") closeLayer = sg.SceneGraphNode("closeLayer") # Adding the stars at random sequence = np.random.randint(-9, 10, (3, 4, 2)) for dup in sequence[0]: farStar = sg.SceneGraphNode("farQuad") farStar.transform = tr.translate(dup[0] / 10.0, dup[1] / 10.0, 0) farStar.childs += [farQuad] farLayer.childs += [farStar] for dup in sequence[1]: mediumStar = sg.SceneGraphNode("mediumQuad") mediumStar.transform = tr.translate(dup[0] / 10.0, dup[1] / 10.0, 0) mediumStar.childs += [mediumQuad] mediumLayer.childs += [mediumStar] for dup in sequence[2]: closeStar = sg.SceneGraphNode("closeQuad") closeStar.transform = tr.translate(dup[0] / 10.0, dup[1] / 10.0, 0) closeStar.childs += [closeQuad] closeLayer.childs += [closeStar] # Joining the layers background = sg.SceneGraphNode("background") background.transform = tr.translate(0, 0, 0) background.childs += [farLayer] background.childs += [mediumLayer] background.childs += [closeLayer] # An extension of the background in order to allow # limited scrolling backgroundExtra = sg.SceneGraphNode("backgroundExtra") backgroundExtra.transform = tr.translate(0, 2, 0) backgroundExtra.childs += [background] finalBackground = sg.SceneGraphNode("finalBackground") finalBackground.childs = [background, backgroundExtra] return finalBackground
def __init__(self): #creamos el avion # Figuras básicas gpu_body_quad = es.toGPUShape(bs.createColorQuad(0.65, 0.65, 0.65)) # gris gpu_tail_triangle = es.toGPUShape( bs.createColorTriangle(0.65, 0.65, 0.65)) # gris gpu_nose_triangle = es.toGPUShape( bs.createColorTriangle(0.65, 0.65, 0.65)) # gris gpu_wing_quad = es.toGPUShape(bs.createColorQuad(1, 0.5, 0.5)) # gris oscuro gpu_window_quad = es.toGPUShape(bs.createColorQuad(0, 1, 0.86)) # celeste #creamos el "cuerpo" body = sg.SceneGraphNode('body') body.transform = tr.scale(2.5, 0.7, 1) #alargamos el "cuerpo" del avion body.childs += [gpu_body_quad] # Creamos las ventanas window = sg.SceneGraphNode('window') # ventana generica window.transform = tr.scale(0.25, 0.25, 1) window.childs += [gpu_window_quad] # prueba dos ventanas window_1 = sg.SceneGraphNode('window_1') window_1.transform = tr.translate(1, 0.14, 0) # tr.matmul([]).. window_1.childs += [window] window_2 = sg.SceneGraphNode('window_2') window_2.transform = tr.translate(0.65, 0.14, 0) # tr.matmul([]).. window_2.childs += [window] window_3 = sg.SceneGraphNode('window_3') window_3.transform = tr.translate(0.3, 0.14, 0) # tr.matmul([]).. window_3.childs += [window] # cola tail = sg.SceneGraphNode('tail') #ventana generica tail.transform = tr.rotationZ( 0.46 ) #dejamos el borde trasero del triangulo ortogonal al cuerpo uwu tail.childs += [gpu_tail_triangle] tail_back = sg.SceneGraphNode('eyeLeft') tail_back.transform = tr.matmul( [tr.translate(-1.0092, 0.4, 0), tr.scale(1.1, 1.1, 0)]) tail_back.childs += [tail] # nariz nose = sg.SceneGraphNode('nose') #ventana generica nose.transform = tr.matmul([ tr.rotationZ(0.465), tr.translate(1.26, -0.55, 0), tr.scale(0.64, 0.64, 0) ]) nose.childs += [gpu_nose_triangle] #ala wing = sg.SceneGraphNode('wing') wing.transform = tr.matmul([ tr.rotationZ(-0.55), tr.translate(0.1, -0.5, 0), tr.scale(0.3, 1, 0) ]) wing.childs += [gpu_wing_quad] self.a = 0 #indica la aceleración del avión # Ensamblamos el mono mono = sg.SceneGraphNode('chansey') mono.transform = tr.matmul( [tr.scale(0.1, 0.2, 0), tr.translate(-8, -1.6, 0)]) mono.childs += [ body, window_1, window_2, window_3, tail_back, nose, wing ] transform_mono = sg.SceneGraphNode('chanseyTR') transform_mono.childs += [mono] self.model = transform_mono self.pos = 0 #posicion de la tecla, 1=> acelerando, -1=> desacelerando, 0=>cayendo
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 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
# Telling OpenGL to use our shader program glUseProgram(shaderProgram) # Setting up the clear screen color glClearColor(0.85, 0.85, 0.85, 1.0) # Creating shapes on GPU memory car = createCar() # Our shapes here are always fully painted glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) while not glfw.window_should_close(window): # Using GLFW to check for input events glfw.poll_events() # Clearing the screen in both, color and depth glClear(GL_COLOR_BUFFER_BIT) # Modifying only a specific node in the scene graph wheelRotationNode = sg.findNode(car, "wheelRotation") theta = -10 * glfw.get_time() wheelRotationNode.transform = tr.rotationZ(theta) # Drawing the Car sg.drawSceneGraphNode(car, shaderProgram, tr.identity()) # Once the render is done, buffers are swapped, showing only the complete scene. glfw.swap_buffers(window) glfw.terminate()
def draw_game_over(self, pipeline, dt): sg.findNode(self.g_over, "game_over_banner_TR").transform = tr.matmul([ sg.findTransform(self.g_over, "game_over_banner_TR"), tr.rotationZ(dt) ]) sg.drawSceneGraphNode(self.g_over, pipeline, "transform")
voxBcolor[2]) gpubodyB = es.toGPUShape(bodyB) gpuFinB = es.toGPUShape(finB) bodyC, finC, finbodytrC = fm.make_fish(4. / 1, 1 / 2, 0.1, voxCcolor[0], voxCcolor[1], voxCcolor[2]) gpubodyC = es.toGPUShape(bodyC) gpuFinC = es.toGPUShape(finC) fish = [] # Add type A fish samples = fish_volumes[0].get_samples(config['n_a']) for p in samples: pos = tr.matmul( [tr.translate(*p), tr.rotationZ(2 * np.pi * np.random.random())]) fish.append(fm.Fish(3, gpubodyA, gpuFinA, finbodytrA, pos)) # Add type B fish samples = fish_volumes[1].get_samples(config['n_b']) for p in samples: pos = tr.matmul( [tr.translate(*p), tr.rotationZ(2 * np.pi * np.random.random())]) fish.append(fm.Fish(6, gpubodyB, gpuFinB, finbodytrB, pos)) # Add type C fish samples = fish_volumes[2].get_samples(config['n_c']) for p in samples: pos = tr.matmul( [tr.translate(*p), tr.rotationZ(2 * np.pi * np.random.random())]) fish.append(fm.Fish(1.8, gpubodyC, gpuFinC, finbodytrC, pos))
def __init__(self): # Figuras básicas gpu_quarter_circle = es.toGPUShape(bs.createQuarterCircle()) gpu_indicator_line = es.toGPUShape(bs.createColorQuad(1.0, 1.0, 1.0)) gpu_center = es.toGPUShape(bs.createColorQuad(1, 1, 1)) #creamos un medidor de revoluciones qvel = sg.SceneGraphNode('qvel') # cuarto de circulo generico qvel.transform = tr.scale(0.25, 0.25, 1) qvel.childs += [gpu_quarter_circle] q1vel = sg.SceneGraphNode('q1vel') q1vel.childs += [qvel] q2vel = sg.SceneGraphNode('q2vel') q2vel.transform = tr.rotationZ(1.57) q2vel.childs += [qvel] q3vel = sg.SceneGraphNode('q3vel') q3vel.transform = tr.rotationZ(3.14) q3vel.childs += [qvel] q4vel = sg.SceneGraphNode('q4vel') q4vel.transform = tr.rotationZ(-1.57) q4vel.childs += [qvel] #un centro centro = sg.SceneGraphNode('centro') centro.transform = tr.uniformScale(0.02) centro.childs += [gpu_center] #hacemos los grados raya = sg.SceneGraphNode('raya') raya.childs += [gpu_indicator_line] raya1 = sg.SceneGraphNode('raya1') raya1.transform = tr.matmul( [tr.translate(0, 0.21, 0), tr.scale(0.005, 0.08, 1)]) raya1.childs += [raya] raya2 = sg.SceneGraphNode('raya2') raya2.transform = tr.matmul([ tr.translate(0.206, 0, 0), tr.rotationZ(1.58), tr.scale(0.005, 0.08, 1) ]) raya2.childs += [raya] raya3 = sg.SceneGraphNode('raya3') raya3.transform = tr.matmul([ tr.translate(-0.206, 0, 0), tr.rotationZ(1.58), tr.scale(0.005, 0.08, 1) ]) raya3.childs += [raya] raya4 = sg.SceneGraphNode('raya4') raya4.transform = tr.matmul([ tr.translate(-0.15, 0.15, 0), tr.rotationZ(0.5), tr.scale(0.005, 0.08, 1) ]) raya4.childs += [raya] raya5 = sg.SceneGraphNode('raya5') raya5.transform = tr.matmul([ tr.translate(0.15, 0.15, 0), tr.rotationZ(-0.5), tr.scale(0.005, 0.08, 1) ]) raya5.childs += [raya] raya6 = sg.SceneGraphNode('raya6') raya6.transform = tr.matmul([ tr.translate(0.15, -0.15, 0), tr.rotationZ(0.5), tr.scale(0.005, 0.08, 1) ]) raya6.childs += [raya] raya7 = sg.SceneGraphNode('raya7') raya7.transform = tr.matmul([ tr.translate(-0.15, -0.15, 0), tr.rotationZ(-0.5), tr.scale(0.005, 0.08, 1) ]) raya7.childs += [raya] # Ensamblamos el mono rev = sg.SceneGraphNode('rev') rev.transform = tr.matmul( [tr.translate(-0.25, -0.7, 0), tr.scale(0.7, 1, 1)]) rev.childs += [ q1vel, q2vel, q3vel, q4vel, centro, raya1, raya2, raya3, raya4, raya5, raya6, raya7 ] translate_rev = sg.SceneGraphNode('revTR') translate_rev.childs += [rev] self.model = rev self.pos = 0
zoom += 0.05 elif glfw.get_key(window, glfw.KEY_DOWN) == glfw.PRESS: if zoom > 0.4: zoom -= 0.05 # Zoom transformations scaledSurfaceA.transform = tr.uniformScale(zoom) scaledSurfaceB.transform = tr.uniformScale(zoom) scaledSurfaceC.transform = tr.uniformScale(zoom) scaledBorder.transform = tr.uniformScale(zoom) # Fish transformations for i in range(len(fishesA)): fishesA[i].transform = tr.matmul([tr.uniformScale(zoom), tr.translate(pointsA[nas[i]][1] - 20, pointsA[nas[i]][0] - 10, pointsA[nas[i]][2] - 10), tr.rotationZ(randomRotationA[i])]) tailRotationA = sg.findNode(fishesA[i], 'tailRotation') tailRotationA.transform = tr.rotationZ(rotation) for i in range(len(fishesB)): fishesB[i].transform = tr.matmul([tr.uniformScale(zoom), tr.translate(pointsB[nbs[i]][1] - 20, pointsB[nbs[i]][0] - 10, pointsB[nbs[i]][2] - 10), tr.rotationZ(randomRotationB[i])]) tailRotationB = sg.findNode(fishesB[i], 'tailRotation') tailRotationB.transform = tr.rotationZ(rotation) for i in range(len(fishesC)): fishesC[i].transform = tr.matmul([tr.uniformScale(zoom), tr.translate(pointsC[ncs[i]][1] - 20, pointsC[ncs[i]][0] - 10, pointsC[ncs[i]][2] - 10), tr.rotationZ(randomRotationC[i])]) tailRotationC = sg.findNode(fishesC[i], 'tailRotation')
def update(self, time): # Method to update fin angle # time - Current time theta = np.cos(self.rotFrec * time + self.phase) self.fin_rot.transform = tr.rotationZ(theta)
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()
# Using GLFW to check for input events glfw.poll_events() # Filling or not the shapes depending on the controller state if controller.fillPolygon: glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) else: glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) # Clearing the screen in both, color and depth glClear(GL_COLOR_BUFFER_BIT) # theta is modified an amount proportional to the time spent in a loop iteration if controller.rotate: controller.theta += dt # Create transform matrix transform = tr.matmul([ tr.rotationZ(controller.theta), tr.translate(controller.x, controller.y, 0.0) ]) # Drawing the Quad with the given transformation drawShape(shaderProgram, gpuQuadBlack, transform) # Once the render is done, buffers are swapped, showing only the complete scene. glfw.swap_buffers(window) glfw.terminate()
# Telling OpenGL to use our shader program glUseProgram(mvcPipeline.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) # Creating shapes on GPU memory gpuAxis = es.toGPUShape(bs.createAxis(7)) redCarNode = createCar(1,0,0) blueCarNode = createCar(0,0,1) blueCarNode.transform = np.matmul(tr.rotationZ(-np.pi/4), tr.translate(3.0,0,0.5)) # Using the same view and projection matrices in the whole application projection = tr.perspective(45, float(width)/float(height), 0.1, 100) glUniformMatrix4fv(glGetUniformLocation(mvcPipeline.shaderProgram, "projection"), 1, GL_TRUE, projection) view = tr.lookAt( np.array([5,5,7]), np.array([0,0,0]), np.array([0,0,1]) ) glUniformMatrix4fv(glGetUniformLocation(mvcPipeline.shaderProgram, "view"), 1, GL_TRUE, view) while not glfw.window_should_close(window): # Using GLFW to check for input events glfw.poll_events()