Пример #1
0
def create_color_plane_from_curve(_curve, triangulate, r, g, b, center=None):
    """
    Creates a plane from a curve and a center.

    :param _curve: Curve vertex list
    :param triangulate: Create plane from curve triangulation
    :param center: Center position
    :param r: Red color
    :param g: Green color
    :param b: Blue color
    :return: Merged shape
    :rtype: AdvancedGPUShape
    """
    shapes = []

    # Use delaunay triangulation
    if triangulate:
        k = []
        for i in _curve:
            k.append((i[0], i[1]))
        tri = earclip(k)
        for i in tri:
            x1, y1 = i[0]
            x2, y2 = i[1]
            x3, y3 = i[2]
            shape = bs.create_triangle_color((x1, y1, 0), (x2, y2, 0),
                                             (x3, y3, 0), r, g, b)
            shapes.append(es.to_gpu_shape(shape))
    else:
        if center is None:
            center = _curve[0]
        for i in range(0, len(_curve) - 1):
            x1, y1 = _curve[i]
            x2, y2 = _curve[(i + 1) % len(_curve)]
            c1, c2 = center
            shape = bs.create_triangle_color((x1, y1, 0), (x2, y2, 0),
                                             (c1, c2, 0), r, g, b)
            shapes.append(es.to_gpu_shape(shape))
    return AdvancedGPUShape(shapes)
Пример #2
0
    glClearColor(0.25, 0.25, 0.25, 1.0)

    # Enabling transparencies
    glEnable(GL_BLEND)
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

    # Creating shapes on GPU memory
    gpuBoo = es.to_gpu_shape(
        shapes.create_texture_quad('example_data/boo.png'), GL_REPEAT,
        GL_NEAREST)
    gpuQuestionBox = es.to_gpu_shape(
        shapes.create_texture_quad('example_data/question_box.png', 10, 1),
        GL_REPEAT, GL_NEAREST)

    # Create objets
    obj_boo = AdvancedGPUShape(gpuBoo, shader=pipeline)
    obj_question = AdvancedGPUShape(gpuQuestionBox, shader=pipeline)

    # Apply object transform
    obj_question.scale(sx=-2, sy=0.2)
    obj_question.translate(ty=-0.8)

    # Mainloop
    while not glfw.window_should_close(window):

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

        # OpenGL polygon mode
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
Пример #3
0
    glfw.set_key_callback(window, on_key)

    # Creating shader programs for textures and for colores
    colorShaderProgram = es.SimpleModelViewProjectionShaderProgram()
    phongPipeline = es.SimplePhongShaderProgram()

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

    # Create models
    gpuAxis = es.to_gpu_shape(shapes.create_axis(1))
    obj_axis = AdvancedGPUShape(gpuAxis, shader=colorShaderProgram)

    # Create cilynder, the objective is create many cuads from the bottom, top and
    # mantle. The cilynder is parametrized using an angle theta, a radius r and
    # the height
    h = 1
    r = 0.25

    # Latitude and longitude of the cylinder, latitude subdivides theta, longitude
    # subdivides h
    lat = 20
    lon = 20

    # Angle step
    dang = 2 * np.pi / lat
Пример #4
0
    # 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)

    # Creating shapes on GPU memory
    gpuTextureCube = es.to_gpu_shape(
        shapes.create_texture_cube('example_data/bricks.jpg'), GL_REPEAT,
        GL_LINEAR)
    gpuAxis = es.to_gpu_shape(shapes.create_axis(100))

    # Create objects
    obj_cube = AdvancedGPUShape(gpuTextureCube, shader=textureShaderProgram)
    obj_axis = AdvancedGPUShape(gpuAxis,
                                shader=colorShaderProgram,
                                mode=GL_LINES)

    # Create projection and view matrix
    projection = tr.ortho(-1, 1, -1, 1, 0.1, 100)
    view = tr.look_at(np.array([10, 10, 5]), np.array([0, 0, 0]),
                      np.array([0, 0, 1]))

    # Mainloop
    while not glfw.window_should_close(window):

        # Using GLFW to check for input events
        glfw.poll_events()
Пример #5
0
    glfw.set_key_callback(window, on_key)

    # Creating shader programs for textures and for colores
    phongPipeline = es.SimplePhongShaderProgram()
    colorShaderProgram = es.SimpleModelViewProjectionShaderProgram()

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

    # Create models
    gpuAxis = es.to_gpu_shape(shapes.create_axis(1))
    obj_axis = AdvancedGPUShape(gpuAxis, shader=colorShaderProgram)

    # Create the grid of the system
    vertex_grid = []
    nx = 40
    ny = 40
    zlim = [0, 0]

    for i in range(nx):  # x
        for j in range(ny):  # y
            xp = -1 + 2 / (nx - 1) * j
            yp = -1 + 2 / (ny - 1) * i
            zp = f(xp, yp, 4)  # Function number 4
            zlim = [min(zp, zlim[0]), max(zp, zlim[1])]
            vertex_grid.append([xp, yp, zp])
Пример #6
0
    # Connecting the callback function 'on_key' to handle keyboard events
    glfw.set_key_callback(window, on_key)

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

    # Create shader
    colorShaderProgram = es.SimpleTransformShaderProgram()

    # Creating shapes on GPU memory
    gpuCube = es.to_gpu_shape(shapes.create_rainbow_cube())
    cube = AdvancedGPUShape(gpuCube, shader=colorShaderProgram)

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

        # Clearing the screen in both, color and depth
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
Пример #7
0
    glfw.set_scroll_callback(window, scroll_callback)

    # Create shader
    basicShader = es.SimpleTransformShaderProgram()

    # Setting up the clear screen color
    glClearColor(0.15, 0.15, 0.15, 1.0)

    # Creating shapes on GPU memory
    blueQuad = shapes.create_color_quad(0, 0, 1)
    redQuad = shapes.create_color_quad(1, 0, 0)
    yellowQuad = shapes.create_color_quad(1, 1, 0)
    greenQuad = shapes.create_color_quad(0, 1, 0)

    # Create objects
    obj_quad_blue = AdvancedGPUShape(es.to_gpu_shape(blueQuad),
                                     shader=basicShader)
    obj_quad_red = AdvancedGPUShape(es.to_gpu_shape(redQuad),
                                    shader=basicShader)
    obj_quad_yellow = AdvancedGPUShape(es.to_gpu_shape(yellowQuad),
                                       shader=basicShader)
    obj_quad_green = AdvancedGPUShape(es.to_gpu_shape(greenQuad),
                                      shader=basicShader)

    # Apply permanent transforms
    obj_quad_red.translate(tx=0.5)
    obj_quad_red.uniform_scale(0.5)

    # Polyfon fill mode
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

    # Get time
Пример #8
0
    glfw.set_key_callback(window, on_key)

    # Creating shader programs for textures and for colores
    textureShaderProgram = es.SimpleTextureModelViewProjectionShaderProgram()
    colorShaderProgram = es.SimpleModelViewProjectionShaderProgram()

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

    # Create models
    gpuAxis = es.to_gpu_shape(bs.create_axis(1))
    obj_axis = AdvancedGPUShape(gpuAxis, shader=colorShaderProgram)

    # Create one side of the wall
    vertices = [[1, 0], [0.9, 0.4], [0.5, 0.5], [0, 0.5]]
    curve = catrom.get_spline_fixed(vertices, 10)

    obj_planeL = create_color_plane_from_curve(curve,
                                               False,
                                               0.6,
                                               0.6,
                                               0.6,
                                               center=(0, 0))
    obj_planeL.uniform_scale(1.1)
    obj_planeL.rotation_x(np.pi / 2)
    obj_planeL.rotation_z(-np.pi / 2)
    obj_planeL.translate(0.5, 0, 0)