Exemplo n.º 1
0
def drawSceneGraphNode(node, pipeline, parentTransform=tr2.identity()):
    assert (isinstance(node, SceneGraphNode))

    # Composing the transformations through this path
    newTransform = np.matmul(parentTransform, node.transform)

    # If the child node is a leaf, it should be a GPUShape.
    # Hence, it can be drawn with drawShape
    if len(node.childs) == 1 and isinstance(node.childs[0], es.GPUShape):
        leaf = node.childs[0]
        glUniformMatrix4fv(
            glGetUniformLocation(pipeline.shaderProgram, "model"), 1, GL_TRUE,
            newTransform)
        pipeline.drawShape(leaf)

    # If the child node is not a leaf, it MUST be a SceneGraphNode,
    # so this draw function is called recursively
    else:
        for child in node.childs:
            drawSceneGraphNode(child, pipeline, newTransform)
Exemplo n.º 2
0
def findTransform(node, name, parentTransform=tr2.identity()):

    # The name was not found in this path
    if isinstance(node, es.GPUShape):
        return None

    newTransform = np.matmul(parentTransform, node.transform)

    # This is the requested node
    if node.name == name:
        return newTransform

    # All childs are checked for the requested name
    else:
        for child in node.childs:
            foundTransform = findTransform(child, name, newTransform)
            if isinstance(foundTransform, (np.ndarray, np.generic)):
                return foundTransform

    # No child of this node had the requested name
    return None
Exemplo n.º 3
0
 def __init__(self, name):
     self.name = name
     self.transform = tr.identity()
     self.childs = []
Exemplo n.º 4
0
            tr2.translate(0, 5, 0))
        pipeline.drawShape(gpuBlueCube)
        glUniformMatrix4fv(
            glGetUniformLocation(pipeline.shaderProgram, "model"), 1, GL_TRUE,
            tr2.translate(0, -5, 0))
        pipeline.drawShape(gpuYellowCube)

        glUniformMatrix4fv(
            glGetUniformLocation(pipeline.shaderProgram, "model"), 1, GL_TRUE,
            tr2.translate(0, 0, 5))
        pipeline.drawShape(gpuCyanCube)
        glUniformMatrix4fv(
            glGetUniformLocation(pipeline.shaderProgram, "model"), 1, GL_TRUE,
            tr2.translate(0, 0, -5))
        pipeline.drawShape(gpuPurpleCube)

        glUniformMatrix4fv(
            glGetUniformLocation(pipeline.shaderProgram, "model"), 1, GL_TRUE,
            tr2.identity())
        pipeline.drawShape(gpuRainbowCube)

        glUniformMatrix4fv(
            glGetUniformLocation(pipeline.shaderProgram, "model"), 1, GL_TRUE,
            tr2.identity())
        pipeline.drawShape(gpuAxis, GL_LINES)

        # Once the drawing is rendered, buffers are swap so an uncomplete drawing is never seen.
        glfw.swap_buffers(window)

    glfw.terminate()
                glGetUniformLocation(mvpPipeline.shaderProgram, "view"), 1,
                GL_TRUE, view)
            glUniformMatrix4fv(
                glGetUniformLocation(mvpPipeline.shaderProgram, "model"), 1,
                GL_TRUE, model)
            mvpPipeline.drawShape(gpuCube)

            glUniformMatrix4fv(
                glGetUniformLocation(mvpPipeline.shaderProgram, "projection"),
                1, GL_TRUE, projection)
            glUniformMatrix4fv(
                glGetUniformLocation(mvpPipeline.shaderProgram, "view"), 1,
                GL_TRUE, view)
            glUniformMatrix4fv(
                glGetUniformLocation(mvpPipeline.shaderProgram, "model"), 1,
                GL_TRUE, tr2.identity())
            mvpPipeline.drawShape(gpuAxis, GL_LINES)

        elif controller.mode == SH_MVP_TRANSPOSED:
            # Total transformation is computed in the GPU

            glUseProgram(mvpPipeline.shaderProgram)

            modelT = np.matmul(model_rotation.T, model_traslation.T)

            glUniformMatrix4fv(
                glGetUniformLocation(mvpPipeline.shaderProgram, "projection"),
                1, GL_FALSE, projection.T)
            glUniformMatrix4fv(
                glGetUniformLocation(mvpPipeline.shaderProgram, "view"), 1,
                GL_FALSE, view.T)
Exemplo n.º 6
0
        elif controller.view == 3:
            view = tr2.lookAt(np.array([10, 5, 1]), np.array([0, 0, 0]),
                              np.array([0, 0, 1]))
        elif controller.view == 4:
            view = tr2.lookAt(np.array([10, 5, 0]), np.array([0, 0, 0]),
                              np.array([0, 0, 1]))
        if controller.showAxis:
            glUseProgram(mvcPipeline.shaderProgram)
            glUniformMatrix4fv(
                glGetUniformLocation(mvcPipeline.shaderProgram, "projection"),
                1, GL_TRUE, projection)
            glUniformMatrix4fv(
                glGetUniformLocation(mvcPipeline.shaderProgram, "view"), 1,
                GL_TRUE, view)
            glUniformMatrix4fv(
                glGetUniformLocation(mvcPipeline.shaderProgram, "model"), 1,
                GL_TRUE, tr2.identity())
            mvcPipeline.drawShape(gpuAxis, GL_LINES)

        glUseProgram(textureShaderProgram.shaderProgram)
        glUniformMatrix4fv(
            glGetUniformLocation(textureShaderProgram.shaderProgram,
                                 "projection"), 1, GL_TRUE, projection)
        glUniformMatrix4fv(
            glGetUniformLocation(textureShaderProgram.shaderProgram, "view"),
            1, GL_TRUE, view)
        #sg.drawSceneGraphNode(mar, textureShaderProgram)
        sg.drawSceneGraphNode(barco, textureShaderProgram)
        #sg.drawSceneGraphNode(isla, mvcPipeline)
        glfw.swap_buffers(window)
    glfw.terminate()
Exemplo n.º 7
0
        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)
        ty = 0.2 * np.sin(5 * theta)

        # derivative of tx give us the direction
        dtx = 0.7 * 0.5 * np.cos(0.5 * theta)
        if dtx > 0:
            reflex = tr2.scale(-1, 1, 1)
        else:
            reflex = tr2.identity()

        # Drawing the shapes
        glUniformMatrix4fv(
            glGetUniformLocation(pipeline.shaderProgram, "transform"), 1,
            GL_TRUE,
            tr2.matmul(
                [tr2.translate(tx, ty, 0),
                 tr2.scale(0.5, 0.5, 1.0), reflex]))
        pipeline.drawShape(gpuBoo)

        glUniformMatrix4fv(
            glGetUniformLocation(pipeline.shaderProgram, "transform"), 1,
            GL_TRUE, questionBoxTransform)
        pipeline.drawShape(gpuQuestionBox)
Exemplo n.º 8
0
                                     float(width) / float(height), 0.1, 100)

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

        viewPos = np.array([camX, camY, 2])

        view = tr2.lookAt(viewPos, np.array([0, 0, 0]), np.array([0, 0, 1]))

        rotation_theta = glfw.get_time()

        axis = np.array([1, -1, 1])
        #axis = np.array([0,0,1])
        axis = axis / np.linalg.norm(axis)
        model = tr2.rotationA(rotation_theta, axis)
        model = tr2.identity()

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

        # The axis is drawn without lighting effects
        if controller.showAxis:
            glUseProgram(mvpPipeline.shaderProgram)
            glUniformMatrix4fv(
                glGetUniformLocation(mvpPipeline.shaderProgram, "projection"),