void ft_detect_wall(t_glob *gl) { int x; x = 0; while (x < gl->s_x) { gl->camx = 2 * x / (double)gl->s_x - 1; ft_init_raycast(gl); ft_rayhandle(gl); dda(gl); handle_wall(gl); ft_verline(x, gl); x++; } gl->oldtime = gl->time; gl->time = clock(); gl->ftime = (gl->time - gl->oldtime) / CLOCKS_PER_SEC; gl->ms = gl->ftime * 5.0; gl->rs = gl->ftime * 3.0; ft_minimap(gl); ft_posmap(gl); mlx_put_image_to_window(gl->mlx, gl->win, gl->img, 0, 0); mlx_put_image_to_window(gl->mlx, gl->win, gl->minimap, 1170, 600); mlx_destroy_image(gl->mlx, gl->img); mlx_destroy_image(gl->mlx, gl->minimap); }
int grab_key5(int keycode, t_img *img) { if (keycode == 15) { set_plan(img); img->zoom = 1; img->flou = 0; img->nb_i = 50; clear_map(img); draw_map(img); mlx_put_image_to_window(img->mlx_ptr, img->win_ptr, img->img_ptr, 0, 0); } if (keycode == 69) { img->plan.x_a += img->plan.step_x * WIDTH / 4; img->plan.y_a += img->plan.step_y * HEIGHT / 4; img->plan.x_b -= img->plan.step_x * WIDTH / 4; img->plan.y_b -= img->plan.step_y * HEIGHT / 4; img->plan.step_x = (img->plan.x_b - img->plan.x_a) / WIDTH; img->plan.step_y = (img->plan.y_b - img->plan.y_a) / HEIGHT; clear_map(img); draw_map(img); mlx_put_image_to_window(img->mlx_ptr, img->win_ptr, img->img_ptr, 0, 0); } if (keycode == 3) img->flou = (img->flou) ? 0 : 1; return (0); }
int grab_key4(int keycode, t_img *img) { if (keycode == 78) { img->plan.x_a -= img->plan.step_x * WIDTH / 2; img->plan.y_a -= img->plan.step_y * HEIGHT / 2; img->plan.x_b += img->plan.step_x * WIDTH / 2; img->plan.y_b += img->plan.step_y * HEIGHT / 2; img->plan.step_x = (img->plan.x_b - img->plan.x_a) / WIDTH; img->plan.step_y = (img->plan.y_b - img->plan.y_a) / HEIGHT; clear_map(img); draw_map(img); mlx_put_image_to_window(img->mlx_ptr, img->win_ptr, img->img_ptr, 0, 0); } if (keycode == 9) { if (img->c_value == 0) img->c_value = 1; else if (img->c_value == 1) img->c_value = 0; clear_map(img); draw_map(img); mlx_put_image_to_window(img->mlx_ptr, img->win_ptr, img->img_ptr, 0, 0); } return (0); }
int print_loadbar(t_all *all, t_image *together, double minmax, time_t start) { static int last_pc = -1; static int last_time = -1; time_t elapsed; int pos; pos = (WIN_X / 2) - (630 / 2); elapsed = time(NULL) - start; if (last_time == elapsed && ABS(last_pc - minmax) < 5 && minmax != 100) return (0); mlx_clear_window(all->mlx_ptr, all->win_ptr); get_motd(all, elapsed); mlx_put_image_to_window(all->mlx_ptr, all->win_ptr, together[0].img_ptr, pos, 2 * WIN_Y / 3); mlx_put_image_to_window(all->mlx_ptr, all->win_ptr, together[1].img_ptr, pos + 30, 2 * WIN_Y / 3); mlx_put_image_to_window(all->mlx_ptr, all->win_ptr, together[2].img_ptr, pos + (minmax * 6) + 30, 2 * WIN_Y / 3); put_info(all, elapsed, minmax); last_time = elapsed; last_pc = minmax; return (0); }
void paint_mlx(t_vec3f *a, t_gui gui) { int x; int y; int pos; static t_bool rendered = FALSE; x = 0; y = 0; if (rendered) return (void)mlx_put_image_to_window(gui.mlx, gui.win, gui.image, 0, 0); while (y < HEIGHT && !(x = 0)) { while (x < WIDTH) { pos = (x * gui.bpp / 8) + (y * gui.sl); gui.pixel[pos] = (unsigned char)(ft_min(1.0, (*a).z) * 255); gui.pixel[pos + 1] = (unsigned char)(ft_min(1.0, (*a).y) * 255); gui.pixel[pos + 2] = (unsigned char)(ft_min(1.0, (*a).x) * 255); a++; x++; } y++; } rendered = TRUE; dispose_garbage(); mlx_put_image_to_window(gui.mlx, gui.win, gui.image, 0, 0); }
void draw(t_mlx *mlx) { tp(mlx); drawx(mlx); mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->imgsky->img, 0, 0); mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->imgview->img, 0, 0); map(mlx); mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->imgmap->img, 0, 0); str_data(mlx); }
int expose_hook(t_env *e) { if (ispressed(e->key)) e->scene.progressive_loading ? raytracing_progressive(e, e->cam) : start_raytracing(e); if (e->cam->type == STEREOSCOPIC) mlx_put_image_to_window(e->mlx, e->win.adr, e->cam->stereo.adr, 0, 0); else mlx_put_image_to_window(e->mlx, e->win.adr, e->cam->img.adr, 0, 0); e->key[STAT] ? display_stats(e) : 0; return (0); }
int gere_expose(t_param *param) { mlx_put_image_to_window(param->window.p, param->window.id, param->image.img, 0, 0); draw_ui(param); if (param->click_menu == 1) { mlx_put_image_to_window(param->window.p, param->window.id, param->panel_control.img, 165, 10); draw_conf(param); } return (0); }
void ft_static_xpm(t_id *s) { int i; int j; if (s->gun == 1) mlx_put_image_to_window(s->mlx, s->win, GU, W_X / 2, DE); if (s->map[(int)s->posx][(int)s->posy] == 2) { s->tp = malloc(sizeof(void*)); s->tp = mlx_xpm_file_to_image(s->mlx, "Textures/tp.xpm", &i, &j); mlx_put_image_to_window(s->mlx, s->win, s->tp, WX2, W_Y / 2 - 100); } }
int events(t_game *game) { view(game); draw_mini_map(game); mlx_put_image_to_window(game->window->mlx_ptr, game->window->mlx_win, \ game->window->img, 0, 0); mlx_put_image_to_window(game->window->mlx_ptr, game->window->mlx_win,\ game->window->mini_map, 30, 30); init_keys(game); mlx_hook(game->window->mlx_win, KeyPress, KeyPressMask, &hook_press, game); mlx_hook(game->window->mlx_win, KeyRelease, KeyReleaseMask, &hook_release,\ game); mlx_loop_hook(game->window->mlx_ptr, &gere_key, game); mlx_loop(game->window->mlx_ptr); }
static void level_image(t_env *e) { void *xpm; int lar; int lon; ft_bzero(e->str, LON * LAR * 4); mlx_put_image_to_window(e->mlx, e->win, e->img, 0, 0); xpm = mlx_xpm_file_to_image (e->mlx, e->stage->lvl, &lar, &lon); mlx_put_image_to_window(e->mlx, e->win, xpm, LAR / 2 - lar / 2, LON / 2 - lon / 2); mlx_put_image_to_window(e->mlx, e->win, xpm, LAR / 2 - lar / 2, LON / 2 - lon / 2); sleep(1); }
int main(int argc, char **argv) { t_win *window; t_cam *cam; t_map *map; /* Check argv */ if (argc > 2 || argc == 1) ft_error("Too or not enough parameters in command line"); /* Init Map */ map = ft_init_map(argv[1]); /* Init Env */ window = init_env(); /* Init Camera */ cam = ft_new_camera(map->start, M_PI / 2); /* Init img */ window->img = init_img(); mlx_do_key_autorepeaton(window->mlx); mlx_hook(window->win, 2, (1L << 0), ft_key_hook, window); mlx_expose_hook(window->win, ft_expose_hook, window); ft_draw_img(); mlx_put_image_to_window(window->mlx, window->win, window->img->img, 0, 0); mlx_loop(window->mlx); /* Display view */ /* Fini ! */ return (0); }
int expose_hook(t_env *env) { ft_bzero(env->str, SCREEN_HEIGHT * env->sline); ft_draw_map(env); mlx_put_image_to_window(env->mlx, env->win, env->img, 0, 0); return (0); }
int expose_hook(t_all *all) { mlx_put_image_to_window(all->env.mlx, all->env.win,\ all->img.img, 0, 0); cartridge(all); return (0); }
int ft_mouse(int button, int x, int y, t_mlx *mlx) { double u; double v; u = (WIN_W - (double)x * 2.0) / WIN_H; v = (WIN_H - (double)y * 2.0) / WIN_W; if (button == 1 && (x >= 0 && x <= WIN_W) && (y >= 0 && y <= WIN_H)) { mlx_clear_window(mlx->mlx, mlx->win); mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->img, 0, 0); if ((mlx->tmp = ft_seek(u, v, (t_vec){mlx->cam_pos.x + u, mlx->cam_pos.y + v, mlx->cam_pos.z}, mlx)) == NULL) { MSP(mlx->mlx, mlx->win, 630, 720, 0x00FEDC, "no selection"); mlx->selection = 0; return (0); } ft_string_put(mlx); MSP(mlx->mlx, mlx->win, 630, 735, 0x00FEDC, mlx->pos); free(mlx->pos); //(TMP->type != 4) ? free(mlx->rot) : NULL; mlx->selection = 1; } return (0); }
int ft_keypress(int keycode, t_env *e) { if (keycode == 76) { clear_map(e); get_point(e); choose_fractal(e); mlx_put_image_to_window(e->mlx, e->win, e->img, 0, 0); } if (keycode == 69 || keycode == 78) increase_deacrease(keycode, e); if (keycode == 123 || keycode == 124) ft_keypress2(keycode, e); if (keycode == 126 || keycode == 125) ft_keypress2(keycode, e); if (keycode == 53) { clear_map(e); exit(0); } if (keycode == 12) e->loop = 1; if (keycode == 0) e->loop = 0; return (0); }
int ft_keypress2(int keycode, t_env *e) { if (keycode == 124) move_map(e, (double)WIN_W * 0.05, 0); if (keycode == 123) move_map(e, (double)WIN_W * -0.05, 0); if (keycode == 125) { if (e->title[0] == 'J' || e->title[0] == 'M') move_map(e, 0, (double)WIN_H * 0.05); if (e->title[0] == 'S') move_map(e, 0, (double)WIN_H * -0.05); } if (keycode == 126) { if (e->title[0] == 'J' || e->title[0] == 'M') move_map(e, 0, (double)WIN_H * -0.05); if (e->title[0] == 'S') move_map(e, 0, (double)WIN_H * 0.05); } clear_map(e); choose_fractal(e); mlx_put_image_to_window(e->mlx, e->win, e->img, 0, 0); return (0); }
void put_mandelbrot(t_infos *i) { (i->first) ? 0 : init_mandelbrot(i); while (i->x < HEIGTH) { i->y = 0; while (i->y < WIDTH) { i->c_r = i->x / i->zoom + i->x1; i->c_i = i->y / i->zoom + i->y1; i->z_r = 0; i->z_i = 0; i->i = 0; while (i->z_r * i->z_r + i->z_i * i->z_i < 4 && i->i < i->i_max) { i->tmp = i->z_r; i->z_r = i->z_r * i->z_r - i->z_i * i->z_i + i->c_r; i->z_i = 2 * i->z_i * i->tmp + i->c_i; i->i++; } put_pixel(i); i->y++; } i->x++; } mlx_put_image_to_window(i->mlx, i->win, i->img, 0, 0); }
int fdf(t_env *env) { t_node *tmp; char *str; str = ft_itoa(env->param->zoom); tmp = env->map; while (tmp) { draw_line(env, tmp); tmp = tmp->next; } mlx_put_image_to_window(env->mlx, env->win, env->img->img, 0, 0); mlx_string_put(env->mlx, env->win, 695, 791, 0xAEECFE, "Current zoom x"); mlx_string_put(env->mlx, env->win, 839, 791, 0xFFFFFF, str); free(str); str = ft_itoa(env->param->xdefault); mlx_string_put(env->mlx, env->win, 170, 791, 0xAEECFE, "position.x = "); mlx_string_put(env->mlx, env->win, 300, 791, 0xFFFFFF, str); free(str); str = ft_itoa(env->param->ydefault); mlx_string_put(env->mlx, env->win, 170, 811, 0xAEECFE, "position.y = "); mlx_string_put(env->mlx, env->win, 300, 811, 0xFFFFFF, str); free(str); str = (env->proj) ? "Current proj : par" : "Current proj : iso"; mlx_string_put(env->mlx, env->win, 695, 811, 0xAEECFE, str); return (0); }
static int ft_display(t_windata *t_fdf) { I = -1; while (t_fdf->tab[++I]) { K = I; L = 0; while (t_fdf->tab[I][++L]) { J = L - 1; t_fdf->z2 = ft_atoi(t_fdf->tab[I][L]); t_fdf->z1 = ft_atoi(t_fdf->tab[I][J]); ft_algo(t_fdf); } } K = 0; while (t_fdf->tab[++K]) { I = K - 1; J = -1; while (t_fdf->tab[K][++J]) { L = J; t_fdf->z2 = ft_atoi(t_fdf->tab[K][J]); t_fdf->z1 = ft_atoi(t_fdf->tab[I][J]); ft_algo(t_fdf); } } mlx_put_image_to_window(t_fdf->mlx, t_fdf->win, t_fdf->img, 0, 0); return (0); }
int expose(t_env *env) { if (env->win && env->img.img) mlx_put_image_to_window(env->mlx, env->win, env->img.img, 0, 0); cleanup(env); return (0); }
void draw(t_data *data, t_mlx *mlx) { int i; t_vec3i screen_coord; t_vec4f view_coord; i = 0; while (i + 1 < (int)data->vertices.size) { view_coord = CAST(t_vertex *, ft_vect_at(&data->vertices, i))->pos; world_to_view(&view_coord); view_to_screen(&view_coord, &screen_coord, data, &mlx->v_screen); if (i < (int)data->vertices.size - data->ncol) { line_calc(data, mlx, i + data->ncol, &screen_coord); } if ((i + 1) % data->ncol == 0 && i != 0) { i++; continue ; } line_calc(data, mlx, i + 1, &screen_coord); i++; } mlx_put_image_to_window(mlx->mlx_ptr, mlx->win_ptr, mlx->screen.ptr, 0, 0); }
int expose_loop_hook(t_display *d) { move(d); raycastring(d); mlx_put_image_to_window(d->mlx, d->win, d->img->img_ptr, 0, 0); return (1); }
void aff_mur(t_image *t) { float a; float tmp; float x1; float y1; float i; input_font(t); a = ((t->a / 180) * M_PI); i = 0; while (i <= LENGHT) { x1 = 0.5; y1 = ((1 * ((LENGHT / 2) - i)) / LENGHT); tmp = x1; x1 = (tmp * cos(a)) - (y1 * sin(a)); y1 = (tmp * sin(a)) + (y1 * cos(a)); x1 = x1 + t->x; y1 = y1 + t->y; t->k = my_calcul_k(t, x1, y1); insert_mur(t, i); ++i; } mlx_put_image_to_window(t->mlx_ptr, t->win_ptr, t->img_ptr, 0, 0); }
int loop_hook(t_env *e) { t_rgb c; int x; if (e->img.img != NULL) { //Changed form mlx_destroy_image to this. mlx_destroy_image(e->mlx, e->img.img); e->img.img = NULL; } e->img.img = mlx_new_image(e->mlx, WIN_WIDTH, WIN_HEIGH); x = 0; while (x < WIN_WIDTH) { init_ray(e, x); ray_dir(e); perform_dda(e); compute(e); colors(e, &c); draw_line(x, e, &c); x++; } get_time_frame(e); move(e); mlx_put_image_to_window(e->mlx, e->win, e->img.img, 0, 0); return (0); }
int main(void) { int x; int y; int nb_it; double x_f; double y_f; double stepx; double stepy; t_env e; set_env(&e, "titre", WX, WY); x = 0; x_f = e.xmin; while (x <= WX) { y = 0; y_f = e.ymin; while (y <= WY) { nb_it = is_converg((mandelbrot), x_f, y_f); // printf("val x_f = %lf, val de y_f = %lf, val de nb_it = %d\n", x_f, y_f, nb_it); if (nb_it < 1000) mlx_pixel_put_img(e.img, x, y, rainbow_gen(nb_it * 40)); y++; y_f += e.stepy; } x_f += e.stepx; x++; } mlx_put_image_to_window(e.mlx, e.win, e.img, 0,0); mlx_mouse_hook(e.win, mouse_hook, &e); mlx_loop(e.mlx); return (0); }
void julia_iter(t_param *param, t_zoom *zoom) { double x; double y; t_iter iter; t_pnt pnt; get_data(param); x = 0; while (x < LARGEUR) { y = 0; while (y < HAUTEUR) { iter.c_r = param->itera.c_r; iter.c_i = param->itera.c_i; iter.z_r = x / zoom->zoom + zoom->x1; iter.z_i = y / zoom->zoom + zoom->y1; pnt.x = x; pnt.y = y; julia2(iter, zoom, param, &pnt); y++; } x++; } mlx_put_image_to_window(param->mlx, param->win, param->img, 0, 0); }
int main(int argc, char **argv) { t_mlxenv *e; t_mlxp *list; t_data *data; char *data_mlx; if (argc != 2) ft_error(ARG_ERROR); if ((e = malloc(sizeof(t_mlxenv))) == NULL) ft_error(ALLOC_ERROR); if ((data = malloc(sizeof(t_data))) == NULL) ft_error(ALLOC_ERROR); list = NULL; ft_parsing(&list, argv, data); ft_proj_iso_list(&list, data); if ((e->mlx = mlx_init()) == NULL) ft_error(END_PROG); e->img = mlx_new_image(e->mlx, 1650, 1000); data_mlx = mlx_get_data_addr(e->img, &(data->bpp), &(data->sizelin), &(data->endian)); ft_display_map(&list, data, data_mlx); e->win = mlx_new_window(e->mlx, 1650, 1000, "FdF"); mlx_put_image_to_window(e->mlx, e->win, e->img, 0, 0); ft_hook(e, &list); return (0); }
void raycasting(t_env *e) { int x; x = 0; while (x < WIN_WIDTH) { e->cam_x = (2.0 * x / (double)(WIN_WIDTH)) - 1.0; e->rpos_x = e->pos_x; e->rpos_y = e->pos_y; e->rdir_x = e->dir_x + e->plan_x * e->cam_x; e->rdir_y = e->dir_y + e->plan_y * e->cam_x; e->map_x = (int)(e->rpos_x); e->map_y = (int)(e->rpos_y); e->ddist_x = sqrt(1 + (e->rdir_y * e->rdir_y) / (e->rdir_x * e->rdir_x)); e->ddist_y = sqrt(1 + (e->rdir_x * e->rdir_x) / (e->rdir_y * e->rdir_y)); e->hit = 0; digital_differential_analizer(e); optic_correction(e); get_height_column(e); draw_column(e, x); x++; } mlx_put_image_to_window(e->mlx, e->win, e->img, 0, 0); }
int gere_expose(t_rt *rt) { mlx_put_image_to_window(rt->mlx.mlx_ptr, rt->mlx.win_ptr, rt->mlx.img_ptr, 0, 0); return (0); }