Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2088e43

Browse files
News
The parsing is done Some math tools were developped
1 parent 70e61eb commit 2088e43

File tree

230 files changed

+23119
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

230 files changed

+23119
-0
lines changed

‎Makefile‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# **************************************************************************** #
2+
# #
3+
# ::: :::::::: #
4+
# Makefile :+: :+: :+: #
5+
# +:+ +:+ +:+ #
6+
# By: TheTerror <jfaye@student.42lyon.fr> +#+ +:+ +#+ #
7+
# +#+#+#+#+#+ +#+ #
8+
# Created: 2023年08月17日 16:29:00 by TheTerror #+# #+# #
9+
# Updated: 2023年08月20日 17:40:52 by TheTerror ### ########lyon.fr #
10+
# #
11+
# **************************************************************************** #
12+
13+
NAME = miniRT
14+
LIBFT_LIB = $(LIBFT_PATH)libft.a
15+
16+
17+
LIBFT_PATH = ./libft/
18+
OBJ_PATH = ./.objs/
19+
MEMTOOLS_PATH = ./memtools/
20+
PARSING_PATH = ./parsing/
21+
22+
23+
24+
INCLUDE = minirt.h preprocss.h $(LIBFT_PATH)libft.h $(MEMTOOLS_PATH)memtools.h
25+
26+
CC = cc
27+
CFLAGS= -Wall -Werror -Wextra
28+
MLX_OBJ_OPTIONS = -I/usr/include -Imlx_linux -O3
29+
MLX_LINK_OPTIONS = -Lmlx_linux -lmlx_Linux -L/usr/lib -Imlx_linux -lXext -lX11 -lm -lz
30+
RM = rm -rf
31+
32+
SRC_MEMTOOLS = $(addprefix $(MEMTOOLS_PATH), initmem.c freemem.c init_elms.c free_elms.c)
33+
SRC_PARSING = $(addprefix $(PARSING_PATH), parsing.c ambient.c camera.c light.c \
34+
sphere.c plane.c cylindre.c)
35+
SRC = main.c minirt.c ft_mlx_utils.c events.c utils.c display.c ft_atod.c $(SRC_MEMTOOLS) $(SRC_PARSING)
36+
37+
# OBJ = $(addprefix $(OBJ_PATH), $(notdir $(SRC:%.c=%.o)))
38+
OBJ = $(SRC:%.c=%.o)
39+
40+
all : mk_objdir make_libft $(NAME)
41+
42+
%.o : %.c $(INCLUDE) $(LIBFT_LIB)
43+
$(CC) $(CFLAGS) $(MLX_OBJ_OPTIONS) -c $< -o $@
44+
# mv $@ $(OBJ_PATH)
45+
46+
make_libft :
47+
make -C $(LIBFT_PATH)
48+
49+
$(NAME) : $(OBJ) $(INCLUDE)
50+
$(CC) $(CFLAGS) $(OBJ) $(LIBFT_LIB) $(MLX_LINK_OPTIONS) -o $@
51+
52+
mk_objdir :
53+
@mkdir -p $(OBJ_PATH)
54+
55+
clean :
56+
@make clean -C $(LIBFT_PATH)
57+
@$(RM) $(OBJ)
58+
@$(RM) $(OBJ_PATH)
59+
fclean : clean
60+
@make fclean -C $(LIBFT_PATH)
61+
@$(RM) $(NAME)
62+
re : fclean all

