示例#1
0
    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 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 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 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 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
示例#6
0
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 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
示例#8
0
    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)]))
示例#9
0
        def Movimiento (x,y):
            if x ==1:
                return tr.matmul([tr.translate(0,0,0),tr.translate(y*np.cos(t1*y)
            *np.sin(t1),y*np.cos(t1),0), tr.shearing(np.sin(t1)/50,np.cos(t1)/8,0,0,0,0)])

            elif x ==2 :
                return tr.matmul([tr.translate(np.cos(t1*y),
            y*np.sin(t1*y)*np.sin(t1*y),0),tr.uniformScale(0.5), tr.shearing(np.sin(t1)/8,np.cos(t1)/8,0,0,0,0)])

            elif x ==3 :
                return tr.matmul([tr.translate(y*np.sin(t1*y),np.cos(t1*y),0), tr.uniformScale(0.8), tr.shearing(np.sin(t1)/8,np.cos(t1)/8,0,0,0,0)])

            elif x == 4:
                return tr.matmul([tr.translate(1000000000000,100000000000000,0)])
示例#10
0
 def move_right(self):
     model = self.get_model()
     self.x2 = (self.x2 + 0.05)
     model.transform = tr.matmul([
         tr.uniformScale(self.get_zoom()),
         tr.translate(self.x2, self.y2, 0)
     ])
示例#11
0
def setTransform(n, theta, translation, scale, x):

    t = translation
    shearing = tr.shearing(0.1 * np.sin(theta), 0.1 * np.cos(theta), 0, 0, 0,
                           0)
    scale = tr.uniformScale(scale)
    theta = theta / 4

    if n == 1:
        tx = 0.7 * np.cos(theta / (2 * x))
        ty = 0.4 * np.cos(theta / x) + 0.3 * np.cos(theta)
    elif n == 2:
        tx = 0.4 * np.sin(theta) + 0.7 * np.cos(theta / 2)
        ty = 0.2 * np.sin(theta) * np.cos(theta / x) + 0.1 * np.sin(theta)
    elif n == 3:
        tx = 0.5 * np.cos(theta) * np.sin(theta /
                                          (2 * x)) + 0.4 * np.cos(theta)
        ty = 0.2 * np.cos(theta) * np.sin(theta / x) + 0.3 * np.cos(theta)
    elif n == 4:
        tx = 0.4 * np.cos(theta / x) * np.cos(theta)
        ty = 0.2 * np.cos(theta / (x))
    elif n == 5:
        tx = 0.4 * np.cos(theta / x) * np.sin(theta / x)
        ty = 0.2 * np.cos(theta / x) * np.sin(theta) * np.cos(theta)
    else:
        return tr.identity()

    tx = t[0] + tx
    ty = t[1] + ty
    pos = posInLimits(tx, ty)
    translation = tr.translate(pos[0], pos[1], 0)

    return tr.matmul([shearing, scale, translation])
示例#12
0
    def update(self, t):
        self.update_parent_x()
        self.update_parent_y()
        parent_x = self.get_parent_x()
        parent_y = self.get_parent_y()
        d = self.get_distance()
        w = self.get_velocity()
        new_x = d * sin(w * t)
        new_y = d * cos(w * t)
        self.set_x(new_x + parent_x)
        self.set_y(new_y + parent_y)
        satellites = self.get_satellites_objects()

        model = self.get_model()
        body = sg.findNode(model, 'body')
        body.transform = tr.translate(self.get_x(), self.get_y(), 0)
        orbit = sg.findNode(model, 'orbit')
        orbit.transform = tr.matmul([
            tr.uniformScale(self.get_zoom()),
            tr.translate(self.get_parent_x(), self.get_parent_y(), 0)
        ])

        for planeta in satellites:
            planeta.update(t)

        selection = sg.findNode(model, 'selection_circle')
        if self.selected:
            selection.transform = tr.uniformScale(self.radius + 0.009)
        else:
            selection.transform = tr.uniformScale(0)
示例#13
0
 def move_all(self):
     self.check_life()
     if not self.life_status:
         return
     self.move(self.movement_queue)
     movement = tr.identity()
     if self.next_direction == "W":
         movement = tr.translate(0, 1, 0)
         self.locationY += 1
     elif self.next_direction == "A":
         movement = tr.translate(-1, 0, 0)
         self.locationX += -1
     elif self.next_direction == "S":
         movement = tr.translate(0, -1, 0)
         self.locationY += -1
     elif self.next_direction == "D":
         movement = tr.translate(1, 0, 0)
         self.locationX += 1
     self.queue_movement(self.next_direction)
     self.last_direction = self.next_direction
     if self.check_apple():
         self.eat_apple()
     self.last_position = [self.locationX, self.locationY]
     self.occupied_positions = [self.last_position
                                ] + self.occupied_positions[1:]
     sg.findNode(self.model, "snake_head").transform = tr.matmul(
         [sg.findTransform(self.model, "snake_head"), movement])
示例#14
0
    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
示例#15
0
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
示例#16
0
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
示例#17
0
def generate_forest_trees_obj(locations,
                              fz,
                              trees_models,
                              leaves_models,
                              scale=0.5):
    # Generates an obj model with all the trees merged
    # locations - Matrix of (N,2) of the trees x,y coordinates
    # fz - Terrain height function fz(x,y)->z
    # trees_models - List of OBJ trees models
    # leaves_models - List of OBJ leaves models
    # scales - Scale factor for the trees
    scale_tr = tr.uniformScale(scale)
    forest_trees = []
    for i in range(len(locations)):
        x, y = locations[i]
        z = fz(x, y) - 0.03  # Lower to avoid floating trees
        M = tr.matmul([tr.translate(x, y, z), scale_tr])
        model = i % len(trees_models)
        moved_tree = trees_models[model].transform(M)
        moved_leaves = leaves_models[model].transform(M)
        moved_tree.join(moved_leaves)
        forest_trees.append(moved_tree)
    merged_trees_model = forest_trees[0]
    for i in range(1, len(forest_trees)):
        merged_trees_model.join(forest_trees[i])
    return merged_trees_model
示例#18
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
示例#19
0
    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
示例#20
0
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
示例#21
0
 def zoom_out(self):
     model = self.get_model()
     zoom = self.get_zoom()
     new_zoom = zoom - 0.1
     self.set_zoom(new_zoom)
     model.transform = tr.matmul(
         [tr.uniformScale(new_zoom),
          tr.translate(self.x2, self.y2, 0)])
示例#22
0
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
示例#23
0
def tapa():
    tapa = sg.SceneGraphNode("tapa")
    tapa.transform = tr.matmul([tr.scale(0.25, 2, 0), tr.translate(0.5, 0, 0)])
    tapa.childs += [
        createQuad(255 * 0.35, 255 * 0.35, 255 * 0.35, 255 * 0.35, 255 * 0.35,
                   255 * 0.35)
    ]
    return tapa
示例#24
0
    def Update(self, pipeline, delta, transform, isPaused):
        if self.isAnimated:
            anim_to_play = self.animations[
                self.current_anim]  #animation() actual
            owntransform = tr.matmul([
                transform,
                tr.scale(self.scale[0], self.scale[1], self.scale[2])
            ])  #escalamiento

            if len(anim_to_play.frames) == 1:
                #si la animacion contiene un solo frame, solo se dibuja este
                glUniformMatrix4fv(
                    glGetUniformLocation(pipeline.shaderProgram, "transform"),
                    1, GL_TRUE, owntransform)
                pipeline.drawShape(anim_to_play.frames[0])

            else:

                glUniformMatrix4fv(
                    glGetUniformLocation(pipeline.shaderProgram, "transform"),
                    1, GL_TRUE, owntransform)
                pipeline.drawShape(anim_to_play.frames[self.frame_counter])

                if not isPaused:

                    self.time_counter += delta

                    if self.time_counter > 1 / anim_to_play.fps:  #controlador de la velocidad de la animacion

                        #controlar si ya se animaron todos los frames
                        if self.play_counter >= anim_to_play.anim_length - 1:
                            self.canPlay = False
                            self.isFinished = True

                        #si quedan frames por animar o es un loop se actualizan los frames
                        if self.canPlay or anim_to_play.isLooped:
                            if anim_to_play.canRewind:
                                #si se puede invertir la animacion, los frames se actualizan segun su direccion
                                if self.isRewinding == False:
                                    self.frame_counter += 1
                                else:
                                    self.frame_counter -= 1

                                if self.frame_counter > len(
                                        anim_to_play.frames) - 1:
                                    self.isRewinding = True
                                    self.frame_counter -= 2
                                elif self.frame_counter < 0:
                                    self.isRewinding = False
                                    self.frame_counter += 2
                            else:
                                self.frame_counter = (self.frame_counter +
                                                      1) % len(
                                                          anim_to_play.frames)
                            self.play_counter += 1

                        self.time_counter = 0
示例#25
0
def create_explosion():
    # Ship explosion model
    r, g, b = (0.95, 0.4, 0.0)
    # Defining locations and colors for each vertex of the shape
    vertices = [
        #   positions        colors
        -0.5,
        -0.5,
        0.0,
        r,
        g,
        b,
        0.5,
        -0.5,
        0.0,
        r,
        g,
        b,
        0.0,
        0.5,
        0.0,
        r,
        g,
        b,
        0.0,
        -0.75,
        0.0,
        r,
        g,
        b,
        0.5,
        0.25,
        0.0,
        r,
        g,
        b,
        -0.5,
        0.25,
        0.0,
        r,
        g,
        b
    ]

    # Defining connections among vertices
    # We have a triangle every 3 indices specified
    indices = [0, 1, 2, 3, 4, 5]

    gpuExplosion = es.toGPUShape(bs.Shape(vertices, indices))

    explosion = sg.SceneGraphNode("explosionModel")
    explosion.transform = tr.matmul(
        [tr.translate(0.0, 0.02, 0.0),
         tr.uniformScale(0.15)])
    explosion.childs = [gpuExplosion]

    return explosion
示例#26
0
 def __init__(self, texture):
     self.texture = texture
     monop = es.toGPUShape(bs.createTextureQuad(self.texture, 1, 1), GL_REPEAT, GL_LINEAR)
     self.model = monop
     self.pos_x = 0
     self.pos_y = -0.7
     self.pos=-0.7
     monopTransform= tr.matmul([tr.translate(self.pos_x, self.pos_y, 0), tr.uniformScale(0.5)])
     self.tra = monopTransform
     self.winner = False #aun no gana
     self.loser = False #aun no pierde  
示例#27
0
    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 = []
示例#28
0
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
示例#29
0
def drawExplosions(time):

    global logic

    for explosion in logic.explosions:
        shape = explosion.shape
        spawnTime = explosion.spawnTime

        position = tr.translate(explosion.xPos, explosion.yPos, 0)
        scale = tr.uniformScale(0.2 * (spawnTime + 1 - time))

        shape.transform = tr.matmul([position, scale])
        sg.drawSceneGraphNode(shape, pipeline, "transform")
示例#30
0
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