├── Makefile ├── README.md ├── cam_calc.c ├── default.rt ├── dist.c ├── dist ├── bx.c ├── cy.c ├── dist.h ├── pl.c ├── sp.c ├── sq.c └── tr.c ├── ft_init.c ├── gnl ├── get_next_line_bonus.c ├── get_next_line_bonus.h └── get_next_line_utils_bonus.c ├── init.c ├── keyboard.c ├── libft ├── Makefile ├── ft_atoi.c ├── ft_bzero.c ├── ft_calloc.c ├── ft_isalnum.c ├── ft_isalpha.c ├── ft_isascii.c ├── ft_isdigit.c ├── ft_isprint.c ├── ft_itoa.c ├── ft_lstadd_back.c ├── ft_lstadd_front.c ├── ft_lstclear.c ├── ft_lstdelone.c ├── ft_lstiter.c ├── ft_lstlast.c ├── ft_lstmap.c ├── ft_lstnew.c ├── ft_lstsize.c ├── ft_memccpy.c ├── ft_memchr.c ├── ft_memcmp.c ├── ft_memcpy.c ├── ft_memmove.c ├── ft_memset.c ├── ft_putchar_fd.c ├── ft_putendl_fd.c ├── ft_putnbr_fd.c ├── ft_putstr_fd.c ├── ft_split.c ├── ft_strchr.c ├── ft_strdup.c ├── ft_strjoin.c ├── ft_strlcat.c ├── ft_strlcpy.c ├── ft_strlen.c ├── ft_strmapi.c ├── ft_strncmp.c ├── ft_strnstr.c ├── ft_strrchr.c ├── ft_strtrim.c ├── ft_substr.c ├── ft_tolower.c ├── ft_toupper.c └── libft.h ├── main.c ├── minilibx-linux-master ├── Makefile ├── Makefile.gen ├── Makefile.mk ├── README.md ├── configure ├── libmlx.a ├── libmlx_Linux.a ├── man │ ├── man1 │ │ ├── mlx.1 │ │ ├── mlx_loop.1 │ │ ├── mlx_new_image.1 │ │ ├── mlx_new_window.1 │ │ └── mlx_pixel_put.1 │ └── man3 │ │ ├── mlx.1 │ │ ├── mlx_loop.1 │ │ ├── mlx_new_image.1 │ │ ├── mlx_new_window.1 │ │ └── mlx_pixel_put.1 ├── mlx.h ├── mlx_clear_window.c ├── mlx_clear_window.o ├── mlx_destroy_display.c ├── mlx_destroy_display.o ├── mlx_destroy_image.c ├── mlx_destroy_image.o ├── mlx_destroy_window.c ├── mlx_destroy_window.o ├── mlx_expose_hook.c ├── mlx_expose_hook.o ├── mlx_ext_randr.c ├── mlx_flush_event.c ├── mlx_flush_event.o ├── mlx_get_color_value.c ├── mlx_get_color_value.o ├── mlx_get_data_addr.c ├── mlx_get_data_addr.o ├── mlx_hook.c ├── mlx_hook.o ├── mlx_init.c ├── mlx_init.o ├── mlx_int.h ├── mlx_int_anti_resize_win.c ├── mlx_int_anti_resize_win.o ├── mlx_int_do_nothing.c ├── mlx_int_do_nothing.o ├── mlx_int_get_visual.c ├── mlx_int_get_visual.o ├── mlx_int_param_event.c ├── mlx_int_param_event.o ├── mlx_int_set_win_event_mask.c ├── mlx_int_set_win_event_mask.o ├── mlx_int_str_to_wordtab.c ├── mlx_int_str_to_wordtab.o ├── mlx_int_wait_first_expose.c ├── mlx_int_wait_first_expose.o ├── mlx_key_hook.c ├── mlx_key_hook.o ├── mlx_lib_xpm.c ├── mlx_loop.c ├── mlx_loop.o ├── mlx_loop_hook.c ├── mlx_loop_hook.o ├── mlx_mouse.c ├── mlx_mouse.o ├── mlx_mouse_hook.c ├── mlx_mouse_hook.o ├── mlx_new_image.c ├── mlx_new_image.o ├── mlx_new_window.c ├── mlx_new_window.o ├── mlx_pixel_put.c ├── mlx_pixel_put.o ├── mlx_put_image_to_window.c ├── mlx_put_image_to_window.o ├── mlx_rgb.c ├── mlx_rgb.o ├── mlx_screen_size.c ├── mlx_screen_size.o ├── mlx_set_font.c ├── mlx_set_font.o ├── mlx_string_put.c ├── mlx_string_put.o ├── mlx_xpm.c ├── mlx_xpm.c.ok ├── mlx_xpm.o ├── rgb2c.pl └── test │ ├── Makefile.gen │ ├── Makefile.mk │ ├── main.c │ ├── main.o │ ├── new_win.c │ ├── open.xpm │ ├── open24.xpm │ └── open30.xpm ├── misc ├── geo_op.c ├── mlx_comp.c ├── operators.c ├── rgb_hex.c ├── vectors_0.c └── vectors_1.c ├── mouse.c ├── obj ├── add_bx.c ├── add_c.c ├── add_cy.c ├── add_l.c ├── add_pl.c ├── add_sp.c ├── add_sq.c └── add_tr.c ├── parse ├── def_bx.c ├── def_cy.c ├── def_ft.c ├── def_ft.h ├── def_obj.c ├── def_pl.c ├── def_sp.c ├── def_sq.c ├── def_tr.c ├── elements.c └── settings.c ├── parser.c ├── preview.png ├── raymarching.c ├── raymarching.h ├── save.c └── test_func.c /Makefile: -------------------------------------------------------------------------------- 1 | NAME = miniRT 2 | 3 | SRC = main.c\ 4 | cam_calc.c\ 5 | dist.c\ 6 | init.c\ 7 | ft_init.c\ 8 | mouse.c\ 9 | keyboard.c\ 10 | raymarching.c\ 11 | test_func.c\ 12 | dist/bx.c\ 13 | dist/cy.c\ 14 | dist/pl.c\ 15 | dist/sp.c\ 16 | dist/sq.c\ 17 | dist/tr.c\ 18 | obj/add_bx.c\ 19 | obj/add_cy.c\ 20 | obj/add_l.c\ 21 | obj/add_c.c\ 22 | obj/add_pl.c\ 23 | obj/add_sp.c\ 24 | obj/add_sq.c\ 25 | obj/add_tr.c\ 26 | misc/geo_op.c\ 27 | misc/mlx_comp.c\ 28 | misc/operators.c\ 29 | misc/rgb_hex.c\ 30 | misc/vectors_0.c\ 31 | misc/vectors_1.c\ 32 | gnl/get_next_line_bonus.c\ 33 | parse/settings.c\ 34 | parse/def_ft.c\ 35 | parse/def_obj.c\ 36 | parse/def_sp.c\ 37 | parse/def_pl.c\ 38 | parse/def_cy.c\ 39 | parse/def_sq.c\ 40 | parse/def_tr.c\ 41 | parse/def_bx.c\ 42 | parse/elements.c\ 43 | parser.c\ 44 | save.c\ 45 | 46 | OBJ = main.o\ 47 | cam_calc.o\ 48 | dist.o\ 49 | init.o\ 50 | ft_init.o\ 51 | mouse.o\ 52 | keyboard.o\ 53 | raymarching.o\ 54 | test_func.o\ 55 | bx.o\ 56 | cy.o\ 57 | pl.o\ 58 | sp.o\ 59 | sq.o\ 60 | tr.o\ 61 | add_bx.o\ 62 | add_cy.o\ 63 | add_l.o\ 64 | add_c.o\ 65 | add_pl.o\ 66 | add_sp.o\ 67 | add_sq.o\ 68 | add_tr.o\ 69 | geo_op.o\ 70 | mlx_comp.o\ 71 | operators.o\ 72 | rgb_hex.o\ 73 | vectors_0.o\ 74 | vectors_1.o\ 75 | get_next_line_bonus.o\ 76 | settings.o\ 77 | def_ft.o\ 78 | def_obj.o\ 79 | def_sp.o\ 80 | def_pl.o\ 81 | def_cy.o\ 82 | def_sq.o\ 83 | def_tr.o\ 84 | def_bx.o\ 85 | elements.o\ 86 | parser.o\ 87 | save.o\ 88 | 89 | MLX = minilibx-linux-master/*.a 90 | 91 | LFT = libft/libft.a 92 | 93 | CFLAGS = -Wall -Werror -Wextra 94 | 95 | LFLAGS = -L.. -lmlx -lXext -lX11 -lm -lbsd 96 | 97 | all: $(NAME) 98 | 99 | $(NAME): 100 | make -C libft 101 | gcc -c $(SRC) 102 | gcc $(CFLAGS) $(OBJ) $(LFT) $(MLX) $(LFLAGS) -o $(NAME) 103 | 104 | clean: 105 | make -C libft clean 106 | rm -rf $(OBJ) 107 | 108 | fclean: clean 109 | make -C libft fclean 110 | rm -rf $(NAME) 111 | 112 | re: fclean all 113 | 114 | norminette: 115 | norminette $(SRC) libft/* 116 | 117 | .PHONY: all clean fclean re test 118 | -------------------------------------------------------------------------------- /cam_calc.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* cam_calc.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/11/05 13:46:04 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/05 14:02:26 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "raymarching.h" 14 | 15 | void calculate_vectors(t_data *param) 16 | { 17 | double module; 18 | int i; 19 | 20 | param->cam.vx[0] = -param->cam.vn[1]; 21 | param->cam.vx[1] = param->cam.vn[0]; 22 | param->cam.vx[2] = 0; 23 | param->cam.vy[0] = -param->cam.vn[0] * param->cam.vn[2]; 24 | param->cam.vy[1] = -param->cam.vn[1] * param->cam.vn[2]; 25 | param->cam.vy[2] = pow(param->cam.vn[1], 2) + pow(param->cam.vn[0], 2); 26 | i = -1; 27 | while (++i < 3) 28 | param->cam.p[i] = param->cam.o[i] + param->cam.vn[i] * param->scr.dist; 29 | module = sqrt(pow(param->cam.vx[0], 2) + pow(param->cam.vx[1], 2)); 30 | i = -1; 31 | while (++i < 2) 32 | param->cam.vx[i] /= module; 33 | i = -1; 34 | while (++i < 3) 35 | param->cam.vy[i] /= module; 36 | } 37 | 38 | void copy_cam(t_data *param) 39 | { 40 | int j; 41 | 42 | j = -1; 43 | while (++j < 3) 44 | { 45 | param->c[param->cam.i]->o[j] = param->cam.o[j]; 46 | param->c[param->cam.i]->v[j] = param->cam.vn[j]; 47 | } 48 | } 49 | 50 | void calculate_rotation(t_data *param) 51 | { 52 | double rotation_z_axis; 53 | double rotation_y_axis; 54 | double xy_projection; 55 | 56 | rotation_z_axis = param->crd.x * 2 * param->mou.speed * M_PI / 250 + 57 | param->cam.rot_z; 58 | rotation_y_axis = param->crd.y * 2 * param->mou.speed * M_PI / 250 + 59 | param->cam.rot_y; 60 | xy_projection = cos(rotation_y_axis); 61 | param->cam.vn[0] = cos(rotation_z_axis) * xy_projection; 62 | param->cam.vn[1] = sin(rotation_z_axis) * xy_projection; 63 | param->cam.vn[2] = sin(rotation_y_axis); 64 | } 65 | -------------------------------------------------------------------------------- /default.rt: -------------------------------------------------------------------------------- 1 | R 400 200 2 | A 1 114,124,219 3 | l -500.0,-500.0,1000.0 0.8 230,196,124 4 | l -500.0,500.0,1000.0 0.8 179,196,189 5 | cy 500.0,500.0,1.0 0.0,0.0,1.0 220,140,46 200.0 1000.0 6 | sp 1500.0,1500.0,0.0 500 177,90,118 7 | sp 3500.0,-3500.0,-1000.0 3000.0 100,200,50 8 | bx 500.0,500.0,1.0 0.0,1.0,1.0 500.0 138,187,118 9 | sq 500.0,500.0,1000.0 0.0,1.0,1.0 500.0 138,187,118 10 | pl 3500.0,-3500.0,-1000.0 0.0,0.0,1.0 200,200,200 11 | c 0.0,0.0,0.0 0.0,1.0,0.0 90 12 | c 100.0,0.0,0.0 1.0,0.0,0.0 90 13 | tr 1500.0,1500.0,0.0 500.0,500.0,1.0 3500.0,-3500.0,-1000.0 177,90,118 -------------------------------------------------------------------------------- /dist.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* dist.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/20 11:30:12 by jserrano #+# #+# */ 9 | /* Updated: 2020/10/28 12:53:38 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "dist/dist.h" 14 | 15 | static void obj_dist_p1(t_data *param, double *dist, double *aux) 16 | { 17 | *dist = sp_dist(param); 18 | param->cam.ray.obj_c = (*dist < 2147483647) ? 19 | param->sp[param->cam.ray.obj_n]->col : param->cam.ray.obj_c; 20 | *aux = pl_dist(param); 21 | param->cam.ray.obj_c = (*aux < *dist) ? 22 | param->pl[param->cam.ray.obj_n]->col : param->cam.ray.obj_c; 23 | *dist = (*aux < *dist) ? *aux : *dist; 24 | *aux = cy_dist(param); 25 | param->cam.ray.obj_c = (*aux < *dist) ? 26 | param->cy[param->cam.ray.obj_n]->col : param->cam.ray.obj_c; 27 | *dist = (*aux < *dist) ? *aux : *dist; 28 | } 29 | 30 | static void obj_dist_p2(t_data *param, double *dist, double *aux) 31 | { 32 | *aux = sq_dist(param); 33 | param->cam.ray.obj_c = (*aux < *dist) ? 34 | param->sq[param->cam.ray.obj_n]->col : param->cam.ray.obj_c; 35 | *dist = (*aux < *dist) ? *aux : *dist; 36 | *aux = bx_dist(param); 37 | param->cam.ray.obj_c = (*aux < *dist) ? 38 | param->bx[param->cam.ray.obj_n]->col : param->cam.ray.obj_c; 39 | *dist = (*aux < *dist) ? *aux : *dist; 40 | *aux = tr_dist(param); 41 | param->cam.ray.obj_c = (*aux < *dist) ? 42 | param->tr[param->cam.ray.obj_n]->col : param->cam.ray.obj_c; 43 | *dist = (*aux < *dist) ? *aux : *dist; 44 | } 45 | 46 | double obj_dist(t_data *param) 47 | { 48 | double dist; 49 | double aux; 50 | 51 | obj_dist_p1(param, &dist, &aux); 52 | obj_dist_p2(param, &dist, &aux); 53 | return (dist); 54 | } 55 | -------------------------------------------------------------------------------- /dist/bx.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* bx.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/24 11:03:34 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/04 16:09:31 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "dist.h" 14 | 15 | double bx_dist(t_data *param) 16 | { 17 | double d_xyz[3]; 18 | double dist; 19 | double aux; 20 | int i; 21 | 22 | dist = 2147483647; 23 | i = -1; 24 | while (param->bx[++i]) 25 | { 26 | d_xyz[2] = 27 | plane_dist(param->bx[i]->v, param->bx[i]->o, param->cam.ray.o); 28 | d_xyz[1] = 29 | plane_dist(param->bx[i]->y, param->bx[i]->o, param->cam.ray.o); 30 | d_xyz[0] = 31 | plane_dist(param->bx[i]->x, param->bx[i]->o, param->cam.ray.o); 32 | aux = sqrt(pow(max(d_xyz[2] - param->bx[i]->h / 2, 0), 2) + 33 | pow(max(d_xyz[0] - param->bx[i]->h / 2, 0), 2) + 34 | pow(max(d_xyz[1] - param->bx[i]->h / 2, 0), 2)); 35 | param->cam.ray.obj_n = (aux < dist) ? i : param->cam.ray.obj_n; 36 | dist = (aux < dist) ? aux : dist; 37 | } 38 | return (dist); 39 | } 40 | -------------------------------------------------------------------------------- /dist/cy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* cy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/24 11:02:30 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/04 14:31:25 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "dist.h" 14 | 15 | double cy_dist(t_data *param) 16 | { 17 | double px[3]; 18 | double dy_v[3]; 19 | double d_xy[2]; 20 | double a_d[2]; 21 | int ij[2]; 22 | 23 | a_d[1] = 2147483647; 24 | ij[0] = -1; 25 | while (param->cy[++ij[0]]) 26 | { 27 | ij[1] = -1; 28 | while (++ij[1] < 3) 29 | px[ij[1]] = param->cam.ray.o[ij[1]] - param->cy[ij[0]]->o[ij[1]]; 30 | ij[1] = -1; 31 | while (++ij[1] < 3) 32 | dy_v[ij[1]] = cross_prod(px, param->cy[ij[0]]->v, ij[1]); 33 | d_xy[1] = mod(dy_v); 34 | d_xy[0] = plane_dist(param->cy[ij[0]]->v, param->cy[ij[0]]->o, 35 | param->cam.ray.o); 36 | a_d[0] = sqrt(pow(max(d_xy[0] - param->cy[ij[0]]->h / 2, 0), 2) + 37 | pow(max(d_xy[1] - param->cy[ij[0]]->d / 2, 0), 2)); 38 | param->cam.ray.obj_n = (a_d[0] < a_d[1]) ? ij[0] : param->cam.ray.obj_n; 39 | a_d[1] = (a_d[0] < a_d[1]) ? a_d[0] : a_d[1]; 40 | } 41 | return (a_d[1]); 42 | } 43 | -------------------------------------------------------------------------------- /dist/dist.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* dist.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/24 10:58:20 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/05 14:02:46 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef DIST_H 14 | # define DIST_H 15 | 16 | # include "../raymarching.h" 17 | 18 | double sp_dist(t_data *param); 19 | double pl_dist(t_data *param); 20 | double sq_dist(t_data *param); 21 | double bx_dist(t_data *param); 22 | double cy_dist(t_data *param); 23 | double tr_dist(t_data *param); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /dist/pl.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* pl.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/24 11:00:02 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/04 14:09:30 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "dist.h" 14 | 15 | double pl_dist(t_data *param) 16 | { 17 | double dist; 18 | double aux; 19 | int i; 20 | 21 | dist = 2147483647; 22 | i = 0; 23 | while (param->pl[i]) 24 | { 25 | aux = plane_dist(param->pl[i]->v, param->pl[i]->o, param->cam.ray.o); 26 | param->cam.ray.obj_n = (aux < dist) ? i : param->cam.ray.obj_n; 27 | dist = (aux < dist) ? aux : dist; 28 | i++; 29 | } 30 | return (dist); 31 | } 32 | -------------------------------------------------------------------------------- /dist/sp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* sp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/24 10:57:57 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/04 14:10:03 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "dist.h" 14 | 15 | double sp_dist(t_data *param) 16 | { 17 | double dist; 18 | double aux; 19 | int i; 20 | 21 | dist = 2147483647; 22 | i = 0; 23 | while (param->sp[i]) 24 | { 25 | aux = sqrt(pow(param->sp[i]->o[0] - param->cam.ray.o[0], 2) + 26 | pow(param->sp[i]->o[1] - param->cam.ray.o[1], 2) + 27 | pow(param->sp[i]->o[2] - param->cam.ray.o[2], 2)) - 28 | param->sp[i]->r; 29 | if (aux < dist) 30 | { 31 | param->cam.ray.obj_n = i; 32 | dist = aux; 33 | } 34 | i++; 35 | } 36 | return (dist); 37 | } 38 | -------------------------------------------------------------------------------- /dist/sq.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* sq.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/24 11:01:28 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/04 14:10:23 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "dist.h" 14 | 15 | double sq_dist(t_data *param) 16 | { 17 | double d_xyz[3]; 18 | double dist; 19 | double aux; 20 | int i; 21 | 22 | dist = 2147483647; 23 | i = -1; 24 | while (param->sq[++i]) 25 | { 26 | d_xyz[2] = 27 | plane_dist(param->sq[i]->v, param->sq[i]->o, param->cam.ray.o); 28 | d_xyz[1] = 29 | plane_dist(param->sq[i]->y, param->sq[i]->o, param->cam.ray.o); 30 | d_xyz[0] = 31 | plane_dist(param->sq[i]->x, param->sq[i]->o, param->cam.ray.o); 32 | aux = sqrt(pow(max(d_xyz[2], 0), 2) + 33 | pow(max(d_xyz[0] - param->sq[i]->h / 2, 0), 2) + 34 | pow(max(d_xyz[1] - param->sq[i]->h / 2, 0), 2)); 35 | param->cam.ray.obj_n = (aux < dist) ? i : param->cam.ray.obj_n; 36 | dist = (aux < dist) ? aux : dist; 37 | } 38 | return (dist); 39 | } 40 | -------------------------------------------------------------------------------- /dist/tr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* tr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/24 21:00:17 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/04 15:32:12 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "dist.h" 14 | 15 | /* 16 | ** var[3] = j, x, y 17 | */ 18 | 19 | static void is_inside_ifs(t_data *param, int *var, int i) 20 | { 21 | if (!param->tr[i]->nor[2]) 22 | { 23 | if (!param->tr[i]->nor[1]) 24 | var[1] = 1; 25 | else 26 | var[1] = 0; 27 | var[2] = 2; 28 | } 29 | else 30 | { 31 | var[1] = 0; 32 | var[2] = 1; 33 | } 34 | } 35 | 36 | static int is_inside(t_data *param, int i) 37 | { 38 | double w[2]; 39 | double ac[3]; 40 | double ab[3]; 41 | double ap[3]; 42 | int var[3]; 43 | 44 | is_inside_ifs(param, var, i); 45 | var[0] = -1; 46 | while (++var[0] < 3) 47 | { 48 | ab[var[0]] = param->tr[i]->ab[var[0]]; 49 | ac[var[0]] = param->tr[i]->ac[var[0]]; 50 | ap[var[0]] = param->cam.ray.o[var[0]] - param->tr[i]->a[var[0]]; 51 | } 52 | w[1] = (dot_2d(ap, ac, var[1], var[2]) * dot_2d(ac, ab, var[1], var[2]) - 53 | dot_2d(ap, ab, var[1], var[2]) * dot_2d(ac, ac, var[1], var[2])) / 54 | (dot_2d(ab, ac, var[1], var[2]) * dot_2d(ac, ab, var[1], var[2]) - 55 | dot_2d(ab, ab, var[1], var[2]) * dot_2d(ac, ac, var[1], var[2])); 56 | w[0] = (dot_2d(ap, ac, var[1], var[2]) - 57 | w[1] * dot_2d(ab, ac, var[1], var[2])) / 58 | dot_2d(ac, ac, var[1], var[2]); 59 | if (w[0] >= 0 && w[0] < 1 && w[1] >= 0 && w[1] < 1 && w[0] + w[1] <= 1) 60 | return (1); 61 | return (0); 62 | } 63 | 64 | static double contour_dist(t_data *param, int i) 65 | { 66 | double aux; 67 | double dist; 68 | 69 | dist = segment_dist(param->tr[i]->a, param->tr[i]->b, param->cam.ray.o); 70 | aux = segment_dist(param->tr[i]->b, param->tr[i]->c, param->cam.ray.o); 71 | dist = (aux < dist) ? aux : dist; 72 | aux = segment_dist(param->tr[i]->c, param->tr[i]->a, param->cam.ray.o); 73 | dist = (aux < dist) ? aux : dist; 74 | return (dist); 75 | } 76 | 77 | double tr_dist(t_data *param) 78 | { 79 | int i; 80 | double aux; 81 | double dist; 82 | 83 | i = -1; 84 | dist = 2147483647; 85 | while (param->tr[++i]) 86 | { 87 | aux = (is_inside(param, i)) ? 88 | plane_dist(param->tr[i]->nor, param->tr[i]->a, param->cam.ray.o) : 89 | contour_dist(param, i); 90 | param->cam.ray.obj_n = (aux < dist) ? i : param->cam.ray.obj_n; 91 | dist = (aux < dist) ? aux : dist; 92 | } 93 | return (dist); 94 | } 95 | -------------------------------------------------------------------------------- /ft_init.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_init.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/11/03 17:29:54 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/04 23:42:57 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "raymarching.h" 14 | 15 | static void objs_init(t_data *param) 16 | { 17 | param->scr.x = -1; 18 | param->scr.y = -1; 19 | param->amb_l = -1; 20 | param->cam.n = 0; 21 | param->cam.i = 0; 22 | param->l = (t_light **)malloc(sizeof(t_light *)); 23 | param->l[0] = 0; 24 | param->c = (t_cams **)malloc(sizeof(t_cams *)); 25 | param->c[0] = 0; 26 | param->sp = (t_sphere **)malloc(sizeof(t_sphere *)); 27 | param->sp[0] = 0; 28 | param->pl = (t_plane **)malloc(sizeof(t_plane *)); 29 | param->pl[0] = 0; 30 | param->cy = (t_cylinder **)malloc(sizeof(t_cylinder *)); 31 | param->cy[0] = 0; 32 | param->sq = (t_square **)malloc(sizeof(t_square *)); 33 | param->sq[0] = 0; 34 | param->bx = (t_box **)malloc(sizeof(t_box *)); 35 | param->bx[0] = 0; 36 | param->tr = (t_triangle **)malloc(sizeof(t_triangle *)); 37 | param->tr[0] = 0; 38 | } 39 | 40 | static void screen_init(t_data *param) 41 | { 42 | param->win_id = mlx_new_window(param->id, param->scr.x, 43 | param->scr.y, "miniRT de jserrano"); 44 | param->img.img = mlx_new_image(param->id, param->scr.x, 45 | param->scr.y); 46 | param->img.addr = mlx_get_data_addr(param->img.img, 47 | ¶m->img.bits_per_pixel, ¶m->img.line_length, ¶m->img.endian); 48 | } 49 | 50 | void ft_init(t_data *param, char **argv) 51 | { 52 | param->id = mlx_init(); 53 | mlx_get_screen_size(param->id, ¶m->max_res[0], ¶m->max_res[1]); 54 | objs_init(param); 55 | parse(param, argv); 56 | screen_init(param); 57 | mouse_init(param); 58 | pos_init(param, 0); 59 | vectors_init(param, 0); 60 | calculate_rotation(param); 61 | calculate_vectors(param); 62 | } 63 | -------------------------------------------------------------------------------- /gnl/get_next_line_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* get_next_line_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/28 14:23:36 by jserrano #+# #+# */ 9 | /* Updated: 2020/10/28 14:23:41 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "get_next_line_bonus.h" 14 | 15 | int make_str(char **str, char **line) 16 | { 17 | int len; 18 | char *aux; 19 | 20 | len = 0; 21 | while ((*str)[len] != '\n' && (*str)[len] != '\0') 22 | len++; 23 | if ((*str)[len] == '\n') 24 | { 25 | *line = ft_substr(*str, 0, len); 26 | aux = ft_strdup(&((*str)[len + 1])); 27 | free(*str); 28 | *str = aux; 29 | } 30 | else 31 | { 32 | *line = ft_strdup(*str); 33 | free(*str); 34 | *str = NULL; 35 | return (0); 36 | } 37 | return (1); 38 | } 39 | 40 | int return_str(int fd, int num, char **str, char **line) 41 | { 42 | if (num < 0) 43 | return (-1); 44 | else if (num == 0 && str[fd] == NULL) 45 | { 46 | *line = ft_strdup(""); 47 | return (0); 48 | } 49 | else 50 | return (make_str(&str[fd], line)); 51 | } 52 | 53 | int get_next_line(int fd, char **line) 54 | { 55 | static char *str[FD_SIZE]; 56 | char *res; 57 | int num; 58 | char *aux; 59 | 60 | if (!(res = (char *)malloc(sizeof(char) * (BUFFER_SIZE + 1)))) 61 | return (-1); 62 | if (fd < 0 || !line || BUFFER_SIZE < 1 || read(fd, res, 0) < 0) 63 | return (-1); 64 | while ((num = read(fd, res, BUFFER_SIZE)) > 0) 65 | { 66 | res[num] = '\0'; 67 | if (str[fd] == NULL) 68 | str[fd] = ft_strdup(res); 69 | else 70 | { 71 | aux = ft_strjoin(str[fd], res); 72 | free(str[fd]); 73 | str[fd] = aux; 74 | } 75 | if (ft_strchr(str[fd], '\n')) 76 | break ; 77 | } 78 | return (return_str(fd, num, str, line)); 79 | } 80 | -------------------------------------------------------------------------------- /gnl/get_next_line_bonus.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* get_next_line_bonus.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/28 14:24:10 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/05 14:03:43 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef GET_NEXT_LINE_BONUS_H 14 | # define GET_NEXT_LINE_BONUS_H 15 | # ifndef BUFFER_SIZE 16 | # define BUFFER_SIZE 32 17 | # endif 18 | # ifndef FD_SIZE 19 | # define FD_SIZE 4096 20 | # endif 21 | 22 | # include 23 | # include 24 | # include 25 | # include 26 | # include 27 | # include "../libft/libft.h" 28 | 29 | int get_next_line(int fd, char **line); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /gnl/get_next_line_utils_bonus.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* get_next_line_utils_bonus.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/28 14:25:31 by jserrano #+# #+# */ 9 | /* Updated: 2020/10/28 14:25:31 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "get_next_line_bonus.h" 14 | 15 | size_t ft_strlen(char *str) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (str[i]) 21 | { 22 | i++; 23 | } 24 | return (i); 25 | } 26 | 27 | char *ft_strdup(char *s1) 28 | { 29 | char *s2; 30 | int i; 31 | int size; 32 | 33 | size = ft_strlen(s1); 34 | i = 0; 35 | s2 = (char*)malloc(sizeof(char) * size + 1); 36 | if (s2 == NULL) 37 | { 38 | return (s2); 39 | } 40 | while (i <= size) 41 | { 42 | s2[i] = s1[i]; 43 | i++; 44 | } 45 | return (s2); 46 | } 47 | 48 | char *ft_substr(char *s, unsigned int start, size_t len) 49 | { 50 | size_t i; 51 | char *substr; 52 | 53 | i = 0; 54 | if (!s) 55 | { 56 | return (NULL); 57 | } 58 | if (ft_strlen(s) < start) 59 | return (ft_strdup("")); 60 | substr = (char*)malloc(sizeof(char) * (len + 1)); 61 | if (substr == NULL) 62 | return (substr); 63 | while (s[i] && i < len) 64 | { 65 | substr[i] = s[start + i]; 66 | i++; 67 | } 68 | substr[i] = '\0'; 69 | return (substr); 70 | } 71 | 72 | char *ft_strchr(char *s, int len) 73 | { 74 | while (*s) 75 | { 76 | if (*s == len) 77 | { 78 | return ((char*)s); 79 | } 80 | s++; 81 | } 82 | if (len == '\0') 83 | { 84 | return ((char*)s); 85 | } 86 | return (NULL); 87 | } 88 | 89 | char *ft_strjoin(char *s1, char *s2) 90 | { 91 | int i; 92 | int j; 93 | char *join; 94 | 95 | if (!s1 || !s2) 96 | return (NULL); 97 | join = (char*)malloc(sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1)); 98 | if (join == NULL) 99 | return (join); 100 | i = 0; 101 | j = 0; 102 | while (s1[i]) 103 | { 104 | join[i] = s1[i]; 105 | i++; 106 | } 107 | while (s2[j]) 108 | { 109 | join[i + j] = s2[j]; 110 | j++; 111 | } 112 | join[i + j] = '\0'; 113 | return (join); 114 | } 115 | -------------------------------------------------------------------------------- /init.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* init.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/17 13:38:01 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/04 14:06:35 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "raymarching.h" 14 | 15 | void mouse_init(t_data *param) 16 | { 17 | param->crd.x = 0; 18 | param->crd.y = 0; 19 | param->mou.x = 0; 20 | param->mou.y = 0; 21 | param->mou.speed = 0.25; 22 | } 23 | 24 | void pos_init(t_data *param, int i) 25 | { 26 | param->cam.o[0] = param->c[i]->o[0]; 27 | param->cam.o[1] = param->c[i]->o[1]; 28 | param->cam.o[2] = param->c[i]->o[2]; 29 | } 30 | 31 | void vectors_init(t_data *param, int j) 32 | { 33 | int i; 34 | 35 | i = -1; 36 | while (++i < 3) 37 | param->cam.vn[i] = param->c[j]->v[i]; 38 | if (param->cam.vn[0] >= 0 && param->cam.vn[1] >= 0) 39 | param->cam.rot_z = asin(param->cam.vn[1]); 40 | else if (param->cam.vn[0] < 0 && param->cam.vn[1] >= 0) 41 | param->cam.rot_z = M_PI - asin(param->cam.vn[1]); 42 | else if (param->cam.vn[0] < 0 && param->cam.vn[1] < 0) 43 | param->cam.rot_z = M_PI + asin(param->cam.vn[1]); 44 | else if (param->cam.vn[0] >= 0 && param->cam.vn[1] < 0) 45 | param->cam.rot_z = 2 * M_PI - asin(param->cam.vn[1]); 46 | param->cam.rot_y = (param->cam.vn[2] >= 0) ? asin(param->cam.vn[2]) : 47 | 2 * M_PI - asin(param->cam.vn[2]); 48 | param->scr.fov = param->c[j]->fov; 49 | param->scr.dist = (param->scr.x / 2) / 50 | tan((param->scr.fov / 2) * M_PI / 180); 51 | } 52 | -------------------------------------------------------------------------------- /keyboard.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* keyboard.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/11/04 14:58:23 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/04 23:42:35 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "raymarching.h" 14 | 15 | static void change_cam(t_data *param) 16 | { 17 | if (param->cam.i + 1 == param->cam.n) 18 | param->cam.i = 0; 19 | else 20 | param->cam.i++; 21 | pos_init(param, param->cam.i); 22 | vectors_init(param, param->cam.i); 23 | } 24 | 25 | static void key_pressed_ifs(int keycode, t_data *param) 26 | { 27 | int j; 28 | 29 | j = -1; 30 | if (keycode == KEY_ESC) 31 | ft_exit(param); 32 | else if (keycode == KEY_W) 33 | while (++j < 3) 34 | param->cam.o[j] += param->cam.vn[j] * 20; 35 | else if (keycode == KEY_A) 36 | while (++j < 3) 37 | param->cam.o[j] += param->cam.vx[j] * -20; 38 | else if (keycode == KEY_S) 39 | while (++j < 3) 40 | param->cam.o[j] += param->cam.vn[j] * -20; 41 | else if (keycode == KEY_D) 42 | while (++j < 3) 43 | param->cam.o[j] += param->cam.vx[j] * 20; 44 | else if (keycode == KEY_SPA) 45 | param->cam.o[2] += 10; 46 | else if (keycode == KEY_CTR) 47 | param->cam.o[2] += -10; 48 | else if (keycode == KEY_ENT) 49 | save_scr(param); 50 | else if (keycode == KEY_V) 51 | change_cam(param); 52 | } 53 | 54 | int key_pressed(int keycode, t_data *param) 55 | { 56 | param->key = keycode; 57 | key_pressed_ifs(keycode, param); 58 | calculate_rotation(param); 59 | calculate_vectors(param); 60 | copy_cam(param); 61 | return (0); 62 | } 63 | -------------------------------------------------------------------------------- /libft/Makefile: -------------------------------------------------------------------------------- 1 | NAME = libft.a 2 | CC = gcc 3 | CFLAGS = -Wall -Werror -Wextra -I. -c 4 | 5 | SRC = ft_memset.c \ 6 | ft_bzero.c \ 7 | ft_memcpy.c \ 8 | ft_memccpy.c \ 9 | ft_memmove.c \ 10 | ft_memchr.c \ 11 | ft_memcmp.c \ 12 | ft_strlen.c \ 13 | ft_strlcpy.c\ 14 | ft_strlcat.c \ 15 | ft_strchr.c \ 16 | ft_strchr.c \ 17 | ft_strrchr.c \ 18 | ft_strnstr.c \ 19 | ft_strncmp.c \ 20 | ft_atoi.c \ 21 | ft_isalpha.c \ 22 | ft_isdigit.c \ 23 | ft_isalnum.c \ 24 | ft_isascii.c \ 25 | ft_isprint.c \ 26 | ft_toupper.c \ 27 | ft_tolower.c \ 28 | ft_calloc.c \ 29 | ft_strdup.c\ 30 | ft_itoa.c\ 31 | ft_putchar_fd.c\ 32 | ft_putendl_fd.c\ 33 | ft_putnbr_fd.c\ 34 | ft_putstr_fd.c\ 35 | ft_split.c\ 36 | ft_strjoin.c\ 37 | ft_strmapi.c\ 38 | ft_strtrim.c\ 39 | ft_substr.c\ 40 | 41 | SRC2 = ft_lstnew.c\ 42 | ft_lstadd_front.c\ 43 | ft_lstnew.c\ 44 | ft_lstsize.c\ 45 | ft_lstlast.c\ 46 | ft_lstlast.c\ 47 | ft_lstadd_back.c\ 48 | ft_lstdelone.c\ 49 | ft_lstclear.c\ 50 | ft_lstiter.c\ 51 | ft_lstmap.c\ 52 | 53 | OBJ = $(SRC:.c=.o) 54 | 55 | OBJ2 = $(SRC2:.c=.o) 56 | 57 | all: $(NAME) 58 | 59 | $(NAME): $(OBJ) 60 | @ar rc $(NAME) $(OBJ) 61 | @ranlib $(NAME) 62 | 63 | clean: 64 | @rm -f $(OBJ) $(OBJ2) 65 | 66 | fclean: clean 67 | @rm -f $(NAME) 68 | 69 | re: fclean all 70 | 71 | bonus: $(OBJ) $(OBJ2) 72 | @ar rc $(NAME) $(OBJ) $(OBJ2) 73 | @ranlib $(NAME) 74 | 75 | .PHONY: clean fclean all re bonus 76 | -------------------------------------------------------------------------------- /libft/ft_atoi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_atoi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/01 08:34:36 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/11 10:50:22 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | /* 16 | ** result_neg_i 17 | */ 18 | 19 | int ft_atoi(const char *str) 20 | { 21 | long long int var[3]; 22 | 23 | var[0] = 0; 24 | var[1] = 1; 25 | var[2] = 0; 26 | while (str[var[2]] == 32 || (9 <= str[var[2]] && str[var[2]] <= 13)) 27 | var[2]++; 28 | if (str[var[2]] == '-' || str[var[2]] == '+') 29 | var[1] = (str[var[2]++] == '-') ? -1 : 1; 30 | while (str[var[2]]) 31 | { 32 | if (str[var[2]] < 48 || 57 < str[var[2]]) 33 | return (var[0] * var[1]); 34 | else 35 | var[0] = (var[0] * 10) + (long long int)(str[var[2]] - '0'); 36 | if (var[0] < -2147483648) 37 | return (1); 38 | else if (2147483648 < var[0]) 39 | return (0); 40 | var[2]++; 41 | } 42 | return ((long int)(var[0] * var[1])); 43 | } 44 | -------------------------------------------------------------------------------- /libft/ft_bzero.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_bzero.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/03/31 18:22:07 by marvin #+# #+# */ 9 | /* Updated: 2020/07/10 10:07:16 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "libft.h" 15 | 16 | void ft_bzero(void *s, size_t n) 17 | { 18 | size_t i; 19 | 20 | i = 0; 21 | while (i < n) 22 | { 23 | ((char *)s)[i] = '\0'; 24 | i++; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /libft/ft_calloc.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_calloc.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/01 08:53:09 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/08 12:18:53 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "libft.h" 15 | 16 | void *ft_calloc(size_t nmemb, size_t size) 17 | { 18 | unsigned char *ptr; 19 | 20 | if (!(ptr = malloc(nmemb * size))) 21 | return (NULL); 22 | ft_memset(ptr, 0, nmemb * size); 23 | return ((void *)ptr); 24 | } 25 | -------------------------------------------------------------------------------- /libft/ft_isalnum.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalnum.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/01 08:54:22 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/01 08:54:38 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_isalnum(int c) 16 | { 17 | if ((('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')) 18 | || ('0' <= c && c <= '9')) 19 | return (8); 20 | else 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /libft/ft_isalpha.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalpha.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/01 08:55:18 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/08 10:40:26 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_isalpha(int c) 16 | { 17 | if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')) 18 | return (1); 19 | else 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /libft/ft_isascii.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isascii1.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/01 08:56:00 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/01 08:56:01 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_isascii(int c) 16 | { 17 | if (0 <= c && c <= 127) 18 | return (1); 19 | else 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /libft/ft_isdigit.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isdigit.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/01 08:56:41 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/08 10:40:59 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_isdigit(int c) 16 | { 17 | if ('0' <= c && c <= '9') 18 | return (1); 19 | else 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /libft/ft_isprint.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isprint.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/01 08:57:13 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/08 10:46:58 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_isprint(int c) 16 | { 17 | if (32 <= c && c < 127) 18 | return (1); 19 | else 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /libft/ft_itoa.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_itoa.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/01 12:22:12 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/11 10:50:59 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "libft.h" 15 | 16 | static void itoa_isnegative(int *n, int *negative) 17 | { 18 | if (*n < 0) 19 | { 20 | *n *= -1; 21 | *negative = 1; 22 | } 23 | } 24 | 25 | char *ft_itoa(int n) 26 | { 27 | int tmpn; 28 | int len; 29 | int negative; 30 | char *str; 31 | 32 | if (n == -2147483648) 33 | return (ft_strdup("-2147483648")); 34 | tmpn = n; 35 | len = 2; 36 | negative = 0; 37 | itoa_isnegative(&n, &negative); 38 | while (tmpn /= 10) 39 | len++; 40 | len += negative; 41 | if ((str = (char*)malloc(sizeof(char) * len)) == NULL) 42 | return (NULL); 43 | str[--len] = '\0'; 44 | while (len--) 45 | { 46 | str[len] = n % 10 + '0'; 47 | n = n / 10; 48 | } 49 | if (negative) 50 | str[0] = '-'; 51 | return (str); 52 | } 53 | -------------------------------------------------------------------------------- /libft/ft_lstadd_back.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstadd_back.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/06 12:02:45 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/11 10:51:14 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstadd_back(t_list **alst, t_list *new) 16 | { 17 | t_list *head; 18 | 19 | if (!alst || !new) 20 | return ; 21 | if (*alst) 22 | { 23 | head = *alst; 24 | while (head->next) 25 | head = head->next; 26 | head->next = new; 27 | } 28 | else 29 | *alst = new; 30 | } 31 | -------------------------------------------------------------------------------- /libft/ft_lstadd_front.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstadd_front.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/06 12:41:26 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/10 09:56:15 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstadd_front(t_list **alst, t_list *new) 16 | { 17 | if (!alst || !new) 18 | return ; 19 | new->next = *alst; 20 | *alst = new; 21 | } 22 | -------------------------------------------------------------------------------- /libft/ft_lstclear.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstclear.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/07 09:07:09 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/10 09:40:08 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstclear(t_list **lst, void (*del)(void *)) 16 | { 17 | t_list *aux; 18 | 19 | if (!lst || !(*lst) || !del) 20 | return ; 21 | while ((*lst)) 22 | { 23 | aux = *lst; 24 | del((*lst)->content); 25 | (*lst) = (*lst)->next; 26 | free(aux); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /libft/ft_lstdelone.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstdelone.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/07 09:07:34 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/09 13:40:23 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstdelone(t_list *lst, void (*del)(void *)) 16 | { 17 | if (!lst) 18 | return ; 19 | if (del) 20 | del(lst->content); 21 | free(lst); 22 | } 23 | -------------------------------------------------------------------------------- /libft/ft_lstiter.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstiter1.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/07 09:07:51 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/07 09:07:52 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_lstiter(t_list *lst, void (*f)(void *)) 16 | { 17 | while (lst) 18 | { 19 | f(lst->content); 20 | lst = lst->next; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /libft/ft_lstlast.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstlast.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/07 09:08:11 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/10 09:44:18 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | t_list *ft_lstlast(t_list *lst) 16 | { 17 | t_list *head; 18 | 19 | if (!lst || !(lst->content)) 20 | return (NULL); 21 | head = lst; 22 | while (head->next) 23 | head = head->next; 24 | return (head); 25 | } 26 | -------------------------------------------------------------------------------- /libft/ft_lstmap.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstmap.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/07 09:08:30 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/07 12:31:21 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) 16 | { 17 | t_list *head; 18 | t_list *last; 19 | 20 | if (!lst || !(lst->content)) 21 | return (NULL); 22 | head = ft_lstnew(f(lst->content)); 23 | last = head; 24 | while (lst->next) 25 | { 26 | lst = lst->next; 27 | if (!(last->next = ft_lstnew(f(lst->content)))) 28 | { 29 | while (head) 30 | { 31 | del(head->content); 32 | head = head->next; 33 | } 34 | return (NULL); 35 | } 36 | last = last->next; 37 | last->content = f(lst->content); 38 | } 39 | return (head); 40 | } 41 | -------------------------------------------------------------------------------- /libft/ft_lstnew.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstnew.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/06 11:36:19 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/10 10:05:39 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | #include 15 | 16 | t_list *ft_lstnew(void *content) 17 | { 18 | t_list *head; 19 | 20 | if (!(head = (t_list *)malloc(sizeof(t_list)))) 21 | return (NULL); 22 | head->content = content; 23 | head->next = NULL; 24 | return (head); 25 | } 26 | -------------------------------------------------------------------------------- /libft/ft_lstsize.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstsize.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/07 09:08:52 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/10 10:04:41 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_lstsize(t_list *lst) 16 | { 17 | t_list *head; 18 | int i; 19 | 20 | if (!lst || !(lst->content)) 21 | return (0); 22 | head = lst; 23 | i = 0; 24 | while (head) 25 | { 26 | head = head->next; 27 | i++; 28 | } 29 | return (i); 30 | } 31 | -------------------------------------------------------------------------------- /libft/ft_memccpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memccpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/04/03 12:39:03 by marvin #+# #+# */ 9 | /* Updated: 2020/06/30 19:29:07 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "libft.h" 15 | 16 | void *ft_memccpy(void *dest, const void *src, int c, size_t n) 17 | { 18 | unsigned char *source; 19 | unsigned char *destination; 20 | size_t i; 21 | 22 | source = (unsigned char *)src; 23 | destination = (unsigned char *)dest; 24 | i = 0; 25 | while (i < n) 26 | { 27 | destination[i] = source[i]; 28 | if (source[i] == (unsigned char)c) 29 | return (dest + i + 1); 30 | i++; 31 | } 32 | return (NULL); 33 | } 34 | -------------------------------------------------------------------------------- /libft/ft_memchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/01 08:58:18 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/10 10:07:44 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "libft.h" 15 | 16 | void *ft_memchr(const void *s, int c, size_t n) 17 | { 18 | unsigned char *v; 19 | size_t i; 20 | 21 | v = (unsigned char *)s; 22 | i = 0; 23 | while (i < n) 24 | { 25 | if (v[i] == (unsigned char)c) 26 | return ((void *)&v[i]); 27 | i++; 28 | } 29 | return (NULL); 30 | } 31 | -------------------------------------------------------------------------------- /libft/ft_memcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/01 08:58:54 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/10 10:07:58 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "libft.h" 15 | 16 | int ft_memcmp(const void *s1, const void *s2, size_t n) 17 | { 18 | unsigned char *v1; 19 | unsigned char *v2; 20 | 21 | v1 = (unsigned char *)s1; 22 | v2 = (unsigned char *)s2; 23 | while (0 < n--) 24 | if (*(v1++) != *(v2++)) 25 | return (*(--v1) - *(--v2)); 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /libft/ft_memcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memcpy1.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/01 08:59:20 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/01 08:59:22 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "libft.h" 15 | 16 | void *ft_memcpy(void *dest, const void *src, size_t n) 17 | { 18 | unsigned char *str1; 19 | unsigned char *str2; 20 | 21 | str1 = (unsigned char *)dest; 22 | str2 = (unsigned char *)src; 23 | if (!n || dest == src) 24 | return (dest); 25 | while (0 < n--) 26 | *(str1++) = *(str2++); 27 | return (dest); 28 | } 29 | -------------------------------------------------------------------------------- /libft/ft_memmove.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memmove.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/01 08:59:50 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/11 10:52:16 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "libft.h" 15 | 16 | void *ft_memmove(void *dest, const void *src, size_t n) 17 | { 18 | if (dest == NULL && src == NULL) 19 | return (NULL); 20 | if (dest < src) 21 | ft_memcpy(dest, src, n); 22 | else 23 | while (n--) 24 | *(unsigned char *)(dest + n) = *(unsigned char *)(src + n); 25 | return (dest); 26 | } 27 | -------------------------------------------------------------------------------- /libft/ft_memset.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memset.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/06/29 11:58:30 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/10 10:07:01 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "libft.h" 15 | 16 | void *ft_memset(void *str, int c, size_t n) 17 | { 18 | unsigned char *ptr; 19 | 20 | ptr = (unsigned char *)str; 21 | while (0 < n--) 22 | *(ptr++) = (unsigned char)c; 23 | return (str); 24 | } 25 | -------------------------------------------------------------------------------- /libft/ft_putchar_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putchar_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/06 08:42:30 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/06 08:49:19 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "libft.h" 15 | 16 | void ft_putchar_fd(char c, int fd) 17 | { 18 | write(fd, &c, 1); 19 | } 20 | -------------------------------------------------------------------------------- /libft/ft_putendl_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putendl_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/06 08:44:38 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/09 12:42:11 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "libft.h" 15 | 16 | void ft_putendl_fd(char *s, int fd) 17 | { 18 | int i; 19 | char n; 20 | 21 | if (!s || !fd) 22 | return ; 23 | i = 0; 24 | n = '\n'; 25 | while (s[i]) 26 | { 27 | write(fd, &s[i], 1); 28 | i++; 29 | } 30 | write(fd, &n, 1); 31 | } 32 | -------------------------------------------------------------------------------- /libft/ft_putnbr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnbr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/06 08:46:47 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/11 10:52:37 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putnbr_fd(int n, int fd) 16 | { 17 | if (n == -2147483648) 18 | ft_putstr_fd("-2147483648", fd); 19 | else 20 | { 21 | if (n < 0) 22 | { 23 | ft_putchar_fd('-', fd); 24 | n = -n; 25 | } 26 | if (n > 9) 27 | { 28 | ft_putnbr_fd(n / 10, fd); 29 | ft_putchar_fd((n % 10) + '0', fd); 30 | } 31 | else 32 | ft_putchar_fd((n + '0'), fd); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /libft/ft_putstr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/06 08:58:01 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/09 12:40:20 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "libft.h" 15 | 16 | void ft_putstr_fd(char *s, int fd) 17 | { 18 | int i; 19 | 20 | if (!s || !fd) 21 | return ; 22 | i = 0; 23 | while (s[i]) 24 | { 25 | write(fd, &s[i], 1); 26 | i++; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /libft/ft_split.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_split.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/06 08:53:03 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/11 10:52:52 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include "libft.h" 16 | 17 | static int number_str(char *s, char c) 18 | { 19 | int n_str; 20 | int check; 21 | int i; 22 | 23 | n_str = 0; 24 | check = 0; 25 | i = -1; 26 | if (s[0] == '\0') 27 | return (0); 28 | while (s[++i] != '\0') 29 | { 30 | if (s[i] == c) 31 | check = 0; 32 | else if (check++ == 0) 33 | n_str++; 34 | } 35 | return (n_str); 36 | } 37 | 38 | static char **free_ptr(char **ptr, int i) 39 | { 40 | while (--i >= 0) 41 | free(ptr[i]); 42 | free(ptr); 43 | return (ptr); 44 | } 45 | 46 | static char **pass_values(char **ptr, char *s, char c, int n_str) 47 | { 48 | int i; 49 | int j; 50 | int k; 51 | 52 | i = -1; 53 | j = 0; 54 | while (j < n_str) 55 | { 56 | if (s[++i] != c) 57 | { 58 | k = 0; 59 | while (s[i] != c && s[i] != '\0') 60 | ptr[j][k++] = s[i++]; 61 | ptr[j][k] = '\0'; 62 | j++; 63 | } 64 | } 65 | ptr[j] = NULL; 66 | return (ptr); 67 | } 68 | 69 | static char **set_ptr(char **ptr, char *s, char c, int n_str) 70 | { 71 | int i; 72 | int j; 73 | int size; 74 | 75 | i = -1; 76 | j = 0; 77 | while (j < n_str) 78 | { 79 | if (s[++i] != c) 80 | { 81 | size = 0; 82 | while (s[i + size] != c && s[i + size] != '\0') 83 | size++; 84 | ptr[j] = (char *)malloc(size + 1); 85 | if (!ptr[j]) 86 | return (free_ptr(ptr, j)); 87 | i += size; 88 | j++; 89 | } 90 | } 91 | ptr = pass_values(ptr, s, c, n_str); 92 | return (ptr); 93 | } 94 | 95 | char **ft_split(char const *s, char c) 96 | { 97 | char **ptr; 98 | int n_str; 99 | 100 | if (!s) 101 | return (NULL); 102 | n_str = number_str((char *)s, c); 103 | ptr = (char **)malloc(sizeof(char *) * (n_str + 1)); 104 | if (!ptr) 105 | return (NULL); 106 | ptr = set_ptr(ptr, (char *)s, c, n_str); 107 | return (ptr); 108 | } 109 | -------------------------------------------------------------------------------- /libft/ft_strchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/01 09:00:22 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/10 10:08:38 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "libft.h" 15 | 16 | char *ft_strchr(const char *s, int c) 17 | { 18 | char *str; 19 | 20 | str = (char *)s; 21 | while (*str != c) 22 | { 23 | if (*str == '\0') 24 | return (NULL); 25 | str++; 26 | } 27 | return (str); 28 | } 29 | -------------------------------------------------------------------------------- /libft/ft_strdup.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strdup.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/01 09:01:23 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/10 10:36:25 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "libft.h" 15 | 16 | char *ft_strdup(const char *s) 17 | { 18 | char *ptr; 19 | int size; 20 | int i; 21 | 22 | size = 0; 23 | while (s[size]) 24 | size++; 25 | if (!(ptr = (char *)malloc(sizeof(char) * (size + 1)))) 26 | return (NULL); 27 | i = 0; 28 | while (s[i]) 29 | { 30 | ptr[i] = s[i]; 31 | i++; 32 | } 33 | ptr[i] = '\0'; 34 | return (ptr); 35 | } 36 | -------------------------------------------------------------------------------- /libft/ft_strjoin.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strjoin.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/06 08:54:38 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/09 22:30:14 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "libft.h" 15 | 16 | char *ft_strjoin(char const *s1, char const *s2) 17 | { 18 | int i; 19 | int len1; 20 | int len2; 21 | char *str; 22 | 23 | if (s1 && s2) 24 | { 25 | len1 = ft_strlen(s1); 26 | len2 = ft_strlen(s2); 27 | if (!(str = (char*)malloc(sizeof(char) * (len1 + len2 + 1)))) 28 | return (NULL); 29 | i = -1; 30 | while (s1[++i]) 31 | str[i] = s1[i]; 32 | i = -1; 33 | while (s2[++i]) 34 | { 35 | str[len1] = s2[i]; 36 | len1++; 37 | } 38 | str[len1] = '\0'; 39 | return (str); 40 | } 41 | return (NULL); 42 | } 43 | -------------------------------------------------------------------------------- /libft/ft_strlcat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/01 09:02:17 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/10 10:10:40 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "libft.h" 15 | 16 | size_t ft_strlcat(char *dst, const char *src, size_t size) 17 | { 18 | size_t len; 19 | size_t len1; 20 | size_t i; 21 | 22 | len = ft_strlen(src); 23 | len1 = ft_strlen(dst); 24 | i = 0; 25 | if (size <= len1) 26 | return (len + size); 27 | else 28 | len += len1; 29 | while (src[i] != 0 && len1 + 1 < size) 30 | { 31 | dst[len1] = src[i]; 32 | len1++; 33 | i++; 34 | } 35 | dst[len1] = 0; 36 | return (len); 37 | } 38 | -------------------------------------------------------------------------------- /libft/ft_strlcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/01 09:02:45 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/08 10:49:19 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "libft.h" 15 | 16 | size_t ft_strlcpy(char *dest, const char *src, size_t n) 17 | { 18 | size_t length_src; 19 | size_t i; 20 | 21 | if (!dest || !src) 22 | return (0); 23 | length_src = 0; 24 | while (src[length_src]) 25 | length_src++; 26 | if (n) 27 | { 28 | i = -1; 29 | if (length_src + 1 < n) 30 | while (++i < length_src) 31 | dest[i] = src[i]; 32 | else 33 | while (++i < n - 1) 34 | dest[i] = src[i]; 35 | dest[i] = '\0'; 36 | } 37 | return (length_src); 38 | } 39 | -------------------------------------------------------------------------------- /libft/ft_strlen.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlen.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/01 09:03:12 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/10 10:08:14 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "libft.h" 15 | 16 | size_t ft_strlen(const char *s) 17 | { 18 | size_t len; 19 | 20 | len = 0; 21 | while (s[len] != 0) 22 | len++; 23 | return (len); 24 | } 25 | -------------------------------------------------------------------------------- /libft/ft_strmapi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strmapi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/06 08:55:12 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/08 13:30:25 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "libft.h" 15 | 16 | char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) 17 | { 18 | char *res; 19 | int len; 20 | int i; 21 | 22 | if (!s || !f) 23 | return (NULL); 24 | len = ft_strlen(s); 25 | if (!(res = (char *)malloc(sizeof(char) * len + 1))) 26 | return (NULL); 27 | i = -1; 28 | while (s[++i]) 29 | res[i] = f(i, s[i]); 30 | res[i] = 0; 31 | return (res); 32 | } 33 | -------------------------------------------------------------------------------- /libft/ft_strncmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strncmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/01 09:04:14 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/10 10:09:21 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "libft.h" 15 | 16 | int ft_strncmp(const char *s1, const char *s2, size_t n) 17 | { 18 | unsigned char *c1; 19 | unsigned char *c2; 20 | 21 | c1 = (unsigned char *)s1; 22 | c2 = (unsigned char *)s2; 23 | while (0 < n--) 24 | { 25 | if (*(c1++) != *(c2++)) 26 | return (*(--c1) - *(--c2)); 27 | else if (!(*c1) || !(*c2)) 28 | return (*(c1) - *(c2)); 29 | } 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /libft/ft_strnstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strnstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/01 09:04:45 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/10 10:40:08 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "libft.h" 15 | 16 | char *ft_strnstr(const char *s1, const char *s2, size_t n) 17 | { 18 | size_t len; 19 | 20 | if (*s2 == '\0') 21 | return ((char *)s1); 22 | len = ft_strlen(s2); 23 | while (*s1 != '\0' && n-- >= len) 24 | { 25 | if (*s1 == *s2 && ft_memcmp(s1, s2, len) == 0) 26 | return ((char *)s1); 27 | s1++; 28 | } 29 | return (NULL); 30 | } 31 | -------------------------------------------------------------------------------- /libft/ft_strrchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strrchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/01 09:14:28 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/10 10:08:55 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "libft.h" 15 | 16 | char *ft_strrchr(const char *s, int c) 17 | { 18 | char *s1; 19 | int len; 20 | 21 | s1 = (char *)s; 22 | len = 0; 23 | while (s1[len]) 24 | len++; 25 | while (s1[len] != c && len != 0) 26 | len--; 27 | if (s1[len] == c) 28 | return (&s1[len]); 29 | else 30 | return (NULL); 31 | } 32 | -------------------------------------------------------------------------------- /libft/ft_strtrim.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strtrim.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/01 13:27:02 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/09 22:57:18 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include "libft.h" 16 | 17 | static int ef_check_set(char c, char *set) 18 | { 19 | size_t set_length; 20 | size_t i; 21 | 22 | set_length = ft_strlen(set); 23 | i = 0; 24 | while (i <= set_length) 25 | { 26 | if (c == set[i]) 27 | return (1); 28 | i++; 29 | } 30 | return (0); 31 | } 32 | 33 | static int check_same_set(char const *s1, char *set) 34 | { 35 | int i; 36 | 37 | i = -1; 38 | while (s1[++i]) 39 | if (ef_check_set(s1[i], set) == 0) 40 | return (0); 41 | return (1); 42 | } 43 | 44 | char *ft_strtrim(char const *s1, char const *set) 45 | { 46 | int start; 47 | int end; 48 | char *ptr; 49 | 50 | if (!s1 || !set) 51 | return (NULL); 52 | if (check_same_set(s1, (char *)set) == 1) 53 | return (ft_strdup("")); 54 | start = 0; 55 | end = ft_strlen(s1); 56 | while (ef_check_set(s1[start], (char *)set)) 57 | start++; 58 | while (ef_check_set(s1[end], (char *)set) && end >= 0) 59 | end--; 60 | if (end < start) 61 | return (ft_strdup("")); 62 | if (!(ptr = (char *)malloc(end - start + 2))) 63 | return (NULL); 64 | ft_strlcpy(ptr, s1 + start, end - start + 2); 65 | return (ptr); 66 | } 67 | -------------------------------------------------------------------------------- /libft/ft_substr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_substr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/06 08:56:46 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/11 10:50:06 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "libft.h" 15 | 16 | char *ft_substr(char const *s, unsigned int start, size_t len) 17 | { 18 | char *ptr; 19 | unsigned int i; 20 | 21 | if (!s) 22 | return (NULL); 23 | i = 0; 24 | while (((char *)s)[i] != '\0') 25 | i++; 26 | if (i < start) 27 | return (ft_strdup("")); 28 | ptr = (char *)malloc(len + 1); 29 | if (!ptr) 30 | return (NULL); 31 | i = 0; 32 | while (i < len) 33 | ptr[i++] = ((char *)s)[start++]; 34 | ptr[i] = '\0'; 35 | return (ptr); 36 | } 37 | -------------------------------------------------------------------------------- /libft/ft_tolower.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_tolower1.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/01 09:15:43 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/01 09:15:50 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_tolower(int c) 16 | { 17 | if ('A' <= c && c <= 'Z') 18 | return (c + 32); 19 | else 20 | return (c); 21 | } 22 | -------------------------------------------------------------------------------- /libft/ft_toupper.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_toupper1.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/07/01 09:16:24 by jserrano #+# #+# */ 9 | /* Updated: 2020/07/01 09:16:25 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_toupper(int c) 16 | { 17 | if ('a' <= c && c <= 'z') 18 | return (c - 32); 19 | else 20 | return (c); 21 | } 22 | -------------------------------------------------------------------------------- /main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/11/05 14:53:01 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/05 15:03:26 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "raymarching.h" 14 | 15 | static void ft_hooks(t_data *param) 16 | { 17 | mlx_hook(param->win_id, KEY_PR, MK_KEY_PR, key_pressed, param); 18 | mlx_hook(param->win_id, BUT_PR, MK_BUT_PR, button_pressed, param); 19 | mlx_hook(param->win_id, BUT_RE, MK_BUT_RE, button_released, param); 20 | mlx_hook(param->win_id, MOT_NT, MK_PTR_MO, get_pos, param); 21 | mlx_hook(param->win_id, CLI_MG, CL_CLOSE, ft_exit, param); 22 | mlx_loop_hook(param->id, show_obj, param); 23 | } 24 | 25 | static void main_ifs(t_data *param, int argc, char **argv) 26 | { 27 | if (argc == 3) 28 | { 29 | if (!ft_memcmp(argv[2], "--save", 7)) 30 | save_scr(param); 31 | else 32 | write(1, "Enter --save if you want to save a screenshot\n", 47); 33 | ft_exit(param); 34 | } 35 | mlx_loop(param->id); 36 | } 37 | 38 | int main(int argc, char **argv) 39 | { 40 | t_data *param; 41 | int i; 42 | 43 | if (argc == 2 || argc == 3) 44 | { 45 | i = ft_strlen(argv[1]); 46 | if (ft_memcmp(argv[1] + i - 3, ".rt", 3)) 47 | { 48 | write(1, "Please insert correct .rt file\n", 32); 49 | return (-1); 50 | } 51 | param = (t_data *)malloc(sizeof(t_data)); 52 | ft_init(param, argv); 53 | ft_hooks(param); 54 | main_ifs(param, argc, argv); 55 | } 56 | else 57 | write(1, "Wrong number of arguments!\n", 28); 58 | return (0); 59 | } 60 | -------------------------------------------------------------------------------- /minilibx-linux-master/Makefile: -------------------------------------------------------------------------------- 1 | ## 2 | ## Makefile for MiniLibX in /home/boulon/work/c/raytraceur/minilibx 3 | ## 4 | ## Made by Olivier Crouzet 5 | ## Login 6 | ## 7 | ## Started on Tue Oct 5 15:56:43 2004 Olivier Crouzet 8 | ## Last update Tue May 15 15:44:41 2007 Olivier Crouzet 9 | ## 10 | 11 | ## Please use configure script 12 | 13 | 14 | all : do_configure 15 | 16 | do_configure : 17 | ./configure 18 | 19 | clean : 20 | ./configure clean 21 | 22 | re : clean all 23 | -------------------------------------------------------------------------------- /minilibx-linux-master/Makefile.gen: -------------------------------------------------------------------------------- 1 | INC=/usr/include 2 | HT=Linux 3 | DOCP=do_cp 4 | ## 5 | ## Makefile for MiniLibX in /home/boulon/work/c/raytraceur/minilibx 6 | ## 7 | ## Made by Olivier Crouzet 8 | ## Login 9 | ## 10 | ## Started on Tue Oct 5 15:56:43 2004 Olivier Crouzet 11 | ## Last update Tue May 15 15:41:20 2007 Olivier Crouzet 12 | ## 13 | 14 | ## Please use configure script 15 | 16 | 17 | 18 | CC = gcc 19 | 20 | NAME = libmlx.a 21 | 22 | SRC = mlx_init.c mlx_new_window.c mlx_pixel_put.c mlx_loop.c \ 23 | mlx_mouse_hook.c mlx_key_hook.c mlx_expose_hook.c mlx_loop_hook.c \ 24 | mlx_int_anti_resize_win.c mlx_int_do_nothing.c \ 25 | mlx_int_wait_first_expose.c mlx_int_get_visual.c \ 26 | mlx_flush_event.c mlx_string_put.c mlx_set_font.c \ 27 | mlx_new_image.c mlx_get_data_addr.c \ 28 | mlx_put_image_to_window.c mlx_get_color_value.c mlx_clear_window.c \ 29 | mlx_xpm.c mlx_int_str_to_wordtab.c mlx_destroy_window.c \ 30 | mlx_int_param_event.c mlx_int_set_win_event_mask.c mlx_hook.c \ 31 | mlx_rgb.c mlx_destroy_image.c mlx_mouse.c mlx_screen_size.c \ 32 | mlx_destroy_display.c 33 | 34 | OBJ =$(SRC:.c=.o) 35 | CFLAGS = -O3 -I$(INC) 36 | 37 | all : $(NAME) $(DOCP) 38 | 39 | $(NAME) : $(OBJ) 40 | ar -r $(NAME) $(OBJ) 41 | ranlib $(NAME) 42 | 43 | do_cp : 44 | cp $(NAME) libmlx_$(HT).a 45 | 46 | 47 | clean : 48 | rm -f $(OBJ) $(NAME) libmlx_$(HT).a *~ core *.core 49 | -------------------------------------------------------------------------------- /minilibx-linux-master/Makefile.mk: -------------------------------------------------------------------------------- 1 | ## 2 | ## Makefile for MiniLibX in /home/boulon/work/c/raytraceur/minilibx 3 | ## 4 | ## Made by Olivier Crouzet 5 | ## Login 6 | ## 7 | ## Started on Tue Oct 5 15:56:43 2004 Olivier Crouzet 8 | ## Last update Tue May 15 15:41:20 2007 Olivier Crouzet 9 | ## 10 | 11 | ## Please use configure script 12 | 13 | 14 | INC =%%%% 15 | HT =%%%% 16 | DOCP =%%%% 17 | 18 | CC = gcc 19 | 20 | NAME = libmlx.a 21 | 22 | SRC = mlx_init.c mlx_new_window.c mlx_pixel_put.c mlx_loop.c \ 23 | mlx_mouse_hook.c mlx_key_hook.c mlx_expose_hook.c mlx_loop_hook.c \ 24 | mlx_int_anti_resize_win.c mlx_int_do_nothing.c \ 25 | mlx_int_wait_first_expose.c mlx_int_get_visual.c \ 26 | mlx_flush_event.c mlx_string_put.c mlx_set_font.c \ 27 | mlx_new_image.c mlx_get_data_addr.c \ 28 | mlx_put_image_to_window.c mlx_get_color_value.c mlx_clear_window.c \ 29 | mlx_xpm.c mlx_int_str_to_wordtab.c mlx_destroy_window.c \ 30 | mlx_int_param_event.c mlx_int_set_win_event_mask.c mlx_hook.c \ 31 | mlx_rgb.c mlx_destroy_image.c mlx_mouse.c mlx_screen_size.c \ 32 | mlx_destroy_display.c 33 | 34 | OBJ =$(SRC:.c=.o) 35 | CFLAGS = -O3 -I$(INC) 36 | 37 | all : $(NAME) $(DOCP) 38 | 39 | $(NAME) : $(OBJ) 40 | ar -r $(NAME) $(OBJ) 41 | ranlib $(NAME) 42 | 43 | do_cp : 44 | cp $(NAME) libmlx_$(HT).a 45 | 46 | 47 | clean : 48 | rm -f $(OBJ) $(NAME) libmlx_$(HT).a *~ core *.core 49 | -------------------------------------------------------------------------------- /minilibx-linux-master/README.md: -------------------------------------------------------------------------------- 1 | 2 | This is the MinilibX, a simple X-Window (X11R6) programming API 3 | in C, designed for students, suitable for X-beginners. 4 | 5 | 6 | Contents 7 | 8 | - source code in C to create the mlx library 9 | - man pages (in man/ directory) 10 | - a test program (in test/ directory) is built 11 | with the library 12 | - a public include file mlx.h 13 | - a tiny configure script to generate an appropriate Makefile.gen 14 | 15 | 16 | Requirements 17 | 18 | - MinilibX only support TrueColor visual type (8,15,16,24 or 32 bits depth) 19 | - gcc 20 | - make 21 | - X11 include files (package xorg) 22 | - XShm extension must be present (package libxext-dev) 23 | - Utility functions from BSD systems - development files (package libbsd-dev) 24 | - **e.g. _sudo apt-get install gcc make xorg libxext-dev libbsd-dev_ (Debian/Ubuntu)** 25 | 26 | Compile MinilibX 27 | 28 | - run ./configure or make 29 | both will make a few tests, create Makefile.gen 30 | and then automatically run make on this generated Makefile.gen . 31 | libmlx.a and libmlx_$(HOSTTYPE).a are created. 32 | test/mlx-test binary is also created. 33 | 34 | 35 | Install MinilibX 36 | 37 | - no installation script is provided. You may want to install 38 | - libmlx.a and/or libmlx_$(HOSTTYPE).a in /usr/X11/lib or /usr/local/lib 39 | - mlx.h in /usr/X11/include or /usr/local/include 40 | - man/man3/mlx*.1 in /usr/X11/man/man3 or /usr/local/man/man3 41 | 42 | 43 | Olivier CROUZET - 2014-01-06 - 44 | -------------------------------------------------------------------------------- /minilibx-linux-master/configure: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | if [ -n "$1" -a "$1" = "--help" ] ; then 5 | echo "Usage : $0\n Auto-configure and make MinilibX" 6 | exit 7 | fi 8 | 9 | 10 | conf_inc=NO 11 | 12 | for inc in \ 13 | /usr/X11/include \ 14 | /usr/X11R6/include \ 15 | /usr/X11R5/include \ 16 | /usr/X11R4/include \ 17 | \ 18 | /usr/include \ 19 | /usr/include/X11 \ 20 | /usr/include/X11R6 \ 21 | /usr/include/X11R5 \ 22 | /usr/include/X11R4 \ 23 | \ 24 | /usr/local/X11/include \ 25 | /usr/local/X11R6/include \ 26 | /usr/local/X11R5/include \ 27 | /usr/local/X11R4/include \ 28 | \ 29 | /usr/local/include/X11 \ 30 | /usr/local/include/X11R6 \ 31 | /usr/local/include/X11R5 \ 32 | /usr/local/include/X11R4 \ 33 | \ 34 | /usr/X386/include \ 35 | /usr/x386/include \ 36 | /usr/XFree86/include/X11 \ 37 | \ 38 | /usr/include \ 39 | /usr/local/include \ 40 | /usr/athena/include \ 41 | /usr/local/x11r5/include \ 42 | /usr/lpp/Xamples/include \ 43 | \ 44 | /usr/openwin/include \ 45 | /usr/openwin/share/include 46 | do 47 | if [ -f "$inc/X11/Xlib.h" -a -f "$inc/X11/extensions/XShm.h" ]; then 48 | conf_inc=$inc 49 | break 50 | fi 51 | done 52 | 53 | 54 | if [ "$conf_inc" = "NO" ]; then 55 | echo "Can't find a suitable X11 include directory." 56 | exit 57 | else 58 | echo "X11 include dir : $conf_inc" 59 | fi 60 | 61 | if [ -z "$HOSTTYPE" ]; then 62 | conf_ht=`uname -s` 63 | else 64 | conf_ht=$HOSTTYPE 65 | fi 66 | 67 | if [ -z "$conf_ht" ]; then 68 | conf_docp="" 69 | else 70 | conf_docp="do_cp" 71 | echo "lib_$conf_ht generation" 72 | fi 73 | 74 | 75 | /bin/echo "INC=$conf_inc" > Makefile.gen 76 | /bin/echo "HT=$conf_ht" >> Makefile.gen 77 | /bin/echo "DOCP=$conf_docp" >> Makefile.gen 78 | cat Makefile.mk | grep -v %%%% >> Makefile.gen 79 | 80 | /bin/echo "INC=$conf_inc" > test/Makefile.gen 81 | /bin/echo "HT=$conf_ht" >> test/Makefile.gen 82 | /bin/echo "DOCP=$conf_docp" >> test/Makefile.gen 83 | cat test/Makefile.mk | grep -v %%%% >> test/Makefile.gen 84 | 85 | 86 | if [ -n "$1" -a "$1" = "clean" ] ; then 87 | echo "Now make it clean." 88 | make -f Makefile.gen clean 89 | (cd test ; make -f Makefile.gen clean) 90 | exit 91 | fi 92 | 93 | echo "Now make it." 94 | make -f Makefile.gen all 95 | (cd test ; make -f Makefile.gen all ) 96 | -------------------------------------------------------------------------------- /minilibx-linux-master/libmlx.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/libmlx.a -------------------------------------------------------------------------------- /minilibx-linux-master/libmlx_Linux.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/libmlx_Linux.a -------------------------------------------------------------------------------- /minilibx-linux-master/man/man1/mlx.1: -------------------------------------------------------------------------------- 1 | .TH MiniLibX 3 "September 19, 2002" 2 | .SH NAME 3 | MiniLibX - Simple X-Window Interface Library for students 4 | .SH SYNOPSYS 5 | #include 6 | 7 | .nf 8 | .I void * 9 | .fi 10 | .B mlx_init 11 | (); 12 | 13 | .SH DESCRIPTION 14 | MiniLibX is an easy way to create graphical software, 15 | without any X-Window programming knowledge. It provides 16 | simple window creation, a drawing tool, image and basic events 17 | management. 18 | 19 | .SH X-WINDOW CONCEPT 20 | 21 | X-Window is a network-oriented graphical system for Unix. 22 | It is based on two main parts: 23 | .br 24 | On one side, your software wants to draw something on the screen and/or 25 | get keyboard & mouse entries. 26 | .br 27 | On the other side, the X-Server manages the screen, keyboard and mouse 28 | (It is often refered to as a "display"). 29 | .br 30 | A network connection must be established between these two entities to send 31 | drawing orders (from the software to the X-Server), and keyboard/mouse 32 | events (from the X-Server to the software). 33 | 34 | .SH INCLUDE FILE 35 | .B mlx.h 36 | should be included for a correct use of the MiniLibX API. 37 | It only contains function prototypes, no structure is needed. 38 | 39 | .SH LIBRARY FUNCTIONS 40 | .P 41 | First of all, you need to initialize the connection 42 | between your software and the display. 43 | Once this connection is established, you'll be able to 44 | use other MiniLibX functions to send the X-Server messages, 45 | like "I want to draw a yellow pixel in this window" or "did the 46 | user hit a key?". 47 | .P 48 | The 49 | .B mlx_init 50 | function will create this connection. No parameters are needed, ant it will 51 | return a 52 | .I "void *" 53 | identifier, used for further calls to the library routines. 54 | .P 55 | All other MiniLibX functions are described in the following man pages: 56 | 57 | .TP 20 58 | .B mlx_new_window 59 | : manage windows 60 | .TP 20 61 | .B mlx_pixel_put 62 | : draw inside window 63 | .TP 20 64 | .B mlx_new_image 65 | : manipulate images 66 | .TP 20 67 | .B mlx_loop 68 | : handle keyboard or mouse events 69 | 70 | .SH LINKING MiniLibX 71 | To use MiniLibX functions, you'll need to link 72 | your software with several libraries, including the MiniLibX library itself. 73 | To do this, simply add the following arguments at linking time: 74 | 75 | .B -lmlx -lXext -lX11 76 | 77 | You may also need to specify the path to these libraries, using 78 | the 79 | .B -L 80 | flag. 81 | 82 | 83 | .SH RETURN VALUES 84 | If 85 | .B mlx_init() 86 | fails to set up the connection to the X server, it will return NULL, otherwise 87 | a non-null pointer is returned as a connection identifier. 88 | 89 | .SH SEE ALSO 90 | mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3) 91 | 92 | .SH AUTHOR 93 | Copyright ol@ - 2002-2014 - Olivier Crouzet 94 | -------------------------------------------------------------------------------- /minilibx-linux-master/man/man1/mlx_new_window.1: -------------------------------------------------------------------------------- 1 | .TH MiniLibX 3 "September 19, 2002" 2 | .SH NAME 3 | MiniLibX - Managing windows 4 | .SH SYNOPSYS 5 | 6 | .nf 7 | .I void * 8 | .fi 9 | .B mlx_new_window 10 | ( 11 | .I void *mlx_ptr, int size_x, int size_y, char *title 12 | ); 13 | 14 | .nf 15 | .I int 16 | .fi 17 | .B mlx_clear_window 18 | ( 19 | .I void *mlx_ptr, void *win_ptr 20 | ); 21 | 22 | .nf 23 | .I int 24 | .fi 25 | .B mlx_destroy_window 26 | ( 27 | .I void *mlx_ptr, void *win_ptr 28 | ); 29 | 30 | 31 | .SH DESCRIPTION 32 | The 33 | .B mlx_new_window 34 | () function creates a new window on the screen, using the 35 | .I size_x 36 | and 37 | .I size_y 38 | parameters to determine its size, and 39 | .I title 40 | as the text that should be displayed in the window's title bar. 41 | The 42 | .I mlx_ptr 43 | parameter is the connection identifier returned by 44 | .B mlx_init 45 | () (see the 46 | .B mlx 47 | man page). 48 | .B mlx_new_window 49 | () returns a 50 | .I void * 51 | window identifier that can be used by other MiniLibX calls. 52 | Note that the MiniLibX 53 | can handle an arbitrary number of separate windows. 54 | 55 | .B mlx_clear_window 56 | () and 57 | .B mlx_destroy_window 58 | () respectively clear (in black) and destroy the given window. They both have 59 | the same parameters: 60 | .I mlx_ptr 61 | is the screen connection identifier, and 62 | .I win_ptr 63 | is a window identifier. 64 | 65 | .SH RETURN VALUES 66 | If 67 | .B mlx_new_window() 68 | fails to create a new window (for wathever reason), it will return NULL, 69 | otherwise a non-null pointer is returned as a window identifier. 70 | .B mlx_clear_window 71 | and 72 | .B mlx_destroy_window 73 | right now return nothing. 74 | 75 | .SH SEE ALSO 76 | mlx(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3) 77 | 78 | .SH AUTHOR 79 | Copyright ol@ - 2002-2014 - Olivier Crouzet 80 | -------------------------------------------------------------------------------- /minilibx-linux-master/man/man1/mlx_pixel_put.1: -------------------------------------------------------------------------------- 1 | .TH MiniLibX 3 "September 19, 2002" 2 | .SH NAME 3 | MiniLibX - Drawing inside windows 4 | .SH SYNOPSYS 5 | 6 | .nf 7 | .I int 8 | .fi 9 | .B mlx_pixel_put 10 | ( 11 | .I void *mlx_ptr, void *win_ptr, int x, int y, int color 12 | ); 13 | 14 | .nf 15 | .I int 16 | .fi 17 | .B mlx_string_put 18 | ( 19 | .I void *mlx_ptr, void *win_ptr, int x, int y, int color, char *string 20 | ); 21 | 22 | 23 | .SH DESCRIPTION 24 | The 25 | .B mlx_pixel_put 26 | () function draws a defined pixel in the window 27 | .I win_ptr 28 | using the ( 29 | .I x 30 | , 31 | .I y 32 | ) coordinates, and the specified 33 | .I color 34 | \&. The origin (0,0) is the upper left corner of the window, the x and y axis 35 | respectively pointing right and down. The connection 36 | identifier, 37 | .I mlx_ptr 38 | , is needed (see the 39 | .B mlx 40 | man page). 41 | 42 | Parameters for 43 | .B mlx_string_put 44 | () have the same meaning. Instead of a simple pixel, the specified 45 | .I string 46 | will be displayed at ( 47 | .I x 48 | , 49 | .I y 50 | ). 51 | 52 | In both functions, it is impossible to display anything outside the 53 | specified window, nor display in another window in front of the selected one. 54 | 55 | .SH COLOR MANAGEMENT 56 | The 57 | .I color 58 | parameter has an integer type. The displayed color needs to be encoded 59 | in this integer, following a defined scheme. All displayable colors 60 | can be split in 3 basic colors: red, green and blue. Three associated 61 | values, in the 0-255 range, represent how much of each color is mixed up 62 | to create the original color. Theses three values must be set inside the 63 | integer to display the right color. The three least significant bytes of 64 | this integer are filled as shown in the picture below: 65 | 66 | .TS 67 | allbox; 68 | c s s s s 69 | r c c c c. 70 | Color Integer 71 | Interpretation \[*a] R G B 72 | Bit numbers 31..24 23..16 15..8 7..0 73 | .TE 74 | 75 | While filling the integer, make sure you avoid endian problems. Remember 76 | that the "blue" byte should always be the least significant one. 77 | 78 | 79 | .SH SEE ALSO 80 | mlx(3), mlx_new_window(3), mlx_new_image(3), mlx_loop(3) 81 | 82 | 83 | .SH AUTHOR 84 | Copyright ol@ - 2002-2014 - Olivier Crouzet 85 | -------------------------------------------------------------------------------- /minilibx-linux-master/man/man3/mlx.1: -------------------------------------------------------------------------------- 1 | .TH MiniLibX 3 "September 19, 2002" 2 | .SH NAME 3 | MiniLibX - Simple X-Window Interface Library for students 4 | .SH SYNOPSYS 5 | #include 6 | 7 | .nf 8 | .I void * 9 | .fi 10 | .B mlx_init 11 | (); 12 | 13 | .SH DESCRIPTION 14 | MiniLibX is an easy way to create graphical software, 15 | without any X-Window programming knowledge. It provides 16 | simple window creation, a drawing tool, image and basic events 17 | management. 18 | 19 | .SH X-WINDOW CONCEPT 20 | 21 | X-Window is a network-oriented graphical system for Unix. 22 | It is based on two main parts: 23 | .br 24 | On one side, your software wants to draw something on the screen and/or 25 | get keyboard & mouse entries. 26 | .br 27 | On the other side, the X-Server manages the screen, keyboard and mouse 28 | (It is often refered to as a "display"). 29 | .br 30 | A network connection must be established between these two entities to send 31 | drawing orders (from the software to the X-Server), and keyboard/mouse 32 | events (from the X-Server to the software). 33 | 34 | .SH INCLUDE FILE 35 | .B mlx.h 36 | should be included for a correct use of the MiniLibX API. 37 | It only contains function prototypes, no structure is needed. 38 | 39 | .SH LIBRARY FUNCTIONS 40 | .P 41 | First of all, you need to initialize the connection 42 | between your software and the display. 43 | Once this connection is established, you'll be able to 44 | use other MiniLibX functions to send the X-Server messages, 45 | like "I want to draw a yellow pixel in this window" or "did the 46 | user hit a key?". 47 | .P 48 | The 49 | .B mlx_init 50 | function will create this connection. No parameters are needed, ant it will 51 | return a 52 | .I "void *" 53 | identifier, used for further calls to the library routines. 54 | .P 55 | All other MiniLibX functions are described in the following man pages: 56 | 57 | .TP 20 58 | .B mlx_new_window 59 | : manage windows 60 | .TP 20 61 | .B mlx_pixel_put 62 | : draw inside window 63 | .TP 20 64 | .B mlx_new_image 65 | : manipulate images 66 | .TP 20 67 | .B mlx_loop 68 | : handle keyboard or mouse events 69 | 70 | .SH LINKING MiniLibX 71 | To use MiniLibX functions, you'll need to link 72 | your software with several libraries, including the MiniLibX library itself. 73 | To do this, simply add the following arguments at linking time: 74 | 75 | .B -lmlx -lXext -lX11 76 | 77 | You may also need to specify the path to these libraries, using 78 | the 79 | .B -L 80 | flag. 81 | 82 | 83 | .SH RETURN VALUES 84 | If 85 | .B mlx_init() 86 | fails to set up the connection to the X server, it will return NULL, otherwise 87 | a non-null pointer is returned as a connection identifier. 88 | 89 | .SH SEE ALSO 90 | mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3) 91 | 92 | .SH AUTHOR 93 | Copyright ol@ - 2002-2014 - Olivier Crouzet 94 | -------------------------------------------------------------------------------- /minilibx-linux-master/man/man3/mlx_new_window.1: -------------------------------------------------------------------------------- 1 | .TH MiniLibX 3 "September 19, 2002" 2 | .SH NAME 3 | MiniLibX - Managing windows 4 | .SH SYNOPSYS 5 | 6 | .nf 7 | .I void * 8 | .fi 9 | .B mlx_new_window 10 | ( 11 | .I void *mlx_ptr, int size_x, int size_y, char *title 12 | ); 13 | 14 | .nf 15 | .I int 16 | .fi 17 | .B mlx_clear_window 18 | ( 19 | .I void *mlx_ptr, void *win_ptr 20 | ); 21 | 22 | .nf 23 | .I int 24 | .fi 25 | .B mlx_destroy_window 26 | ( 27 | .I void *mlx_ptr, void *win_ptr 28 | ); 29 | 30 | 31 | .SH DESCRIPTION 32 | The 33 | .B mlx_new_window 34 | () function creates a new window on the screen, using the 35 | .I size_x 36 | and 37 | .I size_y 38 | parameters to determine its size, and 39 | .I title 40 | as the text that should be displayed in the window's title bar. 41 | The 42 | .I mlx_ptr 43 | parameter is the connection identifier returned by 44 | .B mlx_init 45 | () (see the 46 | .B mlx 47 | man page). 48 | .B mlx_new_window 49 | () returns a 50 | .I void * 51 | window identifier that can be used by other MiniLibX calls. 52 | Note that the MiniLibX 53 | can handle an arbitrary number of separate windows. 54 | 55 | .B mlx_clear_window 56 | () and 57 | .B mlx_destroy_window 58 | () respectively clear (in black) and destroy the given window. They both have 59 | the same parameters: 60 | .I mlx_ptr 61 | is the screen connection identifier, and 62 | .I win_ptr 63 | is a window identifier. 64 | 65 | .SH RETURN VALUES 66 | If 67 | .B mlx_new_window() 68 | fails to create a new window (for wathever reason), it will return NULL, 69 | otherwise a non-null pointer is returned as a window identifier. 70 | .B mlx_clear_window 71 | and 72 | .B mlx_destroy_window 73 | right now return nothing. 74 | 75 | .SH SEE ALSO 76 | mlx(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3) 77 | 78 | .SH AUTHOR 79 | Copyright ol@ - 2002-2014 - Olivier Crouzet 80 | -------------------------------------------------------------------------------- /minilibx-linux-master/man/man3/mlx_pixel_put.1: -------------------------------------------------------------------------------- 1 | .TH MiniLibX 3 "September 19, 2002" 2 | .SH NAME 3 | MiniLibX - Drawing inside windows 4 | .SH SYNOPSYS 5 | 6 | .nf 7 | .I int 8 | .fi 9 | .B mlx_pixel_put 10 | ( 11 | .I void *mlx_ptr, void *win_ptr, int x, int y, int color 12 | ); 13 | 14 | .nf 15 | .I int 16 | .fi 17 | .B mlx_string_put 18 | ( 19 | .I void *mlx_ptr, void *win_ptr, int x, int y, int color, char *string 20 | ); 21 | 22 | 23 | .SH DESCRIPTION 24 | The 25 | .B mlx_pixel_put 26 | () function draws a defined pixel in the window 27 | .I win_ptr 28 | using the ( 29 | .I x 30 | , 31 | .I y 32 | ) coordinates, and the specified 33 | .I color 34 | \&. The origin (0,0) is the upper left corner of the window, the x and y axis 35 | respectively pointing right and down. The connection 36 | identifier, 37 | .I mlx_ptr 38 | , is needed (see the 39 | .B mlx 40 | man page). 41 | 42 | Parameters for 43 | .B mlx_string_put 44 | () have the same meaning. Instead of a simple pixel, the specified 45 | .I string 46 | will be displayed at ( 47 | .I x 48 | , 49 | .I y 50 | ). 51 | 52 | In both functions, it is impossible to display anything outside the 53 | specified window, nor display in another window in front of the selected one. 54 | 55 | .SH COLOR MANAGEMENT 56 | The 57 | .I color 58 | parameter has an integer type. The displayed color needs to be encoded 59 | in this integer, following a defined scheme. All displayable colors 60 | can be split in 3 basic colors: red, green and blue. Three associated 61 | values, in the 0-255 range, represent how much of each color is mixed up 62 | to create the original color. Theses three values must be set inside the 63 | integer to display the right color. The three least significant bytes of 64 | this integer are filled as shown in the picture below: 65 | 66 | .nf 67 | | 0 | R | G | B | color integer 68 | +---+---+---+---+ 69 | .fi 70 | 71 | 72 | While filling the integer, make sure you avoid endian problems. Remember 73 | that the "blue" byte should always be the least significant one. 74 | 75 | 76 | .SH SEE ALSO 77 | mlx(3), mlx_new_window(3), mlx_new_image(3), mlx_loop(3) 78 | 79 | 80 | .SH AUTHOR 81 | Copyright ol@ - 2002-2014 - Olivier Crouzet 82 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_clear_window.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_clear_window.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Thu Sep 7 19:46:15 2000 Charlie Root 8 | ** Last update Tue Sep 25 17:11:19 2001 Charlie Root 9 | */ 10 | 11 | 12 | 13 | #include "mlx_int.h" 14 | 15 | 16 | int mlx_clear_window(t_xvar *xvar,t_win_list *win) 17 | { 18 | XClearWindow(xvar->display,win->window); 19 | if (xvar->do_flush) 20 | XFlush(xvar->display); 21 | } 22 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_clear_window.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_clear_window.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_destroy_display.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* mlx_destroy_display.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mg +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/03 18:56:35 by mg #+# #+# */ 9 | /* Updated: 2020/10/04 01:55:35 by mg ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "mlx_int.h" 14 | 15 | int mlx_destroy_display(t_xvar *xvar) 16 | { 17 | XCloseDisplay(xvar->display); 18 | } 19 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_destroy_display.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_destroy_display.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_destroy_image.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_destroy_image.c for MinilibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Tue Mar 12 10:25:15 2002 Charlie Root 8 | ** Last update Tue May 15 16:45:54 2007 Olivier Crouzet 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | int mlx_destroy_image(t_xvar *xvar, t_img *img) 16 | { 17 | if (img->type == MLX_TYPE_SHM_PIXMAP || 18 | img->type == MLX_TYPE_SHM) 19 | { 20 | XShmDetach(xvar->display, &(img->shm)); 21 | shmdt(img->shm.shmaddr); 22 | /* shmctl IPC_RMID already done */ 23 | } 24 | XDestroyImage(img->image); /* For image & shm-image. Also free img->data */ 25 | XFreePixmap(xvar->display, img->pix); 26 | if (img->gc) 27 | XFreeGC(xvar->display, img->gc); 28 | free(img); 29 | if (xvar->do_flush) 30 | XFlush(xvar->display); 31 | } 32 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_destroy_image.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_destroy_image.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_destroy_window.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_destroy_window.c for MinilibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Tue Mar 12 10:25:15 2002 Charlie Root 8 | ** Last update Tue May 15 16:46:08 2007 Olivier Crouzet 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | int mlx_destroy_window(t_xvar *xvar,t_win_list *win) 16 | { 17 | t_win_list *w; 18 | t_win_list *prev; 19 | t_win_list first; 20 | 21 | first.next = xvar->win_list; 22 | prev = &first; 23 | w = prev->next; 24 | while (w) 25 | { 26 | if (w==win) 27 | prev->next = w->next; 28 | else 29 | prev = w; 30 | w = w->next; 31 | } 32 | xvar->win_list = first.next; 33 | XDestroyWindow(xvar->display,win->window); 34 | XFreeGC(xvar->display,win->gc); 35 | free(win); 36 | if (xvar->do_flush) 37 | XFlush(xvar->display); 38 | } 39 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_destroy_window.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_destroy_window.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_expose_hook.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_expose_hook.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Thu Aug 3 11:49:06 2000 Charlie Root 8 | ** Last update Fri Feb 23 17:07:42 2001 Charlie Root 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | 16 | 17 | int mlx_expose_hook(t_win_list *win,int (*funct)(),void *param) 18 | { 19 | win->hooks[Expose].hook = funct; 20 | win->hooks[Expose].param = param; 21 | win->hooks[Expose].mask = ExposureMask; 22 | } 23 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_expose_hook.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_expose_hook.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_flush_event.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_flush_event.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Wed Aug 2 18:58:11 2000 Charlie Root 8 | ** Last update Fri Feb 23 17:08:48 2001 Charlie Root 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | 16 | 17 | int mlx_flush_event(t_xvar *xvar) 18 | { 19 | XEvent ev; 20 | 21 | while (XPending(xvar->display)) 22 | { 23 | XNextEvent(xvar->display,&ev); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_flush_event.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_flush_event.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_get_color_value.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_get_color_value.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Mon Jul 31 19:01:33 2000 Charlie Root 8 | ** Last update Thu Oct 4 15:04:13 2001 Charlie Root 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | int mlx_get_color_value(t_xvar *xvar,int color) 16 | { 17 | return(mlx_int_get_good_color(xvar,color)); 18 | } 19 | 20 | int mlx_int_get_good_color(t_xvar *xvar,int color) 21 | { 22 | XColor xc; 23 | 24 | if (xvar->depth>=24) 25 | return (color); 26 | xc.red = (color>>8)&0xFF00; 27 | xc.green = color&0xFF00; 28 | xc.blue = (color<<8)&0xFF00; 29 | xc.pixel = ((xc.red>>(16-xvar->decrgb[1]))<decrgb[0])+ 30 | ((xc.green>>(16-xvar->decrgb[3]))<decrgb[2])+ 31 | ((xc.blue>>(16-xvar->decrgb[5]))<decrgb[4]); 32 | return (xc.pixel); 33 | } 34 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_get_color_value.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_get_color_value.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_get_data_addr.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_get_data_addr.c for MiniLibX in raytraceur 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Mon Aug 14 15:45:57 2000 Charlie Root 8 | ** Last update Thu Sep 27 19:05:25 2001 Charlie Root 9 | */ 10 | 11 | 12 | 13 | #include "mlx_int.h" 14 | 15 | 16 | char *mlx_get_data_addr(t_img *img,int *bits_per_pixel, 17 | int *size_line,int *endian) 18 | { 19 | *bits_per_pixel = img->bpp; 20 | *size_line = img->size_line; 21 | *endian = img->image->byte_order; 22 | return (img->data); 23 | } 24 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_get_data_addr.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_get_data_addr.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_hook.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_hook.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Thu Aug 3 11:49:06 2000 Charlie Root 8 | ** Last update Fri Jan 28 17:05:28 2005 Olivier Crouzet 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | 16 | 17 | int mlx_hook(t_win_list *win, int x_event, int x_mask, 18 | int (*funct)(),void *param) 19 | { 20 | win->hooks[x_event].hook = funct; 21 | win->hooks[x_event].param = param; 22 | win->hooks[x_event].mask = x_mask; 23 | } 24 | 25 | 26 | int mlx_do_key_autorepeatoff(t_xvar *xvar) 27 | { 28 | XAutoRepeatOff(xvar->display); 29 | } 30 | 31 | int mlx_do_key_autorepeaton(t_xvar *xvar) 32 | { 33 | XAutoRepeatOn(xvar->display); 34 | } 35 | 36 | 37 | int mlx_do_sync(t_xvar *xvar) 38 | { 39 | XSync(xvar->display, False); 40 | } 41 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_hook.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_hook.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_init.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_init.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Mon Jul 31 16:52:42 2000 Charlie Root 8 | ** Last update Fri Jan 28 17:05:09 2005 Olivier Crouzet 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | 16 | void *mlx_init() 17 | { 18 | t_xvar *xvar; 19 | 20 | if (!(xvar = malloc(sizeof(*xvar)))) 21 | return ((void*)0); 22 | if ((xvar->display = XOpenDisplay("")) == 0) 23 | { 24 | free(xvar); 25 | return ((void*)0); 26 | } 27 | xvar->screen = DefaultScreen(xvar->display); 28 | xvar->root = DefaultRootWindow(xvar->display); 29 | xvar->cmap = DefaultColormap(xvar->display,xvar->screen); 30 | xvar->depth = DefaultDepth(xvar->display,xvar->screen); 31 | if (mlx_int_get_visual(xvar)==-1) 32 | { 33 | printf(ERR_NO_TRUECOLOR); 34 | exit(1); 35 | } 36 | xvar->win_list = 0; 37 | xvar->loop_hook = 0; 38 | xvar->loop_param = (void *)0; 39 | xvar->do_flush = 1; 40 | xvar->wm_delete_window = XInternAtom (xvar->display, "WM_DELETE_WINDOW", False); 41 | mlx_int_deal_shm(xvar); 42 | if (xvar->private_cmap) 43 | xvar->cmap = XCreateColormap(xvar->display,xvar->root, 44 | xvar->visual,AllocNone); 45 | mlx_int_rgb_conversion(xvar); 46 | return (xvar); 47 | } 48 | 49 | 50 | /* 51 | ** pshm_format of -1 : Not XYBitmap|XYPixmap|ZPixmap 52 | ** alpha libX need a check of the DISPLAY env var, or shm is allowed 53 | ** in remote Xserver connections. 54 | */ 55 | 56 | int mlx_int_deal_shm(t_xvar *xvar) 57 | { 58 | int use_pshm; 59 | int bidon; 60 | char *dpy; 61 | char buff[33]; 62 | 63 | xvar->use_xshm = XShmQueryVersion(xvar->display,&bidon,&bidon,&(use_pshm)); 64 | if (xvar->use_xshm && use_pshm) 65 | xvar->pshm_format = XShmPixmapFormat(xvar->display); 66 | else 67 | xvar->pshm_format = -1; 68 | gethostname(buff,32); 69 | dpy = getenv(ENV_DISPLAY); 70 | if (dpy && strlen(dpy) && *dpy!=':' && strncmp(dpy,buff,strlen(buff)) && 71 | strncmp(dpy,LOCALHOST,strlen(LOCALHOST)) ) 72 | { 73 | xvar->pshm_format = -1; 74 | xvar->use_xshm = 0; 75 | } 76 | } 77 | 78 | /* 79 | ** TrueColor Visual is needed to have *_mask correctly set 80 | */ 81 | 82 | int mlx_int_rgb_conversion(t_xvar *xvar) 83 | { 84 | bzero(xvar->decrgb,sizeof(int)*6); 85 | while (!(xvar->visual->red_mask&1)) 86 | { xvar->visual->red_mask >>= 1; xvar->decrgb[0] ++; } 87 | while (xvar->visual->red_mask&1) 88 | { xvar->visual->red_mask >>= 1; xvar->decrgb[1] ++; } 89 | while (!(xvar->visual->green_mask&1)) 90 | { xvar->visual->green_mask >>= 1; xvar->decrgb[2] ++; } 91 | while (xvar->visual->green_mask&1) 92 | { xvar->visual->green_mask >>= 1; xvar->decrgb[3] ++; } 93 | while (!(xvar->visual->blue_mask&1)) 94 | { xvar->visual->blue_mask >>= 1; xvar->decrgb[4] ++; } 95 | while (xvar->visual->blue_mask&1) 96 | { xvar->visual->blue_mask >>= 1; xvar->decrgb[5] ++; } 97 | } 98 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_init.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_init.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_int_anti_resize_win.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_int_anti_resize_win.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Tue Aug 8 14:31:05 2000 Charlie Root 8 | ** Last update Tue Sep 25 15:56:58 2001 Charlie Root 9 | */ 10 | 11 | #include "mlx_int.h" 12 | 13 | 14 | int mlx_int_anti_resize_win(t_xvar *xvar,Window win,int w,int h) 15 | { 16 | XSizeHints hints; 17 | long toto; 18 | 19 | XGetWMNormalHints(xvar->display,win,&hints,&toto); 20 | hints.width = w; 21 | hints.height = h; 22 | hints.min_width = w; 23 | hints.min_height = h; 24 | hints.max_width = w; 25 | hints.max_height = h; 26 | hints.flags = PPosition | PSize | PMinSize | PMaxSize; 27 | XSetWMNormalHints(xvar->display,win,&hints); 28 | } 29 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_int_anti_resize_win.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_int_anti_resize_win.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_int_do_nothing.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_int_do_nothing.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Tue Aug 8 12:58:24 2000 Charlie Root 8 | ** Last update Tue Sep 25 15:56:22 2001 Charlie Root 9 | */ 10 | 11 | 12 | 13 | int mlx_int_do_nothing(void *param) 14 | { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_int_do_nothing.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_int_do_nothing.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_int_get_visual.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_int_get_visual.c for MinilibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Wed Oct 3 17:01:51 2001 Charlie Root 8 | ** Last update Thu Oct 4 15:00:45 2001 Charlie Root 9 | */ 10 | 11 | 12 | 13 | #include "mlx_int.h" 14 | 15 | 16 | /* 17 | ** We need a private colormap for non-default Visual. 18 | */ 19 | 20 | 21 | int mlx_int_get_visual(t_xvar *xvar) 22 | { 23 | XVisualInfo *vi; 24 | XVisualInfo template; 25 | int nb_item; 26 | 27 | xvar->private_cmap = 0; 28 | xvar->visual = DefaultVisual(xvar->display,xvar->screen); 29 | if (xvar->visual->class == TrueColor) 30 | return (0); 31 | template.class = TrueColor; 32 | template.depth = xvar->depth; 33 | if (!(vi = XGetVisualInfo(xvar->display,VisualDepthMask|VisualClassMask, 34 | &template,&nb_item)) ) 35 | return (-1); 36 | xvar->visual = vi->visual; 37 | xvar->private_cmap = 1; 38 | return (0); 39 | } 40 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_int_get_visual.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_int_get_visual.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_int_param_event.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_int_param_event.c for MinilibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Mon Jul 31 16:37:50 2000 Charlie Root 8 | ** Last update Wed Oct 6 13:14:52 2004 Olivier Crouzet 9 | */ 10 | 11 | #include "mlx_int.h" 12 | 13 | int mlx_int_param_undef() 14 | { 15 | } 16 | 17 | int mlx_int_param_KeyPress(t_xvar *xvar, XEvent *ev, t_win_list *win) 18 | { 19 | win->hooks[KeyPress].hook(XkbKeycodeToKeysym(xvar->display, 20 | ev->xkey.keycode, 0, 0), 21 | win->hooks[KeyPress].param); 22 | } 23 | 24 | int mlx_int_param_KeyRelease(t_xvar *xvar, XEvent *ev, t_win_list *win) 25 | { 26 | win->hooks[KeyRelease].hook(XkbKeycodeToKeysym(xvar->display, 27 | ev->xkey.keycode, 0, 0), 28 | win->hooks[KeyRelease].param); 29 | } 30 | 31 | int mlx_int_param_ButtonPress(t_xvar *xvar, XEvent *ev, t_win_list *win) 32 | { 33 | win->hooks[ButtonPress].hook(ev->xbutton.button,ev->xbutton.x,ev->xbutton.y, 34 | win->hooks[ButtonPress].param); 35 | } 36 | 37 | int mlx_int_param_ButtonRelease(t_xvar *xvar, XEvent *ev, t_win_list *win) 38 | { 39 | win->hooks[ButtonRelease].hook(ev->xbutton.button, 40 | ev->xbutton.x, ev->xbutton.y, 41 | win->hooks[ButtonRelease].param); 42 | } 43 | 44 | int mlx_int_param_MotionNotify(t_xvar *xvar, XEvent *ev, t_win_list *win) 45 | { 46 | win->hooks[MotionNotify].hook(ev->xbutton.x,ev->xbutton.y, 47 | win->hooks[MotionNotify].param); 48 | } 49 | 50 | int mlx_int_param_Expose(t_xvar *xvar, XEvent *ev, t_win_list *win) 51 | { 52 | if (!ev->xexpose.count) 53 | win->hooks[Expose].hook(win->hooks[Expose].param); 54 | } 55 | 56 | 57 | int mlx_int_param_generic(t_xvar *xvar, XEvent *ev, t_win_list *win) 58 | { 59 | win->hooks[ev->type].hook(win->hooks[ev->type].param); 60 | } 61 | 62 | int (*(mlx_int_param_event[]))() = 63 | { 64 | mlx_int_param_undef, /* 0 */ 65 | mlx_int_param_undef, 66 | mlx_int_param_KeyPress, 67 | mlx_int_param_KeyRelease, /* 3 */ 68 | mlx_int_param_ButtonPress, 69 | mlx_int_param_ButtonRelease, 70 | mlx_int_param_MotionNotify, /* 6 */ 71 | mlx_int_param_generic, 72 | mlx_int_param_generic, 73 | mlx_int_param_generic, 74 | mlx_int_param_generic, 75 | mlx_int_param_generic, 76 | mlx_int_param_Expose, /* 12 */ 77 | mlx_int_param_generic, 78 | mlx_int_param_generic, 79 | mlx_int_param_generic, 80 | mlx_int_param_generic, 81 | mlx_int_param_generic, 82 | mlx_int_param_generic, 83 | mlx_int_param_generic, 84 | mlx_int_param_generic, 85 | mlx_int_param_generic, 86 | mlx_int_param_generic, 87 | mlx_int_param_generic, 88 | mlx_int_param_generic, 89 | mlx_int_param_generic, 90 | mlx_int_param_generic, 91 | mlx_int_param_generic, 92 | mlx_int_param_generic, 93 | mlx_int_param_generic, 94 | mlx_int_param_generic, 95 | mlx_int_param_generic, 96 | mlx_int_param_generic, 97 | mlx_int_param_generic, 98 | mlx_int_param_generic, 99 | mlx_int_param_generic 100 | }; 101 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_int_param_event.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_int_param_event.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_int_set_win_event_mask.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_int_set_win_event_mask.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Thu Aug 3 11:49:06 2000 Charlie Root 8 | ** Last update Fri Feb 23 17:07:42 2001 Charlie Root 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | 16 | 17 | int mlx_int_set_win_event_mask(t_xvar *xvar) 18 | { 19 | t_win_list *win; 20 | int mask; 21 | int i; 22 | XSetWindowAttributes xwa; 23 | 24 | win = xvar->win_list; 25 | while (win) 26 | { 27 | xwa.event_mask = 0; 28 | i = MLX_MAX_EVENT; 29 | while (i--) 30 | xwa.event_mask |= win->hooks[i].mask; 31 | XChangeWindowAttributes(xvar->display, win->window, CWEventMask, &xwa); 32 | win = win->next; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_int_set_win_event_mask.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_int_set_win_event_mask.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_int_str_to_wordtab.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_int_str_to_wordtab.c for MinilibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Wed Sep 13 11:36:09 2000 Charlie Root 8 | ** Last update Fri Dec 14 11:02:09 2001 Charlie Root 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | int mlx_int_str_str(char *str,char *find,int len) 16 | { 17 | int len_f; 18 | int pos; 19 | char *s; 20 | char *f; 21 | 22 | len_f = strlen(find); 23 | if (len_f>len) 24 | return (-1); 25 | pos = 0; 26 | while (*(str+len_f-1)) 27 | { 28 | s = str; 29 | f = find; 30 | while (*(f++) == *(s++)) 31 | if (!*f) 32 | return (pos); 33 | str ++; 34 | pos ++; 35 | } 36 | return (-1); 37 | } 38 | 39 | 40 | 41 | int mlx_int_str_str_cote(char *str,char *find,int len) 42 | { 43 | int len_f; 44 | int pos; 45 | char *s; 46 | char *f; 47 | int cote; 48 | 49 | len_f = strlen(find); 50 | if (len_f>len) 51 | return (-1); 52 | cote = 0; 53 | pos = 0; 54 | while (*(str+len_f-1)) 55 | { 56 | if (*str=='"') 57 | cote = 1-cote; 58 | if (!cote) 59 | { 60 | s = str; 61 | f = find; 62 | while (*(f++) == *(s++)) 63 | if (!*f) 64 | return (pos); 65 | } 66 | str ++; 67 | pos ++; 68 | } 69 | return (-1); 70 | } 71 | 72 | 73 | char **mlx_int_str_to_wordtab(char *str) 74 | { 75 | char **tab; 76 | int pos; 77 | int nb_word; 78 | int len; 79 | 80 | len = strlen(str); 81 | nb_word = 0; 82 | pos = 0; 83 | while (pos 6 | ** 7 | ** Started on Tue Oct 17 09:26:45 2000 olivier crouzet 8 | ** Last update Fri Feb 23 17:27:10 2001 Charlie Root 9 | */ 10 | 11 | 12 | 13 | #include "mlx_int.h" 14 | 15 | 16 | 17 | int mlx_int_wait_first_expose(t_xvar *xvar,Window win) 18 | { 19 | XEvent ev; 20 | 21 | XWindowEvent(xvar->display,win,ExposureMask,&ev); 22 | XPutBackEvent(xvar->display,&ev); 23 | } 24 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_int_wait_first_expose.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_int_wait_first_expose.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_key_hook.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_key_hook.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Thu Aug 3 11:49:06 2000 Charlie Root 8 | ** Last update Fri Feb 23 17:10:09 2001 Charlie Root 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | 16 | 17 | int mlx_key_hook(t_win_list *win,int (*funct)(),void *param) 18 | { 19 | win->hooks[KeyRelease].hook = funct; 20 | win->hooks[KeyRelease].param = param; 21 | win->hooks[KeyRelease].mask = KeyReleaseMask; 22 | } 23 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_key_hook.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_key_hook.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_lib_xpm.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_xpm.c for minilibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Fri Dec 8 11:07:24 2000 Charlie Root 8 | ** Last update Thu Oct 4 16:00:22 2001 Charlie Root 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | 16 | 17 | void *mlx_int_xpm_f_image(t_xvar *xvar,int *width,int *height, 18 | int (*xpm_func)(),void *param) 19 | { 20 | XImage *img1; 21 | XImage *img2; 22 | t_img *im2; 23 | XpmAttributes xpm_att; 24 | 25 | xpm_att.visual = xvar->visual; 26 | xpm_att.colormap = xvar->cmap; 27 | xpm_att.depth = xvar->depth; 28 | xpm_att.bitmap_format = ZPixmap; 29 | xpm_att.valuemask = XpmDepth|XpmBitmapFormat|XpmVisual|XpmColormap; 30 | if (xpm_func(xvar->display,param,&img1,&img2,&xpm_att)) 31 | return ((void *)0); 32 | if (img2) 33 | XDestroyImage(img2); 34 | 35 | if (!(im2 = (void *)mlx_new_image(xvar,img1->width,img1->height))) 36 | { 37 | XDestroyImage(img1); 38 | return ((void *)0); 39 | } 40 | *width = img1->width; 41 | *height = img1->height; 42 | if (mlx_int_egal_img(im2->image,img1)) 43 | { 44 | bcopy(img1->data,im2->data,img1->height*img1->bytes_per_line); 45 | XDestroyImage(img1); 46 | return (im2); 47 | } 48 | if (im2->type==MLX_TYPE_SHM_PIXMAP) 49 | { 50 | XFreePixmap(xvar->display,im2->pix); 51 | im2->pix = XCreatePixmap(xvar->display,xvar->root, 52 | *width,*height,xvar->depth); 53 | } 54 | if (im2->type>MLX_TYPE_XIMAGE) 55 | { 56 | XShmDetach(xvar->display,&(im2->shm)); 57 | shmdt(im2->data); 58 | } 59 | XDestroyImage(im2->image); 60 | im2->image = img1; 61 | im2->data = img1->data; 62 | im2->type = MLX_TYPE_XIMAGE; 63 | im2->size_line = img1->bytes_per_line; 64 | im2->bpp = img1->bits_per_pixel; 65 | return (im2); 66 | } 67 | 68 | 69 | int mlx_int_egal_img(XImage *img1,XImage *img2) 70 | { 71 | if (img1->width!=img2->width || img1->height!=img2->height || 72 | img1->xoffset!=img2->xoffset || img1->format!=img2->format || 73 | img1->byte_order!=img2->byte_order || 74 | img1->bitmap_unit!=img2->bitmap_unit || 75 | img1->bitmap_bit_order!=img2->bitmap_bit_order || 76 | img1->bitmap_pad!=img2->bitmap_pad || img1->depth!=img2->depth || 77 | img1->bytes_per_line!=img2->bytes_per_line || 78 | img1->bits_per_pixel!=img2->bits_per_pixel || 79 | img1->red_mask!=img2->red_mask || img1->green_mask!=img2->green_mask || 80 | img1->blue_mask!=img2->blue_mask ) 81 | return (0); 82 | return (1); 83 | } 84 | 85 | 86 | void *mlx_xpm_file_to_image(t_xvar *xvar,char *filename, 87 | int *width,int *height) 88 | { 89 | return (mlx_int_xpm_f_image(xvar,width,height,XpmReadFileToImage,filename)); 90 | } 91 | 92 | 93 | void *mlx_xpm_to_image(t_xvar *xvar,char **data,int *width,int *height) 94 | { 95 | return (mlx_int_xpm_f_image(xvar,width,height,XpmCreateImageFromData,(void *)data)); 96 | } 97 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_loop.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_loop.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Wed Aug 2 18:58:11 2000 Charlie Root 8 | ** Last update Fri Sep 30 14:47:41 2005 Olivier Crouzet 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | extern int (*(mlx_int_param_event[]))(); 15 | 16 | 17 | int mlx_loop(t_xvar *xvar) 18 | { 19 | XEvent ev; 20 | t_win_list *win; 21 | 22 | mlx_int_set_win_event_mask(xvar); 23 | xvar->do_flush = 0; 24 | while (42) 25 | { 26 | while (!xvar->loop_hook || XPending(xvar->display)) 27 | { 28 | XNextEvent(xvar->display,&ev); 29 | win = xvar->win_list; 30 | while (win && (win->window!=ev.xany.window)) 31 | win = win->next; 32 | if (win && ev.type < MLX_MAX_EVENT) 33 | { 34 | if (ev.type == ClientMessage && (Atom)ev.xclient.data.l[0] == xvar->wm_delete_window) 35 | XDestroyWindow(xvar->display, win->window); 36 | if (win->hooks[ev.type].hook) 37 | mlx_int_param_event[ev.type](xvar, &ev, win); 38 | } 39 | } 40 | XSync(xvar->display, False); 41 | xvar->loop_hook(xvar->loop_param); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_loop.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_loop.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_loop_hook.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_loop_hook.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Thu Aug 3 11:49:06 2000 Charlie Root 8 | ** Last update Fri Feb 23 17:11:39 2001 Charlie Root 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | 16 | 17 | int mlx_loop_hook(t_xvar *xvar,int (*funct)(),void *param) 18 | { 19 | xvar->loop_hook = funct; 20 | xvar->loop_param = param; 21 | } 22 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_loop_hook.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_loop_hook.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_mouse.c: -------------------------------------------------------------------------------- 1 | #include "mlx_int.h" 2 | 3 | int mlx_mouse_move(t_xvar *xvar, t_win_list *win, int x, int y) 4 | { 5 | XWarpPointer(xvar->display, None, win->window, 0, 0, 0, 0, x, y); 6 | return (0); 7 | } 8 | 9 | int mlx_mouse_hide(t_xvar *xvar, t_win_list *win) 10 | { 11 | static char data[1] = {0}; 12 | Cursor cursor; 13 | Pixmap blank; 14 | XColor dummy; 15 | 16 | blank = XCreateBitmapFromData(xvar->display, win->window, data, 1, 1); 17 | cursor = XCreatePixmapCursor(xvar->display, blank, blank, &dummy, &dummy, 0, 0); 18 | XDefineCursor(xvar->display, win->window, cursor); 19 | XFreePixmap(xvar->display, blank); 20 | XFreeCursor(xvar->display, cursor); 21 | } 22 | 23 | int mlx_mouse_show(t_xvar *xvar, t_win_list *win) 24 | { 25 | XUndefineCursor(xvar->display, win->window); 26 | } 27 | 28 | /* 29 | ** Queries the position of the mouse pointer relative to the origin of the 30 | ** specified window and saves it to the provided location. 31 | ** 32 | ** If the pointer is not on the same screen as the specified window, both 33 | ** win_x_return and win_y_return are set to zero and the function returns 0. 34 | */ 35 | 36 | int mlx_mouse_get_pos(t_xvar *xvar, t_win_list *win, \ 37 | int *win_x_return, int *win_y_return) 38 | { 39 | Window root_return; 40 | Window child_return; 41 | int root_x_return; 42 | int root_y_return; 43 | unsigned mask_return; 44 | 45 | return (XQueryPointer(xvar->display, win->window, \ 46 | &root_return, &child_return, &root_x_return, &root_y_return, \ 47 | win_x_return, win_y_return, &mask_return)); 48 | } 49 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_mouse.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_mouse.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_mouse_hook.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_mouse_hook.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Thu Aug 3 11:49:06 2000 Charlie Root 8 | ** Last update Fri Feb 23 17:11:05 2001 Charlie Root 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | 16 | 17 | int mlx_mouse_hook(t_win_list *win,int (*funct)(),void *param) 18 | { 19 | win->hooks[ButtonPress].hook = funct; 20 | win->hooks[ButtonPress].param = param; 21 | win->hooks[ButtonPress].mask = ButtonPressMask; 22 | } 23 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_mouse_hook.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_mouse_hook.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_new_image.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_new_image.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_new_window.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_new_window.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Mon Jul 31 17:29:02 2000 Charlie Root 8 | ** Last update Thu Oct 4 15:44:43 2001 Charlie Root 9 | */ 10 | 11 | 12 | /* 13 | ** We do not use White/BlackPixel macro, TrueColor Visual make sure 14 | ** 0 is black & -1 is white 15 | ** 16 | ** With mlx_int_wait_first_expose, no flush is needed. 17 | */ 18 | 19 | #include "mlx_int.h" 20 | 21 | 22 | void *mlx_new_window(t_xvar *xvar,int size_x,int size_y,char *title) 23 | { 24 | t_win_list *new_win; 25 | XSetWindowAttributes xswa; 26 | XGCValues xgcv; 27 | 28 | xswa.background_pixel = 0; 29 | xswa.border_pixel = -1; 30 | xswa.colormap = xvar->cmap; 31 | /* 32 | xswa.event_mask = ButtonPressMask | ButtonReleaseMask | ExposureMask | 33 | KeyPressMask | KeyReleaseMask | StructureNotifyMask; 34 | */ 35 | /* xswa.event_mask = ExposureMask; */ 36 | xswa.event_mask = 0xFFFFFF; /* all events */ 37 | if (!(new_win = malloc(sizeof(*new_win)))) 38 | return ((void *)0); 39 | new_win->window = XCreateWindow(xvar->display,xvar->root,0,0,size_x,size_y, 40 | 0,CopyFromParent,InputOutput,xvar->visual, 41 | CWEventMask|CWBackPixel|CWBorderPixel| 42 | CWColormap,&xswa); 43 | mlx_int_anti_resize_win(xvar,new_win->window,size_x,size_y); 44 | XStoreName(xvar->display,new_win->window,title); 45 | XSetWMProtocols(xvar->display, new_win->window, &(xvar->wm_delete_window), 1); 46 | xgcv.foreground = -1; 47 | xgcv.function = GXcopy; 48 | xgcv.plane_mask = AllPlanes; 49 | new_win->gc = XCreateGC(xvar->display,new_win->window, 50 | GCFunction|GCPlaneMask|GCForeground,&xgcv); 51 | new_win->next = xvar->win_list; 52 | xvar->win_list = new_win; 53 | /* 54 | new_win->mouse_hook = mlx_int_do_nothing; 55 | new_win->key_hook = mlx_int_do_nothing; 56 | new_win->expose_hook = mlx_int_do_nothing; 57 | */ 58 | bzero(&(new_win->hooks), sizeof(new_win->hooks)); 59 | XMapRaised(xvar->display,new_win->window); 60 | mlx_int_wait_first_expose(xvar,new_win->window); 61 | return (new_win); 62 | } 63 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_new_window.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_new_window.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_pixel_put.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_pixel_put.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Mon Jul 31 19:01:33 2000 Charlie Root 8 | ** Last update Tue Sep 25 17:09:49 2001 Charlie Root 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | 16 | int mlx_pixel_put(t_xvar *xvar,t_win_list *win, 17 | int x,int y,int color) 18 | { 19 | XGCValues xgcv; 20 | 21 | xgcv.foreground = mlx_int_get_good_color(xvar,color); 22 | XChangeGC(xvar->display,win->gc,GCForeground,&xgcv); 23 | XDrawPoint(xvar->display,win->window,win->gc,x,y); 24 | if (xvar->do_flush) 25 | XFlush(xvar->display); 26 | } 27 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_pixel_put.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_pixel_put.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_put_image_to_window.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_put_image_to_window.c for MiniLibX in raytraceur 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Mon Aug 14 15:55:49 2000 Charlie Root 8 | ** Last update Sun Oct 2 09:53:00 2005 Olivier Crouzet 9 | */ 10 | 11 | 12 | 13 | #include "mlx_int.h" 14 | 15 | 16 | int mlx_put_image_to_window(t_xvar *xvar,t_win_list *win,t_img *img, 17 | int x,int y) 18 | { 19 | GC gc; 20 | 21 | gc = win->gc; 22 | if (img->gc) 23 | { 24 | gc = img->gc; 25 | XSetClipOrigin(xvar->display, gc, x, y); 26 | } 27 | if (img->type==MLX_TYPE_SHM) 28 | XShmPutImage(xvar->display,img->pix, win->gc, img->image,0,0,0,0, 29 | img->width,img->height,False); 30 | if (img->type==MLX_TYPE_XIMAGE) 31 | XPutImage(xvar->display,img->pix, win->gc, img->image,0,0,0,0, 32 | img->width,img->height); 33 | XCopyArea(xvar->display,img->pix,win->window, gc, 34 | 0,0,img->width,img->height,x,y); 35 | if (xvar->do_flush) 36 | XFlush(xvar->display); 37 | } 38 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_put_image_to_window.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_put_image_to_window.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_rgb.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_rgb.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_screen_size.c: -------------------------------------------------------------------------------- 1 | #include "mlx_int.h" 2 | 3 | int mlx_get_screen_size(void *mlx_ptr, int *sizex, int *sizey) 4 | { 5 | XWindowAttributes xwAttr; 6 | Status ret; 7 | t_xvar *xvar; 8 | 9 | xvar = mlx_ptr; 10 | ret = XGetWindowAttributes(xvar->display, xvar->root, &xwAttr); 11 | (*sizex) = xwAttr.width; 12 | (*sizey) = xwAttr.height; 13 | } 14 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_screen_size.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_screen_size.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_set_font.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* mlx_set_font.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: amalliar +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/09/30 13:30:47 by amalliar #+# #+# */ 9 | /* Updated: 2020/09/30 17:08:36 by amalliar ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "mlx_int.h" 14 | 15 | /* 16 | ** Allows to specify the font that will be used by mlx_string_put. 17 | ** 18 | ** Note: only fixed-width bitmap fonts are supported by Xlib, refer to xfontsel 19 | ** utility to get valid font names for this function. 20 | */ 21 | 22 | void mlx_set_font(t_xvar *xvar, t_win_list *win, char *name) 23 | { 24 | static Font font = 0; 25 | 26 | if (font) 27 | XUnloadFont(xvar->display, font); 28 | font = XLoadFont(xvar->display, name); 29 | XSetFont(xvar->display, win->gc, font); 30 | } 31 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_set_font.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_set_font.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_string_put.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** mlx_string_put.c for MiniLibX in 3 | ** 4 | ** Made by Charlie Root 5 | ** Login 6 | ** 7 | ** Started on Mon Jul 31 19:01:33 2000 Charlie Root 8 | ** Last update Tue Sep 25 17:11:47 2001 Charlie Root 9 | */ 10 | 11 | 12 | #include "mlx_int.h" 13 | 14 | 15 | 16 | int mlx_string_put(t_xvar *xvar,t_win_list *win, 17 | int x,int y,int color,char *string) 18 | { 19 | XGCValues xgcv; 20 | 21 | xgcv.foreground = mlx_int_get_good_color(xvar,color); 22 | XChangeGC(xvar->display,win->gc,GCForeground,&xgcv); 23 | XDrawString(xvar->display,win->window,win->gc,x,y,string,strlen(string)); 24 | if (xvar->do_flush) 25 | XFlush(xvar->display); 26 | } 27 | -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_string_put.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_string_put.o -------------------------------------------------------------------------------- /minilibx-linux-master/mlx_xpm.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/mlx_xpm.o -------------------------------------------------------------------------------- /minilibx-linux-master/rgb2c.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # 3 | ## rgb2c.pl for MiniLibX in /home/boulon/work/c/raytraceur/minilibx 4 | ## 5 | ## Made by Olivier Crouzet 6 | ## Login 7 | ## 8 | ## Started on Tue Oct 5 16:33:46 2004 Olivier Crouzet 9 | ## Last update Tue Oct 5 16:36:11 2004 Olivier Crouzet 10 | ## 11 | 12 | 13 | # 14 | # Generate a .c file with encoded colors, from the XFree86 rgb.txt file. 15 | # 16 | 17 | open(RGB, "/usr/X11/lib/X11/rgb.txt"); 18 | 19 | 20 | printf("/*\n** This is a generated file with rgb2c.pl and rgb.txt from\n"); 21 | printf("** the XFree86 distribution.\n*/\n\n"); 22 | printf("struct s_col_name mlx_col_name[] =\n{\n"); 23 | 24 | while () 25 | { 26 | @tab = split; 27 | if ($tab[0] ne "!") 28 | { 29 | $color = $tab[3]; 30 | if ("$tab[4]" ne "") 31 | { 32 | $color = "$tab[3] $tab[4]"; 33 | } 34 | printf(" { \"%s\" , 0x%x },\n", $color, $tab[0]*65536+$tab[1]*256+$tab[2]); 35 | } 36 | } 37 | 38 | printf(" { 0, 0 }\n};\n"); 39 | -------------------------------------------------------------------------------- /minilibx-linux-master/test/Makefile.gen: -------------------------------------------------------------------------------- 1 | INC=/usr/include 2 | HT=Linux 3 | DOCP=do_cp 4 | 5 | 6 | 7 | INCLIB=$(INC)/../lib 8 | 9 | CC=gcc 10 | 11 | CFLAGS= -I$(INC) -O3 -I.. 12 | 13 | NAME= mlx-test 14 | SRC = main.c 15 | OBJ = $(SRC:.c=.o) 16 | 17 | all :$(NAME) 18 | 19 | $(NAME) :$(OBJ) 20 | $(CC) -o $(NAME) $(OBJ) -L.. -lmlx -L$(INCLIB) -lXext -lX11 -lm -lbsd 21 | 22 | clean : 23 | rm -f $(NAME) $(OBJ) *~ core *.core 24 | 25 | 26 | re : clean all 27 | -------------------------------------------------------------------------------- /minilibx-linux-master/test/Makefile.mk: -------------------------------------------------------------------------------- 1 | 2 | 3 | INC=%%%% 4 | 5 | INCLIB=$(INC)/../lib 6 | 7 | CC=gcc 8 | 9 | CFLAGS= -I$(INC) -O3 -I.. 10 | 11 | NAME= mlx-test 12 | SRC = main.c 13 | OBJ = $(SRC:.c=.o) 14 | 15 | all :$(NAME) 16 | 17 | $(NAME) :$(OBJ) 18 | $(CC) -o $(NAME) $(OBJ) -L.. -lmlx -L$(INCLIB) -lXext -lX11 -lm -lbsd 19 | 20 | clean : 21 | rm -f $(NAME) $(OBJ) *~ core *.core 22 | 23 | 24 | re : clean all 25 | -------------------------------------------------------------------------------- /minilibx-linux-master/test/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/minilibx-linux-master/test/main.o -------------------------------------------------------------------------------- /minilibx-linux-master/test/new_win.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #include "mlx.h" 5 | 6 | 7 | void *mlx; 8 | void *win1; 9 | void *win2; 10 | 11 | 12 | 13 | int gere_mouse(int x,int y,int button,void*toto) 14 | { 15 | printf("Mouse event - new win\n"); 16 | mlx_destroy_window(mlx,win1); 17 | win1 = mlx_new_window(mlx,random()%500,random()%500,"new win"); 18 | mlx_mouse_hook(win1,gere_mouse,0); 19 | } 20 | 21 | 22 | int main() 23 | { 24 | srandom(time(0)); 25 | mlx = mlx_init(); 26 | win1 = mlx_new_window(mlx,300,300,"win1"); 27 | win2 = mlx_new_window(mlx,600,600,"win2"); 28 | mlx_mouse_hook(win1,gere_mouse,0); 29 | mlx_mouse_hook(win2,gere_mouse,0); 30 | mlx_loop(mlx); 31 | } 32 | -------------------------------------------------------------------------------- /misc/geo_op.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* geo_op.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/28 13:26:09 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/04 14:34:30 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../raymarching.h" 14 | 15 | double plane_dist(double *v, double *o, double *p) 16 | { 17 | return (fabs(v[0] * p[0] + v[1] * p[1] + v[2] * p[2] - 18 | (v[0] * o[0] + v[1] * o[1] + v[2] * o[2]))); 19 | } 20 | 21 | double segment_dist(double *a, double *b, double *p) 22 | { 23 | double h; 24 | double d[3]; 25 | double pa[3]; 26 | double ba[3]; 27 | int j; 28 | 29 | j = -1; 30 | while (++j < 3) 31 | { 32 | pa[j] = a[j] - p[j]; 33 | ba[j] = a[j] - b[j]; 34 | } 35 | h = min(1, max(0, dot_prod(pa, ba) / pow(mod(ba), 2))); 36 | j = -1; 37 | while (++j < 3) 38 | d[j] = pa[j] - h * ba[j]; 39 | return (mod(d)); 40 | } 41 | -------------------------------------------------------------------------------- /misc/mlx_comp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* mlx_comp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/28 12:57:37 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/04 15:03:57 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../raymarching.h" 14 | 15 | static void free_elm(t_data *param) 16 | { 17 | int i; 18 | 19 | i = -1; 20 | while (param->l[++i]) 21 | free(param->l[i]); 22 | free(param->l); 23 | i = -1; 24 | while (param->c[++i]) 25 | free(param->c[i]); 26 | free(param->c); 27 | } 28 | 29 | static void free_obj_1(t_data *param) 30 | { 31 | int i; 32 | 33 | i = -1; 34 | while (param->sp[++i]) 35 | free(param->sp[i]); 36 | free(param->sp); 37 | i = -1; 38 | while (param->pl[++i]) 39 | free(param->pl[i]); 40 | free(param->pl); 41 | i = -1; 42 | while (param->cy[++i]) 43 | free(param->cy[i]); 44 | free(param->cy); 45 | } 46 | 47 | static void free_obj_2(t_data *param) 48 | { 49 | int i; 50 | 51 | i = -1; 52 | while (param->sq[++i]) 53 | free(param->sq[i]); 54 | free(param->sq); 55 | i = -1; 56 | while (param->bx[++i]) 57 | free(param->bx[i]); 58 | free(param->bx); 59 | i = -1; 60 | while (param->tr[++i]) 61 | free(param->tr[i]); 62 | free(param->tr); 63 | } 64 | 65 | int ft_exit(t_data *param) 66 | { 67 | free(param->id); 68 | free(param->win_id); 69 | free(param->img.img); 70 | free_elm(param); 71 | free_obj_1(param); 72 | free_obj_2(param); 73 | free(param); 74 | exit(0); 75 | return (0); 76 | } 77 | 78 | void my_mlx_pixel_put(t_data *param, int x, int y, int color) 79 | { 80 | char *dst; 81 | 82 | dst = param->img.addr + (y * param->img.line_length + x * 83 | (param->img.bits_per_pixel / 8)); 84 | *(unsigned int*)dst = color; 85 | } 86 | -------------------------------------------------------------------------------- /misc/operators.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* operators.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/28 13:25:03 by jserrano #+# #+# */ 9 | /* Updated: 2020/10/28 13:25:48 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../raymarching.h" 14 | 15 | double max(double a, double b) 16 | { 17 | if (a < b) 18 | return (b); 19 | return (a); 20 | } 21 | 22 | double min(double a, double b) 23 | { 24 | if (a < b) 25 | return (a); 26 | return (b); 27 | } 28 | -------------------------------------------------------------------------------- /misc/rgb_hex.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* rgb_hex.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/28 13:23:47 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/03 15:48:22 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../raymarching.h" 14 | 15 | void rgb_to_hex(int *rgb, int *hex) 16 | { 17 | int i; 18 | 19 | i = -1; 20 | while (++i < 3) 21 | rgb[i] = (rgb[i] > 255) ? 255 : rgb[i]; 22 | *hex = rgb[0] * 65536 + rgb[1] * 256 + rgb[2]; 23 | } 24 | 25 | void hex_to_rgb(int hex, int *rgb) 26 | { 27 | int i; 28 | 29 | i = 3; 30 | while (--i >= 0) 31 | { 32 | rgb[i] = hex % 256; 33 | hex /= 256; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /misc/vectors_0.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* vectors_0.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/28 12:58:50 by jserrano #+# #+# */ 9 | /* Updated: 2020/10/28 13:01:36 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../raymarching.h" 14 | 15 | double mod(double *v) 16 | { 17 | return (sqrt(pow(v[0], 2) + pow(v[1], 2) + pow(v[2], 2))); 18 | } 19 | 20 | double cross_prod(double *u, double *v, int i) 21 | { 22 | if (i == 0) 23 | return (u[1] * v[2] - u[2] * v[1]); 24 | else if (i == 1) 25 | return (u[2] * v[0] - u[0] * v[2]); 26 | else if (i == 2) 27 | return (u[0] * v[1] - u[1] * v[0]); 28 | else 29 | return (0); 30 | } 31 | 32 | double dot_prod(double *u, double *v) 33 | { 34 | return (u[0] * v[0] + u[1] * v[1] + u[2] * v[2]); 35 | } 36 | 37 | double dot2_prod(double *u) 38 | { 39 | return (dot_prod(u, u)); 40 | } 41 | -------------------------------------------------------------------------------- /misc/vectors_1.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* vectors_1.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/28 13:01:13 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/04 14:35:47 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../raymarching.h" 14 | 15 | double dot_2d(double *u, double *v, int x, int y) 16 | { 17 | return (u[x] * v[x] + u[y] * v[y]); 18 | } 19 | 20 | void norm(double *u, double *v) 21 | { 22 | int j; 23 | double module; 24 | 25 | j = -1; 26 | module = mod(u); 27 | while (++j < 3) 28 | v[j] = u[j] / module; 29 | } 30 | -------------------------------------------------------------------------------- /mouse.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* input.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/17 13:25:20 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/04 14:58:48 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "raymarching.h" 14 | 15 | int get_pos(int x, int y, t_data *param) 16 | { 17 | if (param->button == 1) 18 | { 19 | param->reload = 1; 20 | param->crd.x = param->mou.x + x - param->scr.x / 2; 21 | param->crd.y = -(param->mou.y + y - param->scr.y / 2); 22 | if (param->crd.y > 249) 23 | { 24 | param->crd.y = 245; 25 | mlx_mouse_move(param->id, param->win_id, x, 26 | param->scr.y / 2 - param->crd.y); 27 | } 28 | else if (param->crd.y < -249) 29 | { 30 | param->crd.y = -245; 31 | mlx_mouse_move(param->id, param->win_id, x, 32 | param->scr.y / 2 - param->crd.y); 33 | } 34 | calculate_rotation(param); 35 | calculate_vectors(param); 36 | copy_cam(param); 37 | } 38 | return (0); 39 | } 40 | 41 | int button_pressed(int button, int x, int y, t_data *param) 42 | { 43 | param->button = button; 44 | if (param->key == KEY_ENT) 45 | param->key = 0; 46 | if (button == 1) 47 | { 48 | mlx_mouse_hide(param->id, param->win_id); 49 | mlx_mouse_move(param->id, param->win_id, param->scr.x / 2, 50 | param->scr.y / 2); 51 | param->crd.aux_x = x; 52 | param->crd.aux_y = y; 53 | } 54 | else if (button == 3) 55 | { 56 | vectors_init(param, param->cam.i); 57 | mouse_init(param); 58 | calculate_rotation(param); 59 | calculate_vectors(param); 60 | copy_cam(param); 61 | } 62 | return (0); 63 | } 64 | 65 | int button_released(int button, int x, int y, t_data *param) 66 | { 67 | if (button == 1) 68 | { 69 | param->mou.x += (x - param->scr.x / 2); 70 | param->mou.y += (y - param->scr.y / 2); 71 | mlx_mouse_move(param->id, param->win_id, param->crd.aux_x, 72 | param->crd.aux_y); 73 | mlx_mouse_show(param->id, param->win_id); 74 | } 75 | param->button = 0; 76 | return (0); 77 | } 78 | -------------------------------------------------------------------------------- /obj/add_bx.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* add_bx.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/27 18:24:32 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/04 16:11:00 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../raymarching.h" 14 | 15 | static void cpy_sq(t_box **sq, t_box **aux, int i) 16 | { 17 | int j; 18 | 19 | j = -1; 20 | while (++j < 3) 21 | { 22 | aux[i]->o[j] = sq[i]->o[j]; 23 | aux[i]->v[j] = sq[i]->v[j]; 24 | aux[i]->x[j] = sq[i]->x[j]; 25 | aux[i]->y[j] = sq[i]->y[j]; 26 | } 27 | aux[i]->h = sq[i]->h; 28 | aux[i]->col = sq[i]->col; 29 | } 30 | 31 | static void new_sq(t_box **aux, double **o_v, double h, int *var) 32 | { 33 | int j; 34 | 35 | j = -1; 36 | while (++j < 3) 37 | { 38 | aux[var[0]]->o[j] = o_v[0][j]; 39 | aux[var[0]]->v[j] = o_v[1][j]; 40 | } 41 | aux[var[0]]->x[0] = 0; 42 | aux[var[0]]->x[1] = -o_v[1][2]; 43 | aux[var[0]]->x[2] = o_v[1][1]; 44 | j = -1; 45 | while (++j < 3) 46 | aux[var[0]]->y[j] = cross_prod(o_v[1], aux[var[0]]->x, j); 47 | norm(aux[var[0]]->y, aux[var[0]]->y); 48 | aux[var[0]]->h = h; 49 | aux[var[0]]->col = var[1]; 50 | } 51 | 52 | static int init_sq(t_box **sq, t_box ***aux, int *var) 53 | { 54 | var[2] = 0; 55 | while (sq[var[2]]) 56 | var[2]++; 57 | if (!(*aux = (t_box **)malloc(sizeof(t_box *) * (var[2] + 2)))) 58 | return (0); 59 | return (1); 60 | } 61 | 62 | /* 63 | ** var[3] = i, c, len 64 | */ 65 | 66 | t_box **add_bx(t_box **sq, double **o_v, double h, int c) 67 | { 68 | t_box **aux; 69 | int var[3]; 70 | 71 | if (!init_sq(sq, &aux, var)) 72 | return (sq); 73 | var[1] = c; 74 | norm(o_v[1], o_v[1]); 75 | var[0] = -1; 76 | while (++var[0] < var[2] + 1) 77 | { 78 | aux[var[0]] = (t_box *)malloc(sizeof(t_box)); 79 | if (var[0] < var[2]) 80 | cpy_sq(sq, aux, var[0]); 81 | else 82 | new_sq(aux, o_v, h, var); 83 | } 84 | aux[var[0]] = 0; 85 | var[0] = 0; 86 | if (var[2]) 87 | while (sq[var[0]]) 88 | free(sq[var[0]++]); 89 | free(sq); 90 | return (aux); 91 | } 92 | -------------------------------------------------------------------------------- /obj/add_c.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* add_c.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/31 15:16:32 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/04 16:42:40 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../raymarching.h" 14 | 15 | static void cpy_c(t_cams **c, t_cams **aux, int i) 16 | { 17 | int j; 18 | 19 | j = -1; 20 | while (++j < 3) 21 | { 22 | aux[i]->o[j] = c[i]->o[j]; 23 | aux[i]->v[j] = c[i]->v[j]; 24 | } 25 | aux[i]->fov = c[i]->fov; 26 | } 27 | 28 | static void new_c(t_cams **aux, double **o_v, int fov, int i) 29 | { 30 | int j; 31 | 32 | j = -1; 33 | while (++j < 3) 34 | { 35 | aux[i]->o[j] = o_v[0][j]; 36 | aux[i]->v[j] = o_v[1][j]; 37 | } 38 | aux[i]->fov = fov; 39 | } 40 | 41 | static void set_c(t_cams **c, t_cams **aux, double **o_v, int fov) 42 | { 43 | int i; 44 | int len; 45 | 46 | len = 0; 47 | while (c[len]) 48 | len++; 49 | i = -1; 50 | while (++i < len + 1) 51 | { 52 | aux[i] = (t_cams *)malloc(sizeof(t_cams)); 53 | if (i < len) 54 | cpy_c(c, aux, i); 55 | else 56 | new_c(aux, o_v, fov, i); 57 | } 58 | aux[i] = 0; 59 | } 60 | 61 | t_cams **add_c(t_cams **c, double **o_v, int fov) 62 | { 63 | int i; 64 | int len; 65 | t_cams **aux; 66 | 67 | len = 0; 68 | while (c[len]) 69 | len++; 70 | if (!(aux = (t_cams **)malloc(sizeof(t_cams *) * len))) 71 | return (c); 72 | norm(o_v[1], o_v[1]); 73 | set_c(c, aux, o_v, fov); 74 | i = 0; 75 | if (len) 76 | while (c[i]) 77 | free(c[i++]); 78 | free(c); 79 | return (aux); 80 | } 81 | -------------------------------------------------------------------------------- /obj/add_cy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* add_cy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/27 17:51:46 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/04 17:04:01 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../raymarching.h" 14 | 15 | static void cpy_cy(t_cylinder **cy, t_cylinder **aux, int i) 16 | { 17 | int j; 18 | 19 | j = -1; 20 | while (++j < 3) 21 | { 22 | aux[i]->o[j] = cy[i]->o[j]; 23 | aux[i]->v[j] = cy[i]->v[j]; 24 | } 25 | aux[i]->col = cy[i]->col; 26 | aux[i]->d = cy[i]->d; 27 | aux[i]->h = cy[i]->h; 28 | } 29 | 30 | static void new_cy(t_cylinder **aux, double **o_v, double *dim, 31 | int *var) 32 | { 33 | int j; 34 | double vn[3]; 35 | 36 | norm(o_v[1], vn); 37 | j = -1; 38 | while (++j < 3) 39 | { 40 | aux[var[0]]->o[j] = o_v[0][j]; 41 | aux[var[0]]->v[j] = vn[j]; 42 | } 43 | aux[var[0]]->col = var[1]; 44 | aux[var[0]]->d = dim[0]; 45 | aux[var[0]]->h = dim[1]; 46 | } 47 | 48 | static t_cylinder **init_sq(t_cylinder **cy, int *var) 49 | { 50 | t_cylinder **aux; 51 | 52 | var[2] = 0; 53 | while (cy[var[2]]) 54 | var[2]++; 55 | if (!(aux = (t_cylinder **)malloc(sizeof(t_cylinder *) * (var[2] + 2)))) 56 | return (0); 57 | return (aux); 58 | } 59 | 60 | /* 61 | ** var = i, c, len 62 | */ 63 | 64 | t_cylinder **add_cy(t_cylinder **cy, double **o_v, double *d_h, int c) 65 | { 66 | t_cylinder **aux; 67 | int var[3]; 68 | 69 | if (!(aux = init_sq(cy, var))) 70 | return (cy); 71 | var[0] = -1; 72 | var[1] = c; 73 | while (++var[0] < var[2] + 1) 74 | { 75 | aux[var[0]] = (t_cylinder *)malloc(sizeof(t_cylinder)); 76 | if (var[0] < var[2]) 77 | cpy_cy(cy, aux, var[0]); 78 | else 79 | new_cy(aux, o_v, d_h, var); 80 | } 81 | aux[var[0]] = 0; 82 | var[0] = 0; 83 | if (var[2]) 84 | while (cy[var[0]]) 85 | free(cy[var[0]++]); 86 | free(cy); 87 | return (aux); 88 | } 89 | -------------------------------------------------------------------------------- /obj/add_l.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* add_l.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/27 16:23:06 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/04 15:05:41 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../raymarching.h" 14 | 15 | static void set_l(t_light **l, t_light **aux, double *o, int *var) 16 | { 17 | int i_j[2]; 18 | 19 | i_j[0] = -1; 20 | while (++i_j[0] < var[0] + 1) 21 | { 22 | aux[i_j[0]] = (t_light *)malloc(sizeof(t_light)); 23 | i_j[1] = -1; 24 | if (i_j[0] < var[0]) 25 | { 26 | while (++i_j[1] < 3) 27 | { 28 | aux[i_j[0]]->o[i_j[1]] = l[i_j[0]]->o[i_j[1]]; 29 | aux[i_j[0]]->rgb[i_j[1]] = l[i_j[0]]->rgb[i_j[1]]; 30 | } 31 | aux[i_j[0]]->col = l[i_j[0]]->col; 32 | } 33 | else 34 | { 35 | while (++i_j[1] < 3) 36 | aux[i_j[0]]->o[i_j[1]] = o[i_j[1]]; 37 | hex_to_rgb(var[1], (int *)aux[i_j[0]]->rgb); 38 | aux[i_j[0]]->col = var[1]; 39 | } 40 | } 41 | aux[i_j[0]] = 0; 42 | } 43 | 44 | t_light **add_l(t_light **l, double *o, int c) 45 | { 46 | t_light **aux; 47 | int var[2]; 48 | int i; 49 | 50 | var[0] = 0; 51 | var[1] = c; 52 | while (l[var[0]]) 53 | var[0]++; 54 | if (!(aux = (t_light **)malloc(sizeof(t_light *) * (var[0] + 2)))) 55 | return (l); 56 | set_l(l, aux, o, var); 57 | i = 0; 58 | if (var[0]) 59 | while (l[i]) 60 | free(l[i++]); 61 | free(l); 62 | return (aux); 63 | } 64 | -------------------------------------------------------------------------------- /obj/add_pl.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* add_pl.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/27 16:33:45 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/04 14:51:44 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../raymarching.h" 14 | 15 | static void cpy_pl(t_plane **pl, t_plane **aux, int i) 16 | { 17 | int j; 18 | 19 | j = -1; 20 | while (++j < 3) 21 | { 22 | aux[i]->o[j] = pl[i]->o[j]; 23 | aux[i]->v[j] = pl[i]->v[j]; 24 | } 25 | aux[i]->col = pl[i]->col; 26 | } 27 | 28 | static void set_pl(t_plane **pl, t_plane **aux, double **o_v, int *var) 29 | { 30 | int i; 31 | int j; 32 | 33 | i = -1; 34 | while (++i < var[0] + 1) 35 | { 36 | aux[i] = (t_plane *)malloc(sizeof(t_plane)); 37 | if (i < var[0]) 38 | cpy_pl(pl, aux, i); 39 | else 40 | { 41 | j = -1; 42 | while (++j < 3) 43 | { 44 | aux[i]->o[j] = o_v[0][j]; 45 | aux[i]->v[j] = o_v[1][j]; 46 | } 47 | aux[i]->col = var[1]; 48 | } 49 | } 50 | aux[i] = 0; 51 | } 52 | 53 | t_plane **add_pl(t_plane **pl, double *o, double *v, int c) 54 | { 55 | t_plane **aux; 56 | double vn[3]; 57 | double **o_v; 58 | int var[2]; 59 | int i; 60 | 61 | var[0] = 0; 62 | var[1] = c; 63 | while (pl[var[0]]) 64 | var[0]++; 65 | if (!(aux = (t_plane **)malloc(sizeof(t_plane *) * (var[0] + 2))) || 66 | !(o_v = (double **)malloc(sizeof(double *) * 2))) 67 | return (pl); 68 | o_v[0] = o; 69 | o_v[1] = v; 70 | norm(v, vn); 71 | set_pl(pl, aux, o_v, var); 72 | i = 0; 73 | if (var[0]) 74 | while (pl[i]) 75 | free(pl[i++]); 76 | free(pl); 77 | free(o_v); 78 | return (aux); 79 | } 80 | -------------------------------------------------------------------------------- /obj/add_sp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* add_sp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/27 15:48:06 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/04 17:22:04 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../raymarching.h" 14 | 15 | static void cpy_sp(t_sphere **sp, t_sphere **aux, int i) 16 | { 17 | int j; 18 | 19 | j = -1; 20 | while (++j < 3) 21 | aux[i]->o[j] = sp[i]->o[j]; 22 | aux[i]->r = sp[i]->r; 23 | aux[i]->col = sp[i]->col; 24 | } 25 | 26 | static void new_sp(t_sphere **aux, double *o, double r, int *var) 27 | { 28 | int j; 29 | 30 | j = -1; 31 | while (++j < 3) 32 | aux[var[2]]->o[j] = o[j]; 33 | aux[var[2]]->r = r; 34 | aux[var[2]]->col = var[1]; 35 | } 36 | 37 | static int sp_init(t_sphere **sp, t_sphere ***aux, int *var, int c) 38 | { 39 | var[0] = 0; 40 | var[1] = c; 41 | while (sp[var[0]]) 42 | var[0]++; 43 | if (!(*aux = (t_sphere **)malloc(sizeof(t_sphere *) * (var[0] + 2)))) 44 | return (1); 45 | return (0); 46 | } 47 | 48 | /* 49 | ** var[3] = len, c, i 50 | */ 51 | 52 | t_sphere **add_sp(t_sphere **sp, double *o, double r, int c) 53 | { 54 | t_sphere **aux; 55 | int var[3]; 56 | 57 | if (sp_init(sp, &aux, var, c)) 58 | return (sp); 59 | var[2] = -1; 60 | while (++var[2] < var[0] + 1) 61 | { 62 | aux[var[2]] = (t_sphere *)malloc(sizeof(t_sphere)); 63 | if (var[2] < var[0]) 64 | cpy_sp(sp, aux, var[2]); 65 | else 66 | new_sp(aux, o, r, var); 67 | } 68 | aux[var[2]] = 0; 69 | var[2] = 0; 70 | if (var[0]) 71 | while (sp[var[2]]) 72 | free(sp[var[2]++]); 73 | free(sp); 74 | return (aux); 75 | } 76 | -------------------------------------------------------------------------------- /obj/add_sq.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* add_sq.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/27 16:42:18 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/04 16:53:47 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../raymarching.h" 14 | 15 | static void cpy_sq(t_square **sq, t_square **aux, int i) 16 | { 17 | int j; 18 | 19 | j = -1; 20 | while (++j < 3) 21 | { 22 | aux[i]->o[j] = sq[i]->o[j]; 23 | aux[i]->v[j] = sq[i]->v[j]; 24 | aux[i]->x[j] = sq[i]->x[j]; 25 | aux[i]->y[j] = sq[i]->y[j]; 26 | } 27 | aux[i]->h = sq[i]->h; 28 | aux[i]->col = sq[i]->col; 29 | } 30 | 31 | static void new_sq(t_square **aux, double **o_v, double h, int *var) 32 | { 33 | int j; 34 | 35 | j = -1; 36 | while (++j < 3) 37 | { 38 | aux[var[0]]->o[j] = o_v[0][j]; 39 | aux[var[0]]->v[j] = o_v[1][j]; 40 | } 41 | aux[var[0]]->x[0] = 0; 42 | aux[var[0]]->x[1] = -o_v[1][2]; 43 | aux[var[0]]->x[2] = o_v[1][1]; 44 | j = -1; 45 | while (++j < 3) 46 | aux[var[0]]->y[j] = cross_prod(o_v[1], aux[var[0]]->x, j); 47 | norm(aux[var[0]]->y, aux[var[0]]->y); 48 | aux[var[0]]->h = h; 49 | aux[var[0]]->col = var[1]; 50 | } 51 | 52 | static t_square **init_sq(t_square **sq, int *var) 53 | { 54 | t_square **aux; 55 | 56 | var[2] = 0; 57 | while (sq[var[2]]) 58 | var[2]++; 59 | if (!(aux = (t_square **)malloc(sizeof(t_square *) * (var[2] + 2)))) 60 | return (0); 61 | return (aux); 62 | } 63 | 64 | /* 65 | ** var[3] = i, c, len 66 | */ 67 | 68 | t_square **add_sq(t_square **sq, double **o_v, double h, int c) 69 | { 70 | t_square **aux; 71 | int var[3]; 72 | 73 | if (!(aux = init_sq(sq, var))) 74 | return (sq); 75 | var[1] = c; 76 | norm(o_v[1], o_v[1]); 77 | var[0] = -1; 78 | while (++var[0] < var[2] + 1) 79 | { 80 | aux[var[0]] = (t_square *)malloc(sizeof(t_square)); 81 | if (var[0] < var[2]) 82 | cpy_sq(sq, aux, var[0]); 83 | else 84 | new_sq(aux, o_v, h, var); 85 | } 86 | aux[var[0]] = 0; 87 | var[0] = 0; 88 | if (var[2]) 89 | while (sq[var[0]]) 90 | free(sq[var[0]++]); 91 | free(sq); 92 | return (aux); 93 | } 94 | -------------------------------------------------------------------------------- /obj/add_tr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* add_tr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/27 18:48:44 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/04 17:22:11 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../raymarching.h" 14 | 15 | static void cpy_tr(t_triangle **tr, t_triangle **aux, int i) 16 | { 17 | int j; 18 | 19 | j = -1; 20 | while (++j < 3) 21 | { 22 | aux[i]->a[j] = tr[i]->a[j]; 23 | aux[i]->b[j] = tr[i]->b[j]; 24 | aux[i]->c[j] = tr[i]->c[j]; 25 | aux[i]->ab[j] = tr[i]->ab[j]; 26 | aux[i]->ac[j] = tr[i]->ac[j]; 27 | aux[i]->nor[j] = tr[i]->nor[j]; 28 | } 29 | aux[i]->col = tr[i]->col; 30 | } 31 | 32 | static void new_tr(t_triangle **aux, double **abc, int *var) 33 | { 34 | int j; 35 | 36 | j = -1; 37 | while (++j < 3) 38 | { 39 | aux[var[0]]->a[j] = abc[0][j]; 40 | aux[var[0]]->b[j] = abc[1][j]; 41 | aux[var[0]]->c[j] = abc[2][j]; 42 | aux[var[0]]->ab[j] = abc[1][j] - abc[0][j]; 43 | aux[var[0]]->ac[j] = abc[2][j] - abc[0][j]; 44 | } 45 | j = -1; 46 | while (++j < 3) 47 | aux[var[0]]->nor[j] = cross_prod(aux[var[0]]->ab, aux[var[0]]->ac, j); 48 | norm(aux[var[0]]->nor, aux[var[0]]->nor); 49 | aux[var[0]]->col = var[1]; 50 | } 51 | 52 | /* 53 | ** var[3] = i, c, len 54 | */ 55 | 56 | t_triangle **add_tr(t_triangle **tr, double **abc, int c) 57 | { 58 | t_triangle **aux; 59 | int var[3]; 60 | 61 | var[2] = 0; 62 | while (tr[var[2]]) 63 | var[2]++; 64 | if (!(aux = (t_triangle **)malloc(sizeof(t_triangle *) * (var[2] + 2)))) 65 | return (tr); 66 | var[1] = c; 67 | var[0] = -1; 68 | while (++var[0] < var[2] + 1) 69 | { 70 | aux[var[0]] = (t_triangle *)malloc(sizeof(t_triangle)); 71 | if (var[0] < var[2]) 72 | cpy_tr(tr, aux, var[1]); 73 | else 74 | new_tr(aux, abc, var); 75 | } 76 | aux[var[0]] = 0; 77 | var[0] = 0; 78 | if (var[2]) 79 | while (tr[var[0]]) 80 | free(tr[var[0]++]); 81 | free(tr); 82 | return (aux); 83 | } 84 | -------------------------------------------------------------------------------- /parse/def_bx.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* def_bx.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/30 15:37:26 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/04 23:56:58 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../raymarching.h" 14 | #include "def_ft.h" 15 | 16 | static void bx_points(char *line, int *error, double **p_v, int *i) 17 | { 18 | while (line[*i] == ' ' || line[*i] == '\t') 19 | (*i)++; 20 | error += def_p(line, i, p_v[0]); 21 | while (line[*i] == ' ' || line[*i] == '\t') 22 | (*i)++; 23 | error += def_p(line, i, p_v[1]); 24 | } 25 | 26 | int def_bx(t_data *param, char *line) 27 | { 28 | int i; 29 | double *p_v[2]; 30 | double h; 31 | int rgb[3]; 32 | int c_error[2]; 33 | 34 | i = 2; 35 | c_error[1] = 0; 36 | p_v[0] = (double *)malloc(sizeof(double) * 3); 37 | p_v[1] = (double *)malloc(sizeof(double) * 3); 38 | bx_points(line, &c_error[1], p_v, &i); 39 | while (line[i] == ' ' || line[i] == '\t') 40 | i++; 41 | c_error[1] += def_d(line, &i, &h); 42 | while (line[i] == ' ' || line[i] == '\t') 43 | i++; 44 | c_error[1] += def_rgb(line, &i, rgb, 1); 45 | rgb_to_hex(rgb, &c_error[0]); 46 | param->bx = add_bx(param->bx, p_v, h, c_error[0]); 47 | free(p_v[0]); 48 | free(p_v[1]); 49 | if (c_error[1]) 50 | return (1); 51 | return (0); 52 | } 53 | -------------------------------------------------------------------------------- /parse/def_cy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* def_cy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/30 12:07:29 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/05 00:34:12 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../raymarching.h" 14 | #include "def_ft.h" 15 | 16 | static void cy_points(char *line, int *i_c_error, double **p_v) 17 | { 18 | while (line[i_c_error[0]] == ' ' || line[i_c_error[0]] == '\t') 19 | i_c_error[0]++; 20 | i_c_error[2] += def_p(line, &i_c_error[0], p_v[0]); 21 | while (line[i_c_error[0]] == ' ' || line[i_c_error[0]] == '\t') 22 | i_c_error[0]++; 23 | i_c_error[2] += def_p(line, &i_c_error[0], p_v[1]); 24 | while (line[i_c_error[0]] == ' ' || line[i_c_error[0]] == '\t') 25 | i_c_error[0]++; 26 | } 27 | 28 | int def_cy(t_data *param, char *line) 29 | { 30 | double *p_v[2]; 31 | double d_h[2]; 32 | int rgb[3]; 33 | int i_c_error[3]; 34 | 35 | i_c_error[0] = 2; 36 | i_c_error[2] = 0; 37 | p_v[0] = (double *)malloc(sizeof(double) * 2); 38 | p_v[1] = (double *)malloc(sizeof(double) * 2); 39 | cy_points(line, i_c_error, p_v); 40 | i_c_error[2] += def_rgb(line, &i_c_error[0], rgb, 1); 41 | while (line[i_c_error[0]] == ' ' || line[i_c_error[0]] == '\t') 42 | i_c_error[0]++; 43 | i_c_error[2] += def_d(line, &i_c_error[0], &d_h[0]); 44 | while (line[i_c_error[0]] == ' ' || line[i_c_error[0]] == '\t') 45 | i_c_error[0]++; 46 | i_c_error[2] += def_d(line, &i_c_error[0], &d_h[1]); 47 | rgb_to_hex(rgb, &i_c_error[1]); 48 | param->cy = add_cy(param->cy, p_v, d_h, i_c_error[1]); 49 | free(p_v[0]); 50 | free(p_v[1]); 51 | if (i_c_error[2]) 52 | return (1); 53 | return (0); 54 | } 55 | -------------------------------------------------------------------------------- /parse/def_ft.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* def_ft.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/30 16:15:51 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/05 00:33:29 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "def_ft.h" 14 | 15 | int def_p(char *line, int *i, double *p) 16 | { 17 | int j; 18 | 19 | if (!ft_isdigit(line[*i]) && line[*i] != '-') 20 | return (1); 21 | j = -1; 22 | while (++j < 3) 23 | { 24 | if (def_d(line, i, p + j)) 25 | return (1); 26 | if (j < 2) 27 | { 28 | if (line[*i] != ',') 29 | return (1); 30 | (*i)++; 31 | } 32 | } 33 | while (ft_isdigit(line[*i])) 34 | (*i)++; 35 | if (line[*i] != ' ' && line[*i] != '\t' && line[*i]) 36 | return (1); 37 | return (0); 38 | } 39 | 40 | int def_d(char *line, int *i, double *d) 41 | { 42 | int num_len; 43 | 44 | if (!ft_isdigit(line[*i]) && line[*i] != '-') 45 | return (1); 46 | *d = (double)ft_atoi(line + *i); 47 | while (ft_isdigit(line[*i]) || line[*i] == '-') 48 | (*i)++; 49 | num_len = 0; 50 | if (line[*i] == '.') 51 | { 52 | (*i)++; 53 | while (ft_isdigit(line[*i + num_len])) 54 | num_len++; 55 | if (num_len) 56 | *d += (double)ft_atoi(line + *i) / pow(10, num_len); 57 | else 58 | return (1); 59 | *i += num_len; 60 | } 61 | return (0); 62 | } 63 | 64 | int def_rgb(char *line, int *i, int *rgb, double alpha) 65 | { 66 | int j; 67 | 68 | j = -1; 69 | while (++j < 3) 70 | { 71 | if (!ft_isdigit(line[*i])) 72 | return (1); 73 | rgb[j] = ft_atoi(line + *i) * alpha; 74 | while (ft_isdigit(line[*i])) 75 | (*i)++; 76 | if (j < 2) 77 | { 78 | if (line[*i] != ',') 79 | return (1); 80 | (*i)++; 81 | } 82 | } 83 | if (!(line[*i] == ' ' || line[*i] == '\t' || !line[*i])) 84 | return (1); 85 | return (0); 86 | } 87 | -------------------------------------------------------------------------------- /parse/def_ft.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* def_ft.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/30 16:14:39 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/05 13:57:29 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef DEF_FT_H 14 | # define DEF_FT_H 15 | 16 | # include "../raymarching.h" 17 | 18 | int def_p(char *line, int *i, double *p); 19 | int def_d(char *line, int *i, double *d); 20 | int def_rgb(char *line, int *i, int *rgb, double alpha); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /parse/def_obj.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* def_obj.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/30 10:12:24 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/03 23:53:02 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../raymarching.h" 14 | 15 | int def_obj(t_data *param, char *line) 16 | { 17 | int error; 18 | 19 | error = 0; 20 | if (!ft_memcmp(line, "sp", 2)) 21 | error += def_sp(param, line); 22 | else if (!ft_memcmp(line, "pl", 2)) 23 | error += def_pl(param, line); 24 | else if (!ft_memcmp(line, "cy", 2)) 25 | error += def_cy(param, line); 26 | else if (!ft_memcmp(line, "sq", 2)) 27 | error += def_sq(param, line); 28 | else if (!ft_memcmp(line, "tr", 2)) 29 | error += def_tr(param, line); 30 | else if (!ft_memcmp(line, "bx", 2)) 31 | error += def_bx(param, line); 32 | if (error) 33 | return (1); 34 | return (0); 35 | } 36 | -------------------------------------------------------------------------------- /parse/def_pl.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* def_pl.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/30 11:47:58 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/04 23:59:13 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../raymarching.h" 14 | #include "def_ft.h" 15 | 16 | int def_pl(t_data *param, char *line) 17 | { 18 | int i; 19 | double p[3]; 20 | double v[3]; 21 | int rgb[3]; 22 | int c_error[2]; 23 | 24 | c_error[1] = 0; 25 | i = 2; 26 | while (line[i] == ' ' || line[i] == '\t') 27 | i++; 28 | c_error[1] += def_p(line, &i, p); 29 | while (line[i] == ' ' || line[i] == '\t') 30 | i++; 31 | c_error[1] += def_p(line, &i, v); 32 | while (line[i] == ' ' || line[i] == '\t') 33 | i++; 34 | c_error[1] += def_rgb(line, &i, rgb, 1); 35 | rgb_to_hex(rgb, &c_error[0]); 36 | param->pl = add_pl(param->pl, p, v, c_error[0]); 37 | if (c_error[1]) 38 | return (1); 39 | return (0); 40 | } 41 | -------------------------------------------------------------------------------- /parse/def_sp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* def_sp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/30 11:33:04 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/04 23:59:14 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../raymarching.h" 14 | #include "def_ft.h" 15 | 16 | int def_sp(t_data *param, char *line) 17 | { 18 | int i; 19 | double p[3]; 20 | double d; 21 | int rgb[3]; 22 | int c_error[2]; 23 | 24 | i = 2; 25 | c_error[1] = 0; 26 | while (line[i] == ' ' || line[i] == '\t') 27 | i++; 28 | c_error[1] += def_p(line, &i, p); 29 | while (line[i] == ' ' || line[i] == '\t') 30 | i++; 31 | c_error[1] += def_d(line, &i, &d); 32 | while (line[i] == ' ' || line[i] == '\t') 33 | i++; 34 | c_error[1] += def_rgb(line, &i, rgb, 1); 35 | rgb_to_hex(rgb, &c_error[0]); 36 | param->sp = add_sp(param->sp, p, d / 2, c_error[0]); 37 | if (c_error[1]) 38 | return (1); 39 | return (0); 40 | } 41 | -------------------------------------------------------------------------------- /parse/def_sq.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* def_sq.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/30 14:04:34 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/05 00:13:25 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../raymarching.h" 14 | #include "def_ft.h" 15 | 16 | static void sq_points(char *line, int *c_error, double **p_v, int *i) 17 | { 18 | while (line[*i] == ' ' || line[*i] == '\t') 19 | (*i)++; 20 | c_error[1] += def_p(line, i, p_v[0]); 21 | while (line[*i] == ' ' || line[*i] == '\t') 22 | (*i)++; 23 | c_error[1] += def_p(line, i, p_v[1]); 24 | } 25 | 26 | int def_sq(t_data *param, char *line) 27 | { 28 | int i; 29 | double *p_v[2]; 30 | double h; 31 | int rgb[3]; 32 | int c_error[2]; 33 | 34 | i = 2; 35 | c_error[1] = 0; 36 | p_v[0] = (double *)malloc(sizeof(double) * 3); 37 | p_v[1] = (double *)malloc(sizeof(double) * 3); 38 | sq_points(line, c_error, p_v, &i); 39 | while (line[i] == ' ' || line[i] == '\t') 40 | i++; 41 | c_error[1] += def_d(line, &i, &h); 42 | while (line[i] == ' ' || line[i] == '\t') 43 | i++; 44 | c_error[1] += def_rgb(line, &i, rgb, 1); 45 | rgb_to_hex(rgb, &c_error[0]); 46 | param->sq = add_sq(param->sq, p_v, h, c_error[0]); 47 | free(p_v[0]); 48 | free(p_v[1]); 49 | if (c_error[1]) 50 | return (1); 51 | return (0); 52 | } 53 | -------------------------------------------------------------------------------- /parse/def_tr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* def_tr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/30 14:21:06 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/05 00:23:48 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../raymarching.h" 14 | #include "def_ft.h" 15 | 16 | static void tr_points(char *line, double **abc, int *error, int *i) 17 | { 18 | while (line[*i] == ' ' || line[*i] == '\t') 19 | (*i)++; 20 | error += def_p(line, i, abc[0]); 21 | while (line[*i] == ' ' || line[*i] == '\t') 22 | (*i)++; 23 | error += def_p(line, i, abc[1]); 24 | while (line[*i] == ' ' || line[*i] == '\t') 25 | (*i)++; 26 | error += def_p(line, i, abc[2]); 27 | while (line[*i] == ' ' || line[*i] == '\t') 28 | (*i)++; 29 | } 30 | 31 | int def_tr(t_data *param, char *line) 32 | { 33 | int i; 34 | double *abc[3]; 35 | int rgb[3]; 36 | int c; 37 | int error; 38 | 39 | i = 2; 40 | error = 0; 41 | abc[0] = (double *)malloc(sizeof(double) * 3); 42 | abc[1] = (double *)malloc(sizeof(double) * 3); 43 | abc[2] = (double *)malloc(sizeof(double) * 3); 44 | tr_points(line, abc, &error, &i); 45 | error += def_rgb(line, &i, rgb, 1); 46 | rgb_to_hex(rgb, &c); 47 | param->tr = add_tr(param->tr, abc, c); 48 | free(abc[0]); 49 | free(abc[1]); 50 | free(abc[2]); 51 | if (error) 52 | return (1); 53 | return (0); 54 | } 55 | -------------------------------------------------------------------------------- /parser.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* parser.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/29 13:40:28 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/04 12:39:50 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "raymarching.h" 14 | 15 | void parse(t_data *param, char **argv) 16 | { 17 | int fd; 18 | char *line; 19 | int error; 20 | int final[2]; 21 | 22 | fd = open(argv[1], O_RDONLY); 23 | error = 0; 24 | final[0] = 1; 25 | final[1] = 0; 26 | while (final[0]) 27 | { 28 | final[1] = (!get_next_line(fd, &line)) ? 1 : 0; 29 | final[0] -= final[1]; 30 | error += def_settings(param, line); 31 | error += def_obj(param, line); 32 | error += def_elm(param, line); 33 | free(line); 34 | } 35 | close(fd); 36 | if (error) 37 | { 38 | write(1, "Error\n", 7); 39 | write(1, "Invalid .rt file\n", 18); 40 | ft_exit(param); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eljommys/miniRT-for-Linux/eab601438e45078749b0d19259bc1569e92113c0/preview.png -------------------------------------------------------------------------------- /save.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* save.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/11/02 14:19:38 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/05 15:17:17 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "raymarching.h" 14 | 15 | static void dec_hex_endian(int len, unsigned char *size) 16 | { 17 | int i; 18 | 19 | i = -1; 20 | while (++i < 4) 21 | { 22 | size[i] = len % 256; 23 | len /= 256; 24 | } 25 | } 26 | 27 | static void write_header(t_data *param, int fd) 28 | { 29 | unsigned char bytes[4]; 30 | int len; 31 | 32 | len = param->scr.y * param->img.line_length + 33 | param->scr.x * (param->img.bits_per_pixel / 8); 34 | write(fd, "BM", 2); 35 | dec_hex_endian(len + 54, bytes); 36 | write(fd, bytes, 4); 37 | write(fd, "\0\0\0\0\66\0\0\0\50\0\0\0", 12); 38 | dec_hex_endian(param->scr.x, bytes); 39 | write(fd, bytes, 4); 40 | dec_hex_endian(param->scr.y, bytes); 41 | write(fd, bytes, 4); 42 | write(fd, "\1\0\40\0\0\0\0\0", 8); 43 | dec_hex_endian(0, bytes); 44 | write(fd, bytes, 4); 45 | dec_hex_endian(param->scr.x, bytes); 46 | write(fd, bytes, 4); 47 | dec_hex_endian(param->scr.y, bytes); 48 | write(fd, bytes, 4); 49 | write(fd, "\0\0\0\0\0\0\0\0", 8); 50 | } 51 | 52 | void save_scr(t_data *param) 53 | { 54 | int fd; 55 | int i; 56 | 57 | param->key = KEY_ENT; 58 | show_obj(param); 59 | fd = open("screenshot.bmp", O_WRONLY | O_CREAT); 60 | write_header(param, fd); 61 | i = param->scr.y; 62 | while (--i >= 0) 63 | write(fd, param->img.addr + i * param->img.line_length, 64 | param->scr.x * (param->img.bits_per_pixel / 8)); 65 | close(fd); 66 | } 67 | -------------------------------------------------------------------------------- /test_func.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_func.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: jserrano +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2020/10/17 13:45:20 by jserrano #+# #+# */ 9 | /* Updated: 2020/11/04 17:22:41 by jserrano ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "raymarching.h" 14 | 15 | static void draw_pixel(t_data *param, int x, int y) 16 | { 17 | int i; 18 | 19 | gen_ray(param, x, y, 1); 20 | param->cam.ray.ray_c = param->amb_l; 21 | if (is_hit(param)) 22 | { 23 | i = -1; 24 | while (param->l[++i]) 25 | bounce_ray(param, i); 26 | i = -1; 27 | while (++i < 3) 28 | param->cam.ray.ray_rgb[i] = (param->cam.ray.ray_rgb_o[i] * 29 | (double)param->cam.ray.ray_rgb_l[i] / 255) + 30 | (param->cam.ray.ray_rgb_o[i] * (double)param->amb_l_rgb[i] / 255); 31 | rgb_to_hex(param->cam.ray.ray_rgb, ¶m->cam.ray.ray_c); 32 | } 33 | my_mlx_pixel_put(param, x, y, param->cam.ray.ray_c); 34 | } 35 | 36 | int show_obj(t_data *param) 37 | { 38 | int x; 39 | int y; 40 | int step; 41 | 42 | step = (param->key == KEY_ENT) ? 1 : 8; 43 | y = -1; 44 | while (++y < param->scr.y) 45 | { 46 | x = -1; 47 | while (++x < param->scr.x) 48 | { 49 | if (!(x % step) && !(y % step)) 50 | draw_pixel(param, x, y); 51 | else 52 | my_mlx_pixel_put(param, x, y, 0); 53 | } 54 | } 55 | mlx_put_image_to_window(param->id, param->win_id, param->img.img, 0, 0); 56 | return (0); 57 | } 58 | --------------------------------------------------------------------------------