‎display.c‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* display.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: TheTerror <jfaye@student.42lyon.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023年08月20日 17:15:36 by TheTerror #+# #+# */
9+
/* Updated: 2023年08月20日 22:48:36 by TheTerror ### ########lyon.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "minirt.h"
14+
15+
t_bool ft_displayothers(t_vars *v);
16+
17+
t_bool ft_displayelms(t_vars *v)
18+
{
19+
int i;
20+
21+
printf("A %.2f %d,%d,%d\n", v->a->ratio, v->a->r, v->a->g, v->a->b);
22+
printf(\
23+
"C %.2f,%.2f,%.2f %.2f,%.2f,%.2f %.2f\n", v->c->pov.x, v->c->pov.y, \
24+
v->c->pov.z, v->c->dir.x, v->c->dir.y, v->c->dir.z, v->c->fov);
25+
printf("L %.2f,%.2f,%.2f %.2f %d,%d,%d\n", v->l->pol.x, \
26+
v->l->pol.y, v->l->pol.z, v->l->ratio, v->l->r, v->l->g, v->l->b);
27+
i = 0;
28+
while (v->sp[i])
29+
{
30+
printf("sp %.2f,%.2f,%.2f %.2f %d,%d,%d\n", \
31+
v->sp[i]->o.x, v->sp[i]->o.y, v->sp[i]->o.z, v->sp[i]->d, \
32+
v->sp[i]->r, v->sp[i]->g, v->sp[i]->b);
33+
i++;
34+
}
35+
ft_displayothers(v);
36+
return (__TRUE);
37+
}
38+
39+
t_bool ft_displayothers(t_vars *v)
40+
{
41+
int i;
42+
43+
i = 0;
44+
while (v->pl[i])
45+
{
46+
printf(\
47+
"pl %.2f,%.2f,%.2f %.2f,%.2f,%.2f %d,%d,%d\n", v->pl[i]->p.x, \
48+
v->pl[i]->p.y, v->pl[i]->p.z, v->pl[i]->dir.x, v->pl[i]->dir.y, \
49+
v->pl[i]->dir.z, v->pl[i]->r, v->pl[i]->g, v->pl[i]->b);
50+
i++;
51+
}
52+
i = 0;
53+
while (v->cy[i])
54+
{
55+
printf(\
56+
"cy %.2f,%.2f,%.2f %.2f,%.2f,%.2f %.2f %.2f %d,%d,%d\n", \
57+
v->cy[i]->o.x, v->cy[i]->o.y, v->cy[i]->o.z, v->cy[i]->dir.x, \
58+
v->cy[i]->dir.y, v->cy[i]->dir.z, v->cy[i]->d, v->cy[i]->h, \
59+
v->cy[i]->r, v->cy[i]->g, v->cy[i]->b);
60+
i++;
61+
}
62+
return (__TRUE);
63+
}

‎events.c‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* events.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: TheTerror <jfaye@student.42lyon.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023年08月18日 19:20:10 by TheTerror #+# #+# */
9+
/* Updated: 2023年08月18日 19:25:17 by TheTerror ### ########lyon.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "minirt.h"
14+
15+
int ft_keyhook(int keycode, t_vars *v)
16+
{
17+
if (keycode == __ESC)
18+
ft_exitprocss(v, EXIT_SUCCESS);
19+
return (0);
20+
}
21+
int ft_xbutton_close(t_vars *v)
22+
{
23+
ft_exitprocss(v, EXIT_SUCCESS);
24+
return (0);
25+
}
26+
27+
void ft_events(t_vars *v)
28+
{
29+
mlx_hook(v->win, __ON_DESTROY, 0, ft_xbutton_close, v);
30+
mlx_hook(v->win, __ON_KEYUP, __KEYRELEASEMASK, ft_keyhook, v);
31+
}

‎ft_atod.c‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_atod.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: TheTerror <jfaye@student.42lyon.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023年08月19日 21:19:02 by TheTerror #+# #+# */
9+
/* Updated: 2023年08月19日 21:20:24 by TheTerror ### ########lyon.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "minirt.h"
14+
15+
typedef struct s_tools
16+
{
17+
unsigned int i;
18+
int sign;
19+
double dec;
20+
double fdb;
21+
double n;
22+
} t_tools;
23+
24+
void ft_init_skip(t_tools *x, const char *nptr);
25+
26+
double ft_atod(const char *nptr)
27+
{
28+
t_tools x;
29+
30+
ft_init_skip(&x, nptr);
31+
while (nptr[x.i] >= '0' && nptr[x.i] <= '9')
32+
{
33+
x.fdb = (x.fdb * 10) + (nptr[x.i] - 48);
34+
x.i++;
35+
}
36+
if (nptr[x.i] == '.' && ft_isdigit(nptr[x.i + 1]))
37+
{
38+
x.i++;
39+
x.dec = 10;
40+
while (nptr[x.i] >= '0' && nptr[x.i] <= '9')
41+
{
42+
x.n = 0;
43+
x.n = (x.n * 10) + (nptr[x.i] - 48);
44+
x.n /= x.dec;
45+
x.fdb += x.n;
46+
x.dec *= 10;
47+
x.i++;
48+
}
49+
}
50+
return (x.fdb * x.sign);
51+
}
52+
53+
void ft_init_skip(t_tools *x, const char *nptr)
54+
{
55+
x->i = 0;
56+
x->fdb = 0;
57+
x->sign = 1;
58+
while (nptr[x->i] == ' ' || (nptr[x->i] >= 9 && nptr[x->i] <= 13))
59+
x->i++;
60+
if (nptr[x->i] == '+' || nptr[x->i] == '-')
61+
{
62+
if (nptr[x->i] == '-')
63+
x->sign = -1;
64+
x->i++;
65+
}
66+
}

‎ft_mlx_utils.c‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_mlx_utils.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: TheTerror <jfaye@student.42lyon.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023年02月17日 19:48:23 by TheTerror #+# #+# */
9+
/* Updated: 2023年08月18日 19:21:42 by TheTerror ### ########lyon.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "minirt.h"
14+
15+
t_bool ft_set_mlx(t_vars *v)
16+
{
17+
v->xptr = mlx_init();
18+
if (!v->xptr)
19+
return (__FALSE);
20+
v->win = mlx_new_window(v->xptr, _SIZE_X, _SIZE_Y, "miniRT");
21+
if (!v->win)
22+
return (__FALSE);
23+
v->im->img = mlx_new_image(v->xptr, _WIDHT, _HEIGHT);
24+
if (!v->im->img)
25+
return (__FALSE);
26+
v->im->addr = mlx_get_data_addr(v->im->img, &(v->im->bpp), \
27+
&(v->im->size_line), &(v->im->endian));
28+
return (__TRUE);
29+
}
30+
31+
void my_mlx_pixel_put(t_img *img, int x, int y, int color)
32+
{
33+
char *dst;
34+
35+
dst = img->addr + (y * img->size_line + x * (img->bpp / 8));
36+
*(unsigned int *)dst = color;
37+
}
38+
39+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /