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.º 2
0
    def rotationZ(self, theta=0):
        """
        Rotate model.

        :param theta:
        :return:
        """
        self._model = _tr.matmul([_tr.rotationZ(theta), self._model])
Exemplo n.º 3
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.º 4
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
Exemplo n.º 5
0
    # Telling OpenGL to use our shader program
    glUseProgram(mvcPipeline.shaderProgram)

    # Setting up the clear screen color
    glClearColor(0.85, 0.85, 0.85, 1.0)

    # As we work in 3D, we need to check which part is in front,
    # and which one is at the back
    glEnable(GL_DEPTH_TEST)

    # Creating shapes on GPU memory
    gpuAxis = es.toGPUShape(bs.createAxis(7))
    redCarNode = createCar(1, 0, 0)
    blueCarNode = createCar(0, 0, 1)

    blueCarNode.transform = np.matmul(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
Exemplo n.º 6
0
        # 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)

        # Box, Earth and deathstar