Esempio n. 1
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
Esempio n. 2
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)
     ])
Esempio n. 4
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
Esempio 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
Esempio 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
Esempio 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
Esempio n. 8
0
    def translate(self, tx=0, ty=0, tz=0):
        """
        Translate model.

        :param tx:
        :param ty:
        :param tz:
        :return:
        """
        self._model = _tr.matmul([_tr.translate(tx, ty, tz), self._model])
Esempio 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.
Esempio 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
Esempio n. 11
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
Esempio 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
Esempio n. 13
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
Esempio n. 14
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
Esempio n. 15
0
 def draw(self, pipeline):
     glUseProgram(pipeline.shaderProgram)
     self.model.transform = tr2.translate(0.7 * self.pos_x,
                                          0.47 * self.pos_y, 0)
     sg.drawSceneGraphNode(self.model, pipeline, "transform")
Esempio n. 16
0
def crearbarco(image_filename_1, image_filename_2, image_filename_3):
    gpuBote = es.toGPUShape(cr.createBote(image_filename_1), GL_REPEAT,
                            GL_LINEAR)
    gpuMastil = es.toGPUShape(cr.createMastil(image_filename_1), GL_REPEAT,
                              GL_LINEAR)
    gpuVela = es.toGPUShape(cr.createVela(image_filename_2), GL_REPEAT,
                            GL_LINEAR)
    gpuFlag = es.toGPUShape(cr.createFlag(image_filename_3), GL_REPEAT,
                            GL_LINEAR)

    #instancia del bote
    bote = sg.SceneGraphNode("bote")
    bote.childs += [gpuBote]
    #instancia de flag
    flag = sg.SceneGraphNode("flag")
    flag.transform = tr2.uniformScale(0.5)
    flag.childs += [gpuFlag]

    flagTranslate = sg.SceneGraphNode("flagTranslate")
    flagTranslate.transform = tr2.translate(-3, 0, 2.5)
    flagTranslate.childs += [flag]
    #2 instancias de mastil
    frontMastil = sg.SceneGraphNode("frontMastil")
    frontMastil.transform = tr2.translate(1.2, 0, 0)
    frontMastil.childs += [gpuMastil]

    backMastil = sg.SceneGraphNode("backMastil")
    backMastil.transform = tr2.translate(-1.2, 0, 0)
    backMastil.childs += [gpuMastil]
    #2 instancias de velas
    frontVela = sg.SceneGraphNode("frontVela")
    frontVela.transform = tr2.translate(1.2, 0, 2.5)
    frontVela.childs += [gpuVela]

    backVela = sg.SceneGraphNode("backVela")
    backVela.transform = tr2.translate(-1.2, 0, 2.5)
    backVela.childs += [gpuVela]
    #instancia de cola
    cola = sg.SceneGraphNode("cola")
    cola.transform = tr2.uniformScale(0.5)
    cola.childs += [gpuMastil]
    colaTranslated = sg.SceneGraphNode("colaTranslated")
    colaTranslated.transform = tr2.translate(-2.5, 0, 1)
    colaTranslated.childs += [cola]

    #instacia del barco completo
    barco = sg.SceneGraphNode("barco")
    barco.childs += [bote]
    barco.childs += [frontMastil]
    barco.childs += [backMastil]
    barco.childs += [colaTranslated]
    barco.childs += [frontVela]
    barco.childs += [backVela]
    barco.childs += [flagTranslate]

    #barco rotado
    scaledBarco = sg.SceneGraphNode("scaledBarco")
    scaledBarco.transform = tr2.uniformScale(0.05)
    scaledBarco.childs += [barco]
    rotatedBarco = sg.SceneGraphNode("rotatedBarco")
    rotatedBarco.transform = tr2.rotationZ(3)
    rotatedBarco.childs += [scaledBarco]

    traslatedBarco = sg.SceneGraphNode("traslatedBarco")
    traslatedBarco.transform = tr2.translate(0.0, 0.0, 0.0)
    traslatedBarco.childs += [rotatedBarco]
    return traslatedBarco
Esempio n. 17
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
Esempio n. 18
0
    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(tr2.rotationZ(-np.pi / 4),
                                      tr2.translate(3.0, 0, 0.5))

    # Using the same view and projection matrices in the whole application
    projection = tr2.perspective(45, float(width) / float(height), 0.1, 100)
    glUniformMatrix4fv(
        glGetUniformLocation(mvcPipeline.shaderProgram, "projection"), 1,
        GL_TRUE, projection)

    view = tr2.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()
Esempio 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))
Esempio n. 20
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))
    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
Esempio n. 22
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
        if (glfw.get_key(window, glfw.KEY_RIGHT) == glfw.PRESS):
            camera_theta += 2 * dt

        camX = 10 * np.sin(camera_theta)
        camY = 10 * np.cos(camera_theta)

        view = tr2.lookAt(np.array([camX, camY, 5]), np.array([0, 0, 0]),
                          np.array([0, 0, 1]))

        axis = np.array([1, -1, 1])
        axis = axis / np.linalg.norm(axis)
        theta = glfw.get_time()

        model_rotation = tr2.rotationA(theta, axis)
        model_traslation = tr2.translate(0.2, 0, 0)

        projection = tr2.ortho(-1, 1, -1, 1, 0.1, 100)

        # 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 | GL_DEPTH_BUFFER_BIT)

        if controller.mode == SH_TRANSFORM:
            # Total transformation is computed in the CPU
Esempio n. 24
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()
Esempio n. 25
0
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        # 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)

        if controller.showAxis:
            glUniformMatrix4fv(
                glGetUniformLocation(mvcPipeline.shaderProgram, "model"), 1,
                GL_TRUE, tr2.identity())
            mvcPipeline.drawShape(gpuAxis, GL_LINES)

        # Moving the spaceship
        shipNode1.transform = tr2.translate(x + 0.8, y + 0.8, 0)
        shipNode1.transform = np.matmul(
            shipNode1.transform, tr2.rotationZ(glfw.get_time() + np.pi / 2))

        shipNode2.transform = tr2.translate(-x + 2, y - 1, 1.5)
        shipNode2.transform = np.matmul(
            shipNode2.transform, tr2.rotationZ(-glfw.get_time() + np.pi / 2))

        # Drawing the scene
        glUseProgram(textureShaderProgram.shaderProgram)
        glUniformMatrix4fv(
            glGetUniformLocation(textureShaderProgram.shaderProgram,
                                 "projection"), 1, GL_TRUE, projection)
        glUniformMatrix4fv(
            glGetUniformLocation(textureShaderProgram.shaderProgram, "view"),
            1, GL_TRUE, normal_view)
Esempio n. 26
0
            glGetUniformLocation(pipeline.shaderProgram, "projection"), 1,
            GL_TRUE, projection)

        # Clearing the screen in both, color and depth
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        # 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)

        # Drawing shapes with different model transformations
        glUniformMatrix4fv(
            glGetUniformLocation(pipeline.shaderProgram, "model"), 1, GL_TRUE,
            tr2.translate(5, 0, 0))
        pipeline.drawShape(gpuRedCube)
        glUniformMatrix4fv(
            glGetUniformLocation(pipeline.shaderProgram, "model"), 1, GL_TRUE,
            tr2.translate(-5, 0, 0))
        pipeline.drawShape(gpuGreenCube)

        glUniformMatrix4fv(
            glGetUniformLocation(pipeline.shaderProgram, "model"), 1, GL_TRUE,
            tr2.translate(0, 5, 0))
        pipeline.drawShape(gpuBlueCube)
        glUniformMatrix4fv(
            glGetUniformLocation(pipeline.shaderProgram, "model"), 1, GL_TRUE,
            tr2.translate(0, -5, 0))
        pipeline.drawShape(gpuYellowCube)
Esempio n. 27
0
    glClearColor(1, 1, 1, 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(252 / 255, 246 / 255, 246 / 255, 1, 0, 0,
                           controller.lights)
    blueCarNode = createCar(252 / 255, 246 / 255, 246 / 255, 0, 76 / 255,
                            153 / 255, False)
    groundNode = createGround("pasto.jpg", 0)
    ground1Node = createGround("cielo.jpg", 2)
    blueCarNode.transform = np.matmul(tr2.rotationZ(-np.pi / 4),
                                      tr2.translate(5, 0, 5))
    baseNode = createEdificio()
    ambienteNode = createAmbiente("textura1.jpg", 1, 0, 1, np.pi / 2)
    ambiente1Node = createAmbiente('textura1.jpg', -1, 0, 1, np.pi / 2)
    ambiente2Node = createAmbiente('textura1.jpg', 0, 1, 1, 0)
    ambiente3Node = createAmbiente('textura1.jpg', 0, -1, 1, 0)

    # Define radius of the circumference
    r = 0.7

    # lookAt of normal camera
    normal_view = tr2.lookAt(np.array([2, 2, 3]), np.array([0, 0, 0]),
                             np.array([0, 0, 1]))

    t0 = glfw.get_time()
    theta = np.pi / 4