/* Interior update for tranport step */
void trans_update_interior(mesh_t *mesh, mesh_t *mesh_old, int cur_y, int cur_x)
{
	cell_t *cur_cell, *cur_cell_old, *adj_cell_vert, *adj_cell_hor, *adj_cell_diag;
	double y_comp, x_comp;

	/* Gets the x and y components of the backwards in time vector for method */
	/* of characteristics */
	y_comp = trans_get_old_position(mesh_old, cur_y, cur_x, 1);
	x_comp = trans_get_old_position(mesh_old, cur_y, cur_x, 0);

	// if ((cur_y == 62) && (cur_x == 1))
	// 	printf("x: %d, y: %d, xcomp: %e, ycomp: %e\n", cur_x, cur_y, x_comp, y_comp );

	cur_cell = &mesh->cell[MESH_INDEX(cur_y, cur_x)];
	cur_cell_old = &mesh->cell[MESH_INDEX(cur_y, cur_x)];

	/* Gets the quadrant the foot is in */
	int quad = get_quadrant(y_comp, x_comp);

	/* Sets components to proportions of full cell */
	y_comp = fabs(y_comp / mesh->dim.h);
	x_comp = fabs(x_comp / mesh->dim.h);

	/* Selects the configuration of cells */
	assign_cells(mesh_old, &adj_cell_hor, &adj_cell_vert, &adj_cell_diag, cur_y, cur_x, quad);

	cur_cell->saturation = trans_get_average_sat(cur_cell_old, adj_cell_hor,
							adj_cell_vert, adj_cell_diag, y_comp, x_comp);
}
Exemplo n.º 2
0
int main( int argc, char **argv )
{
    if ( use_gui )
    {
        printf("init_sdl()\n");
        if ( init_sdl() ) return 1;

        printf("init_gl()\n");
        init_gl();
    }

    printf("init_fft()\n");
    if ( init_fft() ) return 1;

    if ( use_serial )
    {
        printf("init_serial()\n");
        if ( init_serial() ) use_serial = FALSE;
    }

    init_lights();
    init_table();

    while ( !done )
    {
        get_samples_do_fft();

        detect_beats();

        assign_lights();

        assign_cells();

        if ( use_gui )
        {
            if (handle_sdl_events()) return 1;
            draw_all();
        }

        if ( use_serial ) send_serial();

        usleep(5000);
    }

    return 0;
}
void trans_update_corner(mesh_t *mesh, mesh_t *mesh_old, int cur_y, int cur_x,
                    int boundary_side1, int boundary_side2)
{
	cell_t *cur_cell, *cur_cell_old, *adj_cell_vert, *adj_cell_hor, *adj_cell_diag;
	double y_comp, x_comp;

	/* Gets the x and y components of the backwards in time vector for method */
	/* of characteristics */
	y_comp = trans_get_old_position(mesh_old, cur_y, cur_x, 1);
	x_comp = trans_get_old_position(mesh_old, cur_y, cur_x, 0);

	cur_cell = &mesh->cell[MESH_INDEX(cur_y, cur_x)];
	cur_cell_old = &mesh->cell[MESH_INDEX(cur_y, cur_x)];

	/* Gets the quadrant the foot is in */
	int quad = get_quadrant(y_comp, x_comp);
	int corner_type = get_corner_config(boundary_side1, boundary_side2);

	/* Sets components to proportions of full cell */
	y_comp = fabs(y_comp / mesh->dim.h);
	x_comp = fabs(x_comp / mesh->dim.h);
	// printf("ycomp %e, xcomp %e\n", y_comp, x_comp);

	/* Selects the configuration of cells */
	switch (corner_type) {
		case 1:
			switch (quad) {
				case 1:
					dup_cell_corner(mesh, cur_cell_old, &adj_cell_hor, &adj_cell_vert,
								&adj_cell_diag);
					break;
				case 2:
					dup_cell_vert(mesh, cur_cell_old, &adj_cell_hor, &adj_cell_vert,
							  	&adj_cell_diag, cur_y, cur_x, 3);
					break;
				case 3:
					assign_cells(mesh_old, &adj_cell_hor, &adj_cell_vert,
						 		&adj_cell_diag, cur_y, cur_x, quad);
					break;
				default:
					dup_cell_hor(mesh, cur_cell_old, &adj_cell_hor, &adj_cell_vert,
					  			&adj_cell_diag, cur_y, cur_x, 2);
					break;
			}
			break;
		case 2:
			switch (quad) {
				case 1:
					dup_cell_vert(mesh, cur_cell_old, &adj_cell_hor, &adj_cell_vert,
						  		&adj_cell_diag, cur_y, cur_x, 1);
					break;
				case 2:
					dup_cell_corner(mesh, cur_cell_old, &adj_cell_hor, &adj_cell_vert,
								&adj_cell_diag);
					break;
				case 3:
					dup_cell_hor(mesh, cur_cell_old, &adj_cell_hor, &adj_cell_vert,
				  				&adj_cell_diag, cur_y, cur_x, 2);
					break;
				default:
					assign_cells(mesh_old, &adj_cell_hor, &adj_cell_vert,
								&adj_cell_diag, cur_y, cur_x, quad);
					break;
			}
			break;
		case 3:
			switch (quad) {
				case 1:
					assign_cells(mesh_old, &adj_cell_hor, &adj_cell_vert,
							&adj_cell_diag, cur_y, cur_x, quad);
					break;
				case 2:
					dup_cell_hor(mesh, cur_cell_old, &adj_cell_hor, &adj_cell_vert,
							&adj_cell_diag, cur_y, cur_x, 0);
					break;
				case 3:
					dup_cell_corner(mesh, cur_cell_old, &adj_cell_hor, &adj_cell_vert,
							&adj_cell_diag);
					break;
				default:
					dup_cell_vert(mesh, cur_cell_old, &adj_cell_hor, &adj_cell_vert,
							&adj_cell_diag, cur_y, cur_x, 1);
					break;
			}
			break;
		default:
			switch (quad) {
				case 1:
					dup_cell_hor(mesh, cur_cell_old, &adj_cell_hor, &adj_cell_vert,
							&adj_cell_diag, cur_y, cur_x, 0);
					break;
				case 2:
					assign_cells(mesh_old, &adj_cell_hor, &adj_cell_vert,
							&adj_cell_diag, cur_y, cur_x, quad);
					break;
				case 3:
					dup_cell_vert(mesh, cur_cell_old, &adj_cell_hor, &adj_cell_vert,
							&adj_cell_diag, cur_y, cur_x, 3);
					break;
				default:
					dup_cell_corner(mesh, cur_cell_old, &adj_cell_hor, &adj_cell_vert,
							&adj_cell_diag);
					break;
			}
	}

	cur_cell->saturation = trans_get_average_sat(cur_cell_old, adj_cell_hor,
							adj_cell_vert, adj_cell_diag, y_comp, x_comp);
	// printf("sat: %e\n", cur_cell->saturation);
}