Exemplo n.º 1
0
def createTextureDeathStar(filename):
    gpuSphere = es.toGPUShape(bs.createTextureSphere(filename),
                              GL_MIRRORED_REPEAT, GL_NEAREST)
    gpuInside = es.toGPUShape(bs.createInsideSphere("textures/dsInside.jpg"),
                              GL_MIRRORED_REPEAT, GL_NEAREST)
    gpuCone = es.toGPUShape(bs.createTextureCone("textures/laser.png"),
                            GL_MIRRORED_REPEAT, GL_NEAREST)

    star_base = sg.SceneGraphNode("star_base")
    star_base.transform = tr2.scale(0.5, 0.5, 0.5)
    star_base.childs += [gpuSphere]

    star_inside = sg.SceneGraphNode("star_inside")
    star_inside.transform = tr2.scale(0.5, 0.5, 0.5)
    star_inside.childs += [gpuInside]

    star_aerial = sg.SceneGraphNode("star_aerial")
    star_aerial.transform = np.matmul(
        tr2.translate(0, -np.sin(3 * np.pi / 8) / 2,
                      np.cos(3 * np.pi / 8) / 2), tr2.rotationX(3 * np.pi / 8))
    star_aerial.transform = np.matmul(star_aerial.transform,
                                      tr2.scale(0.15, 0.15, 0.05))
    star_aerial.childs += [gpuCone]

    star = sg.SceneGraphNode("star")
    star.transform = tr2.rotationY(np.pi / 32)
    star.childs += [star_inside, star_base, star_aerial]

    return star
Exemplo n.º 2
0
def createCar(r, g, b):

    gpuBlackQuad = es.toGPUShape(bs.createColorCube(0, 0, 0))
    gpuChasisQuad = es.toGPUShape(bs.createColorCube(r, g, b))

    # Cheating a single wheel
    wheel = sg.SceneGraphNode("wheel")
    wheel.transform = tr2.scale(0.2, 0.8, 0.2)
    wheel.childs += [gpuBlackQuad]

    wheelRotation = sg.SceneGraphNode("wheelRotation")
    wheelRotation.childs += [wheel]

    # Instanciating 2 wheels, for the front and back parts
    frontWheel = sg.SceneGraphNode("frontWheel")
    frontWheel.transform = tr2.translate(0.3, 0, -0.3)
    frontWheel.childs += [wheelRotation]

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

    # Creating the chasis of the car
    chasis = sg.SceneGraphNode("chasis")
    chasis.transform = tr2.scale(1, 0.7, 0.5)
    chasis.childs += [gpuChasisQuad]

    # All pieces together
    car = sg.SceneGraphNode("car")
    car.childs += [chasis]
    car.childs += [frontWheel]
    car.childs += [backWheel]

    return car
Exemplo n.º 3
0
 def jump_right(self):
     if self.pos == 0:
         self.transmonkey = np.matmul(tr2.translate(0.7, -0.74, 0),
                                      tr2.scale(0.4, 0.4, 1))
         self.pos = 1
     elif self.pos == -1:
         self.transmonkey = np.matmul(tr2.translate(0, -0.74, 0),
                                      tr2.scale(0.4, 0.4, 1))
         self.pos = 0
     self.level += 1
 def move(self, rotation, size, translation1, translation2, translation3):
     self.face.transform = tr.matmul([
         tr.scale(size, size, size),
         tr.translate(translation1, translation2, translation3),
         tr.scale(0.3, 0.3, 0.3),
         tr.translate(0, 0, 2),
         tr.rotationZ(rotation)
     ])
     self.body.transform = tr.matmul([
         tr.scale(size, size, size),
         tr.translate(translation1, translation2, translation3),
         tr.rotationZ(rotation)
     ])
Exemplo n.º 5
0
 def __init__(self, texture):
     self.notice = es.toGPUShape(bs.createTextureQuad(texture), GL_REPEAT,
                                 GL_LINEAR)
     self.transnotice = np.matmul(tr2.translate(0, 0.4, 0),
                                  tr2.scale(-1, 1, 1))
     self.winner = False
     self.loser = False
Exemplo n.º 6
0
def createSpaceShip():
    gpuCenterShip = es.toGPUShape(
        bs.createTextureSphere("textures/ssCenter.jpg"), GL_MIRRORED_REPEAT,
        GL_NEAREST)
    gpuBlock = es.toGPUShape(bs.createTextureCube("textures/ssBlock.jpg"),
                             GL_REPEAT, GL_NEAREST)
    gpuPlane = es.toGPUShape(bs.createTextureHex("textures/ssWings.jpg"),
                             GL_REPEAT, GL_NEAREST)

    spaceShipCenter = sg.SceneGraphNode("spaceShipCenter")
    spaceShipCenter.transform = tr2.scale(0.1, 0.1, 0.1)
    spaceShipCenter.childs += [gpuCenterShip]

    spaceShipBlock = sg.SceneGraphNode("spaceShipBlock")
    spaceShipBlock.transform = tr2.scale(0.02, 0.4, 0.02)
    spaceShipBlock.childs += [gpuBlock]

    spaceShipWingL = sg.SceneGraphNode("spaceShipLeftWing")
    spaceShipWingL.transform = np.matmul(
        tr2.translate(0.02, -0.2, 0.02),
        np.matmul(tr2.rotationX(np.pi / 2), tr2.scale(0.3, 0.3, 0.3)))
    spaceShipWingL.childs += [gpuPlane]

    spaceShipWingR = sg.SceneGraphNode("spaceShipRightWing")
    spaceShipWingR.transform = np.matmul(
        tr2.translate(0.02, 0.2, 0.02),
        np.matmul(tr2.rotationX(np.pi / 2), tr2.scale(0.3, 0.3, 0.3)))
    spaceShipWingR.childs += [gpuPlane]

    spaceShip_rotated = sg.SceneGraphNode("spaceShip_rotated")
    spaceShip_rotated.transform = np.matmul(tr2.rotationZ(0),
                                            tr2.rotationY(np.pi / 2))
    spaceShip_rotated.childs += [
        spaceShipCenter, spaceShipBlock, spaceShipWingR, spaceShipWingL
    ]

    spaceShip_scaled = sg.SceneGraphNode("spaceShip_scaled")
    spaceShip_scaled.transform = tr2.scale(0.5, 0.5, 0.5)
    spaceShip_scaled.childs += [spaceShip_rotated]

    spaceShip = sg.SceneGraphNode("spaceShip")
    spaceShip.transform = tr2.translate(0, 0, 0)
    spaceShip.childs += [spaceShip_scaled]

    return spaceShip
Exemplo n.º 7
0
 def __init__(self, texture):
     self.banana = es.toGPUShape(bs.createTextureQuad(texture), GL_REPEAT,
                                 GL_LINEAR)
     self.pos_x = 0  #será la posición lógica donde se ubicará la banana, se indicará con posterioridad
     self.level = 0  #indica en que nivel partira la banana, se indicará con posterioridad
     self.transbanana = np.matmul(
         tr2.translate(0.7 * self.pos_x, 0.47 * self.level, 0),
         tr2.scale(0.3, 0.3, 1))
     self.set = False
Exemplo n.º 8
0
    def scale(self, sx=1, sy=1, sz=1):
        """
        Scale model.

        :param sx:
        :param sy:
        :param sz:
        :return:
        """
        self._model = _tr.matmul([_tr.scale(sx, sy, sz), self._model])
Exemplo n.º 9
0
 def __init__(self, texture1):
     self.monkey = es.toGPUShape(bs.createTextureQuad(texture1), GL_REPEAT,
                                 GL_LINEAR)
     self.transmonkey = np.matmul(tr2.translate(0, -0.74, 0),
                                  tr2.scale(0.4, 0.4, 1))
     self.pos = 0
     self.jump = False  #indicará si el monito esta saltando para poder dibujarlo con otra textura
     self.logic = False  #indica si la lógica del juego está activa o no
     self.winner = False  #indica si el jugador ganó o no
     self.level = 0  #indica en que nivel con respecto al suelo se encuentra el monito
     self.started = False  #indica que si el juego empezó o no. Empieza cuando el mono se sube a la primera plataforma.
Exemplo n.º 10
0
def createBox(filename):
    gpuCube = es.toGPUShape(bs.createTextureCube(filename), GL_MIRRORED_REPEAT,
                            GL_NEAREST)
    bgCube_scaled = sg.SceneGraphNode("bgCube_scaled")
    bgCube_scaled.transform = tr2.scale(9, 9, 9)
    bgCube_scaled.childs += [gpuCube]

    bgCube = sg.SceneGraphNode("bgCube_scaled")
    bgCube.transform = tr2.translate(0, 0, 0)
    bgCube.childs += [bgCube_scaled]

    return bgCube
Exemplo n.º 11
0
    def __init__(self):
        gpuBlackQuad = es.toGPUShape(bs.createColorQuad(0, 0, 0))

        plataform = sg.SceneGraphNode('plataform')
        plataform.transform = tr2.scale(0.5, 0.04, 1)
        plataform.childs += [gpuBlackQuad]

        plataform_tr = sg.SceneGraphNode('plataformTR')
        plataform_tr.childs += [plataform]

        self.model = plataform_tr
        self.pos_x = 0
        self.pos_y = -1
Exemplo n.º 12
0
def createEarth():
    gpuEarth_texture = es.toGPUShape(
        bs.createTextureQuad("textures/earth.png"), GL_REPEAT, GL_NEAREST)
    earth_scaled = sg.SceneGraphNode("earth_scaled")
    earth_scaled.transform = tr2.scale(0.5, 0.5, 0.5)
    earth_scaled.childs += [gpuEarth_texture]

    earth_rotated = sg.SceneGraphNode("earth_rotated_x")
    earth_rotated.transform = tr2.rotationX(np.pi / 2)
    earth_rotated.childs += [earth_scaled]

    earth = sg.SceneGraphNode("earth")
    earth.transform = tr2.translate(0.5, 4, 0.6)
    earth.childs += [earth_rotated]

    return earth
Exemplo n.º 13
0
def createGround(image, trans):
    gpuGround_texture = es.toGPUShape(bs.createTextureQuad(image), GL_REPEAT,
                                      GL_NEAREST)
    ground_scaled = sg.SceneGraphNode("ground_scaled")
    ground_scaled.transform = tr2.scale(2, 2, 2)
    ground_scaled.childs += [gpuGround_texture]

    ground_rotated = sg.SceneGraphNode("ground_rotated_x")
    ground_rotated.transform = tr2.rotationX(0)
    ground_rotated.childs += [ground_scaled]

    ground = sg.SceneGraphNode("ground")
    ground.transform = tr2.translate(0, 0, trans)
    ground.childs += [ground_rotated]

    return ground
Exemplo n.º 14
0
def createAmbiente(filename, x, y, z, rot):
    gpuAirport_texture = es.toGPUShape(bs.createTextureQuad(filename),
                                       GL_REPEAT, GL_LINEAR)
    ambiente_scaled = sg.SceneGraphNode("ambiente_scaled")
    ambiente_scaled.transform = tr2.scale(2, 2, 2)
    ambiente_scaled.childs += [gpuAirport_texture]

    ambiente_rotated = sg.SceneGraphNode("ambiente_rotated")
    ambiente_rotated.transform = np.matmul(tr2.rotationX(np.pi / 2),
                                           tr2.rotationY(rot))
    ambiente_rotated.childs += [ambiente_scaled]

    ambiente = sg.SceneGraphNode("ambiente")
    ambiente.transform = tr2.translate(x, y, z)
    ambiente.childs += [ambiente_rotated]

    return ambiente
Exemplo n.º 15
0
 def expand_arm(self):
     self.arm_large += 0.1
     sg.findNode(self.model,
                 'arm').transform = tr.scale(0.13, self.arm_large, 0.13)
Exemplo n.º 16
0
def createEdificio():

    gpuBase = es.toGPUShape(bs.createTextureCube("textura.jpg"), GL_REPEAT,
                            GL_NEAREST)
    gpuLados = es.toGPUShape(bs.createTextureCube("textura.jpg"), GL_REPEAT,
                             GL_NEAREST)
    gpuBase2 = es.toGPUShape(bs.createTextureCube("techo.jpg"), GL_REPEAT,
                             GL_NEAREST)
    gpuAntena = es.toGPUShape(bs.createTextureCube("metal.jpg"), GL_REPEAT,
                              GL_NEAREST)
    gpuAntena1 = es.toGPUShape(bs.createCilindro(0, 0, 0))

    base = sg.SceneGraphNode("base")
    base.transform = np.matmul(tr2.scale(0.8 / 2, 0.7 / 2, 0.1875 / 2),
                               tr2.translate(0, 0, 0.5))
    base.childs += [gpuBase]

    lados = sg.SceneGraphNode("lados")
    lados.transform = np.matmul(tr2.translate(0.15, 0, 0.2),
                                tr2.scale(0.0875 / 2, 0.468 / 2, 0.625 / 2))
    lados.childs += [gpuLados]

    lados1 = sg.SceneGraphNode("lados1")
    lados1.transform = np.matmul(tr2.translate(-0.15, 0, 0.2),
                                 tr2.scale(0.0875 / 2, 0.468 / 2, 0.625 / 2))
    lados1.childs += [gpuLados]

    base2 = sg.SceneGraphNode("base2")
    base2.transform = np.matmul(tr2.scale(0.495 / 2, 0.545 / 2, 0.645 / 2),
                                tr2.translate(0, 0, 0.7))
    base2.childs += [gpuBase]

    base3 = sg.SceneGraphNode("base3")
    base3.transform = np.matmul(tr2.scale(0.32 / 2, 0.32 / 2, 2 / 2),
                                tr2.translate(0, 0, 0.8))
    base3.childs += [gpuBase]

    base4 = sg.SceneGraphNode("base4")
    base4.transform = np.matmul(tr2.scale(0.25 / 2, 0.25 / 2, 0.05 / 2),
                                tr2.translate(0, 0, 52.5))
    base4.childs += [gpuBase2]

    base5 = sg.SceneGraphNode("base4")
    base5.transform = np.matmul(tr2.scale(0.2 / 2, 0.2 / 2, 0.05 / 2),
                                tr2.translate(0, 0, 53.5))
    base5.childs += [gpuBase2]

    base6 = sg.SceneGraphNode("base4")
    base6.transform = np.matmul(tr2.scale(0.15 / 2, 0.15 / 2, 0.05 / 2),
                                tr2.translate(0, 0, 54.5))
    base6.childs += [gpuBase2]

    antena = sg.SceneGraphNode("antena")
    antena.transform = np.matmul(tr2.scale(0.015, 0.015, 0.3),
                                 tr2.translate(0, 0, 4.5))
    antena.childs += [gpuAntena]

    antena1 = sg.SceneGraphNode("antena1")
    antena1.transform = np.matmul(tr2.scale(0.01, 0.01, 0.3),
                                  tr2.translate(0, 0, 5))
    antena1.childs += [gpuAntena]

    antena2 = sg.SceneGraphNode("antena2")
    antena2.transform = np.matmul(tr2.scale(0.005, 0.005, 0.3),
                                  tr2.translate(0, 0, 6))
    antena2.childs += [gpuAntena]

    lados_1 = sg.SceneGraphNode("lado_1")
    lados_1.transform = np.matmul(tr2.scale(0.1 / 2, 0.5 / 2, 1.2 / 2),
                                  tr2.translate(1.55, 0, 1.15))
    lados_1.childs += [gpuLados]

    lados_2 = sg.SceneGraphNode("lado_2")
    lados_2.transform = np.matmul(tr2.scale(0.1 / 2, 0.5 / 2, 1.2 / 2),
                                  tr2.translate(-1.55, 0, 1.15))
    lados_2.childs += [gpuLados]

    lados_3 = sg.SceneGraphNode("lado_2")
    lados_3.transform = np.matmul(tr2.scale(0.09 / 2, 0.4 / 2, 0.4 / 2),
                                  tr2.translate(1.65, 0, 5.4))
    lados_3.childs += [gpuLados]

    lados_4 = sg.SceneGraphNode("lado_2")
    lados_4.transform = np.matmul(tr2.scale(0.09 / 2, 0.4 / 2, 0.4 / 2),
                                  tr2.translate(-1.65, 0, 5.4))
    lados_4.childs += [gpuLados]

    edificio = sg.SceneGraphNode("edificio")
    edificio.childs += [lados]
    edificio.childs += [lados1]
    edificio.childs += [base]
    edificio.childs += [base2]
    edificio.childs += [base3]
    edificio.childs += [base4]
    edificio.childs += [base5]
    edificio.childs += [base6]
    edificio.childs += [lados_1]
    edificio.childs += [lados_2]
    edificio.childs += [lados_3]
    edificio.childs += [lados_4]
    edificio.childs += [antena]
    edificio.childs += [antena1]
    edificio.childs += [antena2]

    return edificio
Exemplo n.º 17
0
    # Setting up the clear screen color
    glClearColor(0.25, 0.25, 0.25, 1.0)

    # Enabling transparencies
    glEnable(GL_BLEND)
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

    # Creating shapes on GPU memory
    gpuBoo = es.toGPUShape(bs.createTextureQuad("img/boo.png"), GL_REPEAT,
                           GL_NEAREST)
    gpuQuestionBox = es.toGPUShape(
        bs.createTextureQuad("img/question_box.png", 10, 1), GL_REPEAT,
        GL_NEAREST)

    questionBoxTransform = np.matmul(tr2.translate(0, -0.8, 0),
                                     tr2.scale(-2, 0.2, 1))

    while not glfw.window_should_close(window):
        # Using GLFW to check for input events
        glfw.poll_events()

        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 = glfw.get_time()
        tx = 0.7 * np.sin(0.5 * theta)
Exemplo n.º 18
0
 def move(self):
     self.transbanana = np.matmul(
         tr2.translate(0.7 * self.pos_x, 0.12 + 0.47 * self.level, 0),
         tr2.scale(0.3, 0.3, 1))
Exemplo n.º 19
0
 def move(self, c):
     self.transbackground = np.matmul(tr2.translate(0, 0.2 + c * -0.05, 0),
                                      tr2.scale(2, 2.5, 1))
Exemplo n.º 20
0
 def __init__(self, texture):
     self.background = es.toGPUShape(bs.createTextureQuad(texture),
                                     GL_REPEAT, GL_LINEAR)
     self.transbackground = np.matmul(tr2.translate(0, 0.2, 0),
                                      tr2.scale(2, 2.5, 1))
     self.level = 0  #indica en que nivel esta el monito, parte desde 0: suelo
    def __init__(self, texture_head):
        gpu_body = es.toGPUShape(bs.createColorCube(1, 0, 0))
        gpu_leg = es.toGPUShape(bs.createColorCube(0, 0, 1))
        gpu_skin = es.toGPUShape(bs.createColorCube(1, 1, 0))
        gpu_head = es.toGPUShape(bs.createTextureCube(texture_head), GL_REPEAT,
                                 GL_LINEAR)

        # Creamos el nucleo
        core = sg.SceneGraphNode('core')
        core.transform = tr.scale(0.32, 0.5, 0.6)
        core.childs += [gpu_body]

        # Piernas
        leg = sg.SceneGraphNode('leg')
        leg.transform = tr.scale(0.14, 0.14, 0.5)
        leg.childs += [gpu_leg]

        leg_left = sg.SceneGraphNode('leg_left')
        leg_left.transform = tr.translate(0, -0.17, -0.5)
        leg_left.childs += [leg]

        leg_right = sg.SceneGraphNode('leg_right')
        leg_right.transform = tr.translate(0, 0.17, -0.5)
        leg_right.childs += [leg]

        # Brazos
        arm = sg.SceneGraphNode('arm')
        arm.transform = tr.scale(0.13, 0.5, 0.13)
        arm.childs += [gpu_skin]

        arm_left = sg.SceneGraphNode('arm_left')
        arm_left.transform = tr.translate(0, -0.4, 0.23)
        arm_left.childs += [arm]

        arm_right = sg.SceneGraphNode('arm_right')
        arm_right.transform = tr.translate(0, 0.4, 0.23)
        arm_right.childs += [arm]

        # Cuello
        neck = sg.SceneGraphNode('neck')
        neck.transform = tr.matmul(
            [tr.scale(0.12, 0.12, 0.2),
             tr.translate(0, 0, 1.6)])
        neck.childs += [gpu_skin]

        # Cabeza
        head = sg.SceneGraphNode('head')
        head.transform = tr.matmul(
            [tr.scale(0.35, 0.35, 0.35),
             tr.translate(-0.08, 0, 1.75)])
        head.childs += [gpu_skin]

        body = sg.SceneGraphNode('body')
        body.childs += [
            arm_left, arm_right, leg_left, leg_right, core, neck, head
        ]

        face = sg.SceneGraphNode('face')
        face.transform = tr.matmul(
            [tr.scale(0.3, 0.3, 0.3),
             tr.translate(0, 0, 2)])
        face.childs += [gpu_head]

        body_tr = sg.SceneGraphNode('bodyTR')
        body_tr.childs += [body, face]

        self.face = face
        self.body = body

        self.model = body_tr
        self.show_face = True
Exemplo n.º 22
0
def createCar(r1, g1, b1, r2, g2, b2, isNormal):

    gpuBlackQuad = es.toGPUShape(bs.createCilindro(0, 0, 0), GL_REPEAT,
                                 GL_NEAREST)
    gpuChasisQuad_color1 = es.toGPUShape(bs.createTextureCube("militar.jpg"),
                                         GL_REPEAT, GL_NEAREST)
    gpuChasisQuad_color2 = es.toGPUShape(bs.createTextureCube("auto2.png"),
                                         GL_REPEAT, GL_NEAREST)
    gpuChasisPrism = es.toGPUShape(
        bs.createColorTriangularPrism(153 / 255, 204 / 255, 255 / 255))

    # Cheating a single rueda

    auto = sg.SceneGraphNode("auto")
    auto.transform = tr2.scale(0.2, 0.8, 0.2)
    auto.childs += [gpuBlackQuad]

    rueda = sg.SceneGraphNode("rueda")
    rueda.transform = tr2.scale(0.2 / 6, 0.8 / 6, 0.2 / 6)
    rueda.childs += [gpuBlackQuad]

    ruedaRotation = sg.SceneGraphNode("ruedaRotation")
    ruedaRotation.childs += [rueda]

    # Instanciating 2 ruedas, for the front and back parts
    frontrueda = sg.SceneGraphNode("frontrueda")
    frontrueda.transform = tr2.translate(0.05, 0, -0.45)
    frontrueda.childs += [ruedaRotation]

    backrueda = sg.SceneGraphNode("backrueda")
    backrueda.transform = tr2.translate(-0.05, 0, -0.45)
    backrueda.childs += [ruedaRotation]

    # Creating the bottom chasis of the car
    bot_chasis = sg.SceneGraphNode("bot_chasis")
    bot_chasis.transform = tr2.scale(1 / 5, 0.5 / 5, 0.5 / 6)
    bot_chasis.childs += [gpuChasisQuad_color1]

    # Moving bottom chasis
    moved_b_chasis = sg.SceneGraphNode("moved_b_chasis")
    moved_b_chasis.transform = tr2.translate(0, 0, -0.4)
    moved_b_chasis.childs += [bot_chasis]

    ventana = sg.SceneGraphNode("ventana")
    ventana.transform = np.matmul(tr2.scale(0.6 / 4, 0.3 / 4, 0.3 / 4),
                                  tr2.translate(0, 0, -4.5))
    ventana.childs += [gpuChasisQuad_color1]

    palito = sg.SceneGraphNode("palito")
    palito.transform = np.matmul(tr2.scale(0.2, 0.01, 0.01),
                                 tr2.translate(0.3, -0, -35),
                                 tr2.rotationY(np.pi / 6))
    palito.childs += [gpuChasisQuad_color1]

    # Joining chasis parts
    complete_chasis = sg.SceneGraphNode("complete_chasis")
    complete_chasis.childs += [moved_b_chasis]
    complete_chasis.childs += [ventana]
    complete_chasis.childs += [palito]

    # All pieces together
    car = sg.SceneGraphNode("car")
    car.childs += [complete_chasis]
    car.childs += [frontrueda]
    car.childs += [backrueda]

    return car