Beispiel #1
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)
Beispiel #2
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)]))
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
Beispiel #4
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)]))
Beispiel #5
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
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
Beispiel #7
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 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
Beispiel #9
0
    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
Beispiel #10
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)])
Beispiel #11
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
Beispiel #12
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
Beispiel #13
0
    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
Beispiel #14
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])
def crearBosque(N):

    # Primero escalamos el arbol 
    escalarArbol = sg.SceneGraphNode("escalarArbol")
    escalarArbol.transform = tr.uniformScale(0.5)
    escalarArbol.childs += [crearArbol()]

    bosque = sg.SceneGraphNode("bosque")

    baseName = "arbol"
    for i in range(-N, N+1):
        newNode = sg.SceneGraphNode(baseName + str(i))
        newNode.transform = tr.translate(0.3 * i, 0, 0)
        newNode.childs += [escalarArbol]

        bosque.childs += [newNode] #Se añade la nueva fila de arboles 


    bosqueComp = sg.SceneGraphNode("bosqueComp") #Creamos un bosque con las filas de arboles antes creadas 

    baseName = "fila"    

    for i in range(-5,3): #el objetivo de este for es multiplicar las filas de arboles para crear un bosque 

        newNode = sg.SceneGraphNode(baseName + str(i))
        newNode.transform = tr.translate(0.23*(-1)**i,-0.1*i , 0)
        newNode.childs += [bosque]


        bosqueComp.childs += [newNode]

    return bosqueComp
Beispiel #16
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)
     ])
Beispiel #17
0
    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]
Beispiel #18
0
 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 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 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
Beispiel #21
0
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()
Beispiel #22
0
def createCar():

    # Cheating a single wheel
    wheel = sg.SceneGraphNode("wheel")
    wheel.transform = tr.uniformScale(0.2)
    wheel.childs += [createQuad(0, 0, 0)]

    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.3, 0)
    frontWheel.childs += [wheelRotation]

    backWheel = sg.SceneGraphNode("backWheel")
    backWheel.transform = tr.translate(-0.3, -0.3, 0)
    backWheel.childs += [wheelRotation]

    # Creating the chasis of the car
    chasis = sg.SceneGraphNode("chasis")
    chasis.transform = tr.scale(1, 0.5, 1)
    chasis.childs += [createQuad(1, 0, 0)]

    car = sg.SceneGraphNode("car")
    car.childs += [chasis]
    car.childs += [frontWheel]
    car.childs += [backWheel]

    traslatedCar = sg.SceneGraphNode("traslatedCar")
    traslatedCar.transform = tr.translate(0, 0.3, 0)
    traslatedCar.childs += [car]

    return traslatedCar
Beispiel #23
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)])
Beispiel #24
0
def create_shot(r, g, b):
    # r,g,b - Red, green and blue values of the shot color
    gpuShot = es.toGPUShape(bs.createColorQuad(r, g, b))

    shot = sg.SceneGraphNode("shot")
    shot.transform = tr.uniformScale(0.02)
    shot.childs = [gpuShot]

    return shot
Beispiel #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
Beispiel #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  
Beispiel #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 = []
Beispiel #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
Beispiel #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")
Beispiel #30
0
def createGameOver(victory=False):

    image = "victory_texture.png" if victory else "game_over_texture.png"
    textureShape = es.toGPUShape(bs.createTextureQuad(image), GL_CLAMP_TO_EDGE,
                                 GL_LINEAR)

    scaledTexture = sg.SceneGraphNode("scaledTexture")
    scaledTexture.transform = tr.uniformScale(2)
    scaledTexture.childs += [textureShape]

    texture = sg.SceneGraphNode("texture")
    texture.childs += [scaledTexture]

    return texture