示例#1
0
    def get_view(self):
        """
        Get view matrix.

        :return:
        """
        return _tr2.lookAt(
            _np.array([self._pos.get_x(), self._pos.get_y(), self._pos.get_z()]),
            _np.array([self._center.get_x(), self._center.get_y(), self._center.get_z()]),
            _np.array([self._up.get_x(), self._up.get_y(), self._up.get_z()])
        )
示例#2
0
    def get_view(self):
        """
        Get view matrix.

        :return:
        """
        return _tr2.lookAt(
            _np.array([self._r * _sin(self._theta) * _cos(self._phi),
                       self._r * _sin(self._theta) * _sin(self._phi),
                       self._r * _cos(self._theta)]),
            _np.array([self._center.get_x(), self._center.get_y(), self._center.get_z()]),
            _np.array([self._up.get_x(), self._up.get_y(), self._up.get_z()])
        )
                                      -1.1, -1.2, -1.3, -1.4, -1.5, -1.6, -1.7, -1.8, -1.9, -2,
                                      -2.1, -2.2, -2.3,
                                     0.5, 0.6, 0.7, 0.8, 0.9, 1,
                                      1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2,
                                      2.1, 2.2, 2.3])
        tpose.move(rotation, size, translation1, translation2, translation3)
        tpose_list.append(tpose)

    controller.set_toggle(tpose, 'face')
    controller.set_toggle(axis, 'axis')

    # Creamos la camara y la proyección
    projection = tr2.ortho(-1, 1, -1, 1, 0.1, 100)
    view = tr2.lookAt(
        np.array([80, 10, 5]),  # Donde está parada la cámara
        np.array([0, 0, 0]),  # Donde estoy mirando
        np.array([0, 0, 1])  # Cual es vector UP
    )

    while not glfw.window_should_close(window):

        # Using GLFW to check for input events
        glfw.poll_events()

        # Filling or not the shapes depending on the controller state
        if controller.fill_polygon:
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
        else:
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

        # Clearing the screen in both, color and depth
        # Getting the time difference from the previous iteration
        t1 = glfw.get_time()
        dt = t1 - t0
        t0 = t1

        if (glfw.get_key(window, glfw.KEY_LEFT) == glfw.PRESS):
            camera_theta -= 2 * dt

        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)
示例#5
0
        t0 = t1

        if (glfw.get_key(window, glfw.KEY_LEFT) == glfw.PRESS):
            camera_theta -= 2 * dt

        if (glfw.get_key(window, glfw.KEY_RIGHT) == glfw.PRESS):
            camera_theta += 2 * dt

        # Setting up the view transform

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

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

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

        glUniformMatrix4fv(
            glGetUniformLocation(pipeline.shaderProgram, "view"), 1, GL_TRUE,
            view)

        # Setting up the projection transform

        if controller.projection == PROJECTION_ORTHOGRAPHIC:
            projection = tr2.ortho(-8, 8, -8, 8, 0.1, 100)

        elif controller.projection == PROJECTION_FRUSTUM:
            projection = tr2.frustum(-5, 5, -5, 5, 9, 100)

        elif controller.projection == PROJECTION_PERSPECTIVE:
            projection = tr2.perspective(60,
示例#6
0
    #projection = tr2.frustum(-1, 1,-1, 1, 10, 1000)
    projection = tr2.ortho(-1, 1, -1, 1, 0.1, 1000)

    while not glfw.window_should_close(window):
        # Using GLFW to check for input events
        glfw.poll_events()

        # Clearing the screen in both, color and depth
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        if (controller.fillPolygon):
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
        else:
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

        if controller.view == 1:
            view = tr2.lookAt(np.array([0, 9, 7]), np.array([0, 0, 0]),
                              np.array([0, 0, 1]))
        elif controller.view == 2:
            view = tr2.lookAt(np.array([8, -6, 3]), np.array([0, 0, 0]),
                              np.array([0, 0, 1]))
        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(
示例#7
0
    # 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()

        # 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)
示例#8
0
        projection = tr2.perspective(45,
                                     float(width) / float(height), 0.1, 100)
        glUniformMatrix4fv(
            glGetUniformLocation(mvcPipeline.shaderProgram, "projection"), 1,
            GL_TRUE, projection)

        if controller.starBroken:
            starNode = starCompleteNode
        else:
            starNode = starBrokenNode

        if not controller.free_camera:
            if controller.camera_number == 1:
                # static camera
                normal_view = tr2.lookAt(np.array([2, 2, -1]),
                                         np.array([0, 0, 0]),
                                         np.array([0, 0, 1]))
            elif controller.camera_number == 2:
                # static camera
                normal_view = tr2.lookAt(np.array([2, -2, 0]),
                                         np.array([0, 0, 0]),
                                         np.array([0, 0, 1]))
            elif controller.camera_number == 3:
                # static camera
                normal_view = tr2.lookAt(np.array([1, 1, 3]),
                                         np.array([0, 0, 0]),
                                         np.array([0, 0, 1]))
            else:
                # static camera
                normal_view = tr2.lookAt(np.array([-2, -2, 1]),
                                         np.array([0, 0, 0]),
示例#9
0
    # Creating shader programs for textures and for colores
    textureShaderProgram = es.SimpleTextureModelViewProjectionShaderProgram(
    )  # TEXTURAS
    colorShaderProgram = es.SimpleModelViewProjectionShaderProgram()  # COLORES

    # Setting up the clear screen color
    glClearColor(0.15, 0.15, 0.15, 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)

    # crear la camara y la proyeccion son usadas por el shader
    projection = tr2.ortho(-1, 1, -1, 1, 0.1, 100)  # volumen de visualizacion
    view = tr2.lookAt(  # hacia donde apunto y donde está la camara
        np.array([10, 10, 5]), np.array([0, 0, 0]), np.array([0, 0, 1]))

    tpose = Tpose('img/ricardo.png')
    axis = Axis()

    # Definimos las referencias cruzadas
    controller.set_tpose(tpose)

    while not glfw.window_should_close(window):
        # Using GLFW to check for input events
        glfw.poll_events()

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

        tpose.draw(colorShaderProgram, textureShaderProgram, projection, view)
示例#10
0
                            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
    phi = np.pi / 4
    a = 1
    j = 0
    while not glfw.window_should_close(window):

        glfw.poll_events()

        # Getting the time difference from the previous iteration
        t1 = glfw.get_time()
        dt = t1 - t0
        t0 = t1