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

        :param theta:
        :return:
        """
        self._model = _tr.matmul([_tr.rotationY(theta), self._model])
Exemplo n.º 3
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.º 4
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.º 5
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 red car and rotating its wheels
        redCarNode.transform = tr2.translate(3 * np.sin(glfw.get_time()), 0,
                                             0.5)
        redWheelRotationNode = sg.findNode(redCarNode, "wheelRotation")
        redWheelRotationNode.transform = tr2.rotationY(-10 * glfw.get_time())

        # Uncomment to print the red car position on every iteration
        #print(sg.findPosition(redCarNode, "car"))

        # Drawing the Car
        sg.drawSceneGraphNode(redCarNode, mvcPipeline)
        sg.drawSceneGraphNode(blueCarNode, mvcPipeline)

        # Once the render is done, buffers are swapped, showing only the complete scene.
        glfw.swap_buffers(window)

    glfw.terminate()
Exemplo n.º 6
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
Exemplo n.º 7
0
            glUniformMatrix4fv(
                glGetUniformLocation(mvcPipeline.shaderProgram, "model"), 1,
                GL_TRUE, tr2.identity())
            mvcPipeline.drawShape(gpuAxis, GL_LINES)

        pos = int(len(c1) * t1 / 4) % len(c1)

        phi1 = np.arctan2(c1[pos][1] - c1[pos - 1][1],
                          c1[pos][0] - c1[pos - 1][0])
        # Moving the red car and rotating its ruedas
        redCarNode.transform = np.matmul(
            tr2.translate(0, 0, 0.5), tr2.translate(c1[pos][0], c1[pos][1], 0))
        redCarNode.transform = np.matmul(redCarNode.transform,
                                         tr2.rotationZ(phi1))
        redruedaRotationNode = sg.findNode(redCarNode, "ruedaRotation")
        redruedaRotationNode.transform = tr2.rotationY(10 * glfw.get_time())

        # Drawing redCar using light shader
        glUseProgram(textureShaderProgram.shaderProgram)

        # Setting all uniform shader variables

        glUniformMatrix4fv(
            glGetUniformLocation(textureShaderProgram.shaderProgram,
                                 "projection"), 1, GL_TRUE, projection)
        glUniformMatrix4fv(
            glGetUniformLocation(textureShaderProgram.shaderProgram, "view"),
            1, GL_TRUE, normal_view)

        sg.drawSceneGraphNode(redCarNode, textureShaderProgram)