Esempio n. 1
0
int main(int argc, char* argv[])
{
    GLFWwindow* window;
    double t, dt_total, t_old;
    int width, height;

    glfwSetErrorCallback(error_callback);

    if (!glfwInit())
        exit(EXIT_FAILURE);

    window = glfwCreateWindow(640, 480, "Wave Simulation", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

    glfwSetKeyCallback(window, key_callback);
    glfwSetWindowSizeCallback(window, window_size_callback);
    glfwSetMouseButtonCallback(window, mouse_button_callback);
    glfwSetCursorPosCallback(window, cursor_position_callback);
    glfwSetScrollCallback(window, scroll_callback);

    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);

    glfwGetWindowSize(window, &width, &height);
    window_size_callback(window, width, height);

    // Initialize OpenGL
    init_opengl();

    // Initialize simulation
    init_vertices();
    init_grid();
    adjust_grid();

    // Initialize timer
    t_old = glfwGetTime() - 0.01;

    while (!glfwWindowShouldClose(window))
    {
        t = glfwGetTime();
        dt_total = t - t_old;
        t_old = t;

        // Safety - iterate if dt_total is too large
        while (dt_total > 0.f)
        {
            // Select iteration time step
            dt = dt_total > MAX_DELTA_T ? MAX_DELTA_T : dt_total;
            dt_total -= dt;

            // Calculate wave propagation
            calc_grid();
        }

        // Compute height of each vertex
        adjust_grid();

        // Draw wave grid to OpenGL display
        draw_scene(window);

        glfwPollEvents();
    }

    exit(EXIT_SUCCESS);
}
Esempio n. 2
0
int main(int argc, char* argv[])
{
    GLFWwindow window;
    double t, dt_total, t_old;

    if (!glfwInit())
    {
        fprintf(stderr, "GLFW initialization failed\n");
        exit(EXIT_FAILURE);
    }

    window = glfwOpenWindow(640, 480, GLFW_WINDOWED, "Wave Simulation", NULL);
    if (!window)
    {
        fprintf(stderr, "Could not open window\n");
        exit(EXIT_FAILURE);
    }

    glfwSwapInterval(1);

    // Keyboard handler
    glfwSetKeyCallback(key_callback);
    glfwSetInputMode(window, GLFW_KEY_REPEAT, GL_TRUE);

    // Window resize handler
    glfwSetWindowSizeCallback(window_resize_callback);
    glfwSetMouseButtonCallback(mouse_button_callback);
    glfwSetMousePosCallback(mouse_position_callback);
    glfwSetScrollCallback(scroll_callback);

    // Initialize OpenGL
    init_opengl();

    // Initialize simulation
    init_vertices();
    init_grid();
    adjust_grid();

    // Initialize timer
    t_old = glfwGetTime() - 0.01;

    while (running)
    {
        t = glfwGetTime();
        dt_total = t - t_old;
        t_old = t;

        // Safety - iterate if dt_total is too large
        while (dt_total > 0.f)
        {
            // Select iteration time step
            dt = dt_total > MAX_DELTA_T ? MAX_DELTA_T : dt_total;
            dt_total -= dt;

            // Calculate wave propagation
            calc_grid();
        }

        // Compute height of each vertex
        adjust_grid();

        // Draw wave grid to OpenGL display
        draw_scene();

        glfwPollEvents();

        // Still running?
        running = running && glfwIsWindow(window);
    }

    exit(EXIT_SUCCESS);
}
int main(int argc, char **argv) {
    if (argc > 2 || (argc == 2 && strcmp(argv[1], "print"))) {
        printf("I expect no command line argument or \"print\" as unique command line argument.\n");
        return EXIT_FAILURE;
    }
    if (!get_input()) {
        printf("Incorrect input.\n");
        return EXIT_FAILURE;
    }
    if (argc == 2) {
        printf("\\documentclass[10pt]{article}\n");
        printf("\\usepackage{tikz}\n");
        printf("\\usetikzlibrary{shapes.misc}\n");
        printf("\\usepackage[margin=0cm]{geometry}\n");
        printf("\\pagestyle{empty}\n");
        printf("\\tikzstyle{every node}=[cross out, draw, red]\n\n");
        printf("\\begin{document}\n\n");
        printf("\\vspace*{\\fill}\n");
        printf("\\begin{center}\n");
        printf("\\begin{tikzpicture}[x=0.5cm, y=-0.5cm, ultra thick, blue]\n");
        rebuild_grid();
        printf("%% Walls\n");
        draw_horizontal_lines();
        draw_vertical_lines();
        rebuild_grid();
        draw_pillars();
        rebuild_grid();
        trans_grid();
        looking_for_access_areas();
        looking_for_inner_points();
        looking_for_dead_ends();
        printf("%% Inner points in accessible cul-de-sacs\n");
        draw_cross();
        looking_for_one_way_paths();
        adjust_grid();
        printf("%% Entry-exit paths without intersections\n");
        draw_horizontal_dash();
        draw_vertical_dash();
        printf("\\end{tikzpicture}\n");
        printf("\\end{center}\n");
        printf("\\vspace*{\\fill}\n\n");
        printf("\\end{document}\n");
        return EXIT_SUCCESS;
    }
    rebuild_grid();
    int num_of_gates = looking_for_gates();
    if (num_of_gates == 0)
        printf("The maze has no gate.\n");
    if (num_of_gates == 1)
        printf("The maze has a single gate.\n");
    if (num_of_gates > 1)
        printf("The maze has %d gates.\n", num_of_gates);
    rebuild_grid();
    int num_of_walls = looking_for_walls();
    if (num_of_walls == 0)
        printf("The maze has no wall.\n");
    if (num_of_walls == 1)
        printf("The maze has walls that are all connected.\n");
    if (num_of_walls > 1)
        printf("The maze has %d sets of walls that are all connected.\n", num_of_walls);
    rebuild_grid();
    trans_grid();
    int num_of_accessible_areas = looking_for_access_areas();
    int num_of_inner_points = looking_for_inner_points();
    if (num_of_inner_points == 0)
        printf("The maze has no inaccessible inner point.\n");
    if (num_of_inner_points == 1)
        printf("The maze has a unique inaccessible inner point.\n");
    if (num_of_inner_points > 1)
        printf("The maze has %d inaccessible inner points.\n", num_of_inner_points);
    if (num_of_accessible_areas == 0)
        printf("The maze has no accessible area.\n");
    if (num_of_accessible_areas == 1)
        printf("The maze has a unique accessible area.\n");
    if (num_of_accessible_areas > 1)
        printf("The maze has %d accessible areas.\n", num_of_accessible_areas);
    int num_of_dead_ends = looking_for_dead_ends();
    if (num_of_dead_ends == 0)
        printf("The maze has no accessible cul-de-sac.\n");
    if (num_of_dead_ends == 1)
        printf("The maze has accessible cul-de-sacs that are all connected.\n");
    if (num_of_dead_ends > 1)
        printf("The maze has %d sets of accessible cul-de-sacs that are all connected.\n", num_of_dead_ends);
    int num_of_paths = looking_for_one_way_paths();
    if (num_of_paths == 0)
        printf("The maze has no entry-exit path with no intersection not to cul-de-sacs.\n");
    if (num_of_paths == 1)
        printf("The maze has a unique entry-exit path with no intersection not to cul-de-sacs.\n");
    if (num_of_paths > 1)
        printf("The maze has %d entry-exit paths with no intersections not to cul-de-sacs.\n", num_of_paths);    
}