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

        # 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

        projection = tr.perspective(45, 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 = tr.look_at(
            viewPos,
            np.array([0, 0, 0]),
            np.array([0, 0, 1])
        )
        model = tr.identity()

        # Clearing the screen in both, color and depth
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
示例#2
0
        camX = 10 * np.sin(camera_theta)
        camY = 10 * np.cos(camera_theta)
        viewPos = np.array([camX, camY, 10])
        view = tr2.look_at(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,
                                         float(width) / float(height), 0.1,
                                         100)
        else:
            raise Exception()
        glUniformMatrix4fv(
            glGetUniformLocation(pipeline.shaderProgram, 'projection'), 1,
            GL_TRUE, projection)

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