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()
        if (controller.fillPolygon):
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
        else:
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

        theta = 0.3 * np.sin(glfw.get_time())

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

        glUseProgram(pipeline.shaderProgram)
        # Drawing the shapes
        glUniformMatrix4fv(
            glGetUniformLocation(pipeline.shaderProgram, "transform"), 1,
            GL_TRUE,
            np.matmul(tr.shearing(0, theta, 0, 0, 0, 0), tr.uniformScale(1.5)))

        # Binding samplers to both texture units
        glUniform1i(glGetUniformLocation(pipeline.shaderProgram, "upTexture"),
                    0)
        glUniform1i(
            glGetUniformLocation(pipeline.shaderProgram, "downTexture"), 1)

        # Sending the mouse vertical location to our shader
        glUniform1f(glGetUniformLocation(pipeline.shaderProgram, "mousePosY"),
                    controller.mousePos[1])
        pipeline.drawCall(gpuShape)

        # Once the render is done, buffers are swapped, showing only the complete scene.
        glfw.swap_buffers(window)
Exemplo n.º 3
0
        # Rendering the rendered texture to the viewport as a simple quad
        #######################
        glBindFramebuffer(GL_FRAMEBUFFER, 0)
        glDisable(GL_DEPTH_TEST)
        glClearColor(0.85, 0.85, 0.85, 1.0)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        if (controller.fillTexture):
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
        else:
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

        glUseProgram(textureShaderProgram.shaderProgram)
        glUniformMatrix4fv(
            glGetUniformLocation(textureShaderProgram.shaderProgram,
                                 "transform"), 1, GL_TRUE,
            tr.matmul([
                tr.translate(0.3 * np.cos(theta), 0, 0),
                tr.shearing(0.3 * np.cos(theta), 0, 0, 0, 0, 0)
            ]))
        textureShaderProgram.drawCall(gpuQuad)

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

    # freeing GPU memory
    gpuRainbowCube.clear()
    gpuQuad.clear()

    glfw.terminate()
Exemplo n.º 4
0
                spiral.vertices[m], spiral.vertices[m + 1],
                spiral.vertices[m + 2], 1
            ]
            new_vert = tr.matmul([tr.scale(0.02, 0.02, 1), current_vert])
            spiral.vertices[m] = new_vert[0]
            spiral.vertices[m + 1] = new_vert[1]
            spiral.vertices[m + 2] = new_vert[2]
        GPUspiral = es.GPUShape().initBuffers()
        pipeline.setupVAO(GPUspiral)
        GPUspiral.fillBuffers(spiral.vertices, spiral.indices, GL_STREAM_DRAW)

        # Si el jugador esta infectado, aparece una espiral rotando encima de su modelo y se distoricona la vision
        if player.infected:
            for entity in entityList:
                entity.pos[0] += math.cos(t1) * delta * 0.2 * entity.pos[1]
            full_scene.transform = tr.shearing(
                math.cos(t1) * 0.2, 0, 0, 0, 0, 0)
            decoration_scene.transform = tr.shearing(
                math.cos(t1) * 0.2, 0, 0, 0, 0, 0)
            fullStoreNode.transform = tr.shearing(
                math.cos(t1) * 0.2, 0, 0, 0, 0, 0)
            glUseProgram(pipeline.shaderProgram)
            glUniformMatrix4fv(
                glGetUniformLocation(pipeline.shaderProgram, "transform"), 1,
                GL_TRUE,
                tr.matmul([
                    tr.translate(player.pos[0], player.pos[1] + 0.1, 0),
                    tr.rotationZ(t1)
                ]))
            pipeline.drawCall(GPUspiral, GL_LINE_STRIP)

        # Se quitan de la lista de entidades aquellas que salieron de la pantalla esta iteracion