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 c455b8e

Browse files
08/23/23 save
1 parent e7464e1 commit c455b8e

File tree

21 files changed

+264
-95
lines changed

21 files changed

+264
-95
lines changed

‎Makefile‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# By: TheTerror <jfaye@student.42lyon.fr> +#+ +:+ +#+ #
77
# +#+#+#+#+#+ +#+ #
88
# Created: 2023年08月17日 16:29:00 by TheTerror #+# #+# #
9-
# Updated: 2023/08/21 20:25:26 by TheTerror ### ########lyon.fr #
9+
# Updated: 2023/08/23 21:27:32 by TheTerror ### ########lyon.fr #
1010
# #
1111
# **************************************************************************** #
1212

@@ -16,8 +16,9 @@ LIBFT_LIB = $(LIBFT_PATH)libft.a
1616

1717
LIBFT_PATH = ./libft/
1818
OBJ_PATH = ./.objs/
19-
MEMTOOLS_PATH = ./memtools/
19+
INTERS_PATH = ./inters/
2020
MATHTOOLS_PATH = ./mathtools/
21+
MEMTOOLS_PATH = ./memtools/
2122
PARSING_PATH = ./parsing/
2223

2324

@@ -30,11 +31,14 @@ MLX_OBJ_OPTIONS = -I/usr/include -Imlx_linux -O3
3031
MLX_LINK_OPTIONS = -Lmlx_linux -lmlx_Linux -L/usr/lib -Imlx_linux -lXext -lX11 -lm -lz
3132
RM = rm -rf
3233

34+
SRC_INTERS = $(addprefix $(INTERS_PATH), ray_sphere.c ray_plane.c)
35+
SRC_MATHTOOLS = $(addprefix $(MATHTOOLS_PATH), converts.c vectors.c subtractions.c products.c \
36+
ft_square.c)
3337
SRC_MEMTOOLS = $(addprefix $(MEMTOOLS_PATH), initmem.c freemem.c init_elms.c free_elms.c)
34-
SRC_MATHTOOLS = $(addprefix $(MATHTOOLS_PATH), converts.c vectors.c subtractions.c products.c)
3538
SRC_PARSING = $(addprefix $(PARSING_PATH), parsing.c ambient.c camera.c light.c \
3639
sphere.c plane.c cylindre.c)
37-
SRC = main.c minirt.c ft_mlx_utils.c events.c utils.c display.c ft_atod.c $(SRC_MEMTOOLS) $(SRC_PARSING)
40+
SRC = main.c minirt.c ft_mlx_utils.c events.c utils.c display.c ft_atod.c $(SRC_MEMTOOLS) \
41+
$(SRC_PARSING) $(SRC_MATHTOOLS) $(SRC_INTERS)
3842

3943
# OBJ = $(addprefix $(OBJ_PATH), $(notdir $(SRC:%.c=%.o)))
4044
OBJ = $(SRC:%.c=%.o)

‎display.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: TheTerror <jfaye@student.42lyon.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023年08月20日 17:15:36 by TheTerror #+# #+# */
9-
/* Updated: 2023/08/20 22:48:36 by TheTerror ### ########lyon.fr */
9+
/* Updated: 2023/08/23 16:27:26 by TheTerror ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -18,18 +18,18 @@ t_bool ft_displayelms(t_vars *v)
1818
{
1919
int i;
2020

21-
printf("A %.2f %d,%d,%d\n", v->a->ratio, v->a->r, v->a->g, v->a->b);
21+
printf("A %.2f %d,%d,%d\n", v->a->ratio, v->a->rgb.r, v->a->rgb.g, v->a->rgb.b);
2222
printf(\
2323
"C %.2f,%.2f,%.2f %.2f,%.2f,%.2f %.2f\n", v->c->pov.x, v->c->pov.y, \
2424
v->c->pov.z, v->c->dir.x, v->c->dir.y, v->c->dir.z, v->c->fov);
2525
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);
26+
v->l->pol.y, v->l->pol.z, v->l->ratio, v->l->rgb.r, v->l->rgb.g, v->l->rgb.b);
2727
i = 0;
2828
while (v->sp[i])
2929
{
3030
printf("sp %.2f,%.2f,%.2f %.2f %d,%d,%d\n", \
3131
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);
32+
v->sp[i]->rgb.r, v->sp[i]->rgb.g, v->sp[i]->rgb.b);
3333
i++;
3434
}
3535
ft_displayothers(v);
@@ -46,7 +46,7 @@ t_bool ft_displayothers(t_vars *v)
4646
printf(\
4747
"pl %.2f,%.2f,%.2f %.2f,%.2f,%.2f %d,%d,%d\n", v->pl[i]->p.x, \
4848
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);
49+
v->pl[i]->dir.z, v->pl[i]->rgb.r, v->pl[i]->rgb.g, v->pl[i]->rgb.b);
5050
i++;
5151
}
5252
i = 0;
@@ -56,7 +56,7 @@ t_bool ft_displayothers(t_vars *v)
5656
"cy %.2f,%.2f,%.2f %.2f,%.2f,%.2f %.2f %.2f %d,%d,%d\n", \
5757
v->cy[i]->o.x, v->cy[i]->o.y, v->cy[i]->o.z, v->cy[i]->dir.x, \
5858
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);
59+
v->cy[i]->rgb.r, v->cy[i]->rgb.g, v->cy[i]->rgb.b);
6060
i++;
6161
}
6262
return (__TRUE);

‎inters/inters.h‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* inters.h :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: TheTerror <jfaye@student.42lyon.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023年08月23日 20:21:23 by TheTerror #+# #+# */
9+
/* Updated: 2023年08月23日 20:26:15 by TheTerror ### ########lyon.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#ifndef INTERS_H
14+
# define INTERS_H
15+
16+
# include "../minirt.h"
17+
18+
t_bool ft_ray_inter_sp(t_vars *v, t_sp *sp);
19+
20+
#endif

‎inters/ray_plane.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ray_plane.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: TheTerror <jfaye@student.42lyon.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023年08月23日 21:27:05 by TheTerror #+# #+# */
9+
/* Updated: 2023年08月23日 21:27:20 by TheTerror ### ########lyon.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "inters.h"
14+

‎inters/ray_sphere.c‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ray_sphere.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: TheTerror <jfaye@student.42lyon.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023年08月23日 20:19:01 by TheTerror #+# #+# */
9+
/* Updated: 2023年08月23日 20:29:59 by TheTerror ### ########lyon.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "inters.h"
14+
15+
double ft_ray_inter_sp_op(t_vars *v, t_sp *sp);
16+
double ft_rsp_op_fdbk(double s1, double s2);
17+
18+
t_bool ft_ray_inter_sp(t_vars *v, t_sp *sp)
19+
{
20+
double s;
21+
22+
s = ft_ray_inter_sp_op(v, sp);
23+
if (v->ray.len < 0)
24+
{
25+
if (s >= 0)
26+
{
27+
v->ray.len = s;
28+
return (v->ray.color = ft_color(&sp->rgb), __TRUE);
29+
}
30+
return (__FALSE);
31+
}
32+
if (s >= 0 && s <= v->ray.len)
33+
{
34+
v->ray.len = s;
35+
return (v->ray.color = ft_color(&sp->rgb), __TRUE);
36+
}
37+
return (__FALSE);
38+
}
39+
40+
double ft_ray_inter_sp_op(t_vars *v, t_sp *sp)
41+
{
42+
double a;
43+
double b;
44+
double c;
45+
double delta;
46+
double s1;
47+
double s2;
48+
49+
a = ft_square(v->ray.dir.x) + ft_square(v->ray.dir.y) + \
50+
ft_square(v->ray.dir.z);
51+
b = 2.00 * v->ray.dir.x * (v->ray.o.x - sp->o.x) + \
52+
2.00 * v->ray.dir.y * (v->ray.o.y - sp->o.y) + \
53+
2.00 * v->ray.dir.z * (v->ray.o.z - sp->o.z);
54+
c = ft_square(v->ray.o.x - sp->o.x) + \
55+
ft_square(v->ray.o.y - sp->o.y) + \
56+
ft_square(v->ray.o.z - sp->o.z) - \
57+
ft_square(sp->d / 2.00);
58+
delta = ft_square(b) - (4 * a * c);
59+
if (delta < 0)
60+
return (delta);
61+
s1 = (-b - sqrt(delta)) / (2 * a);
62+
s2 = (-b + sqrt(delta)) / (2 * a);
63+
return (ft_rsp_op_fdbk(s1, s2));
64+
}
65+
66+
double ft_rsp_op_fdbk(double s1, double s2)
67+
{
68+
if (s1 >= 0 && s2 >= 0)
69+
{
70+
if (s1 < s2)
71+
return (s1);
72+
else
73+
return (s2);
74+
}
75+
if (s1 >= s2)
76+
return (s1);
77+
return (s2);
78+
}

‎mathtools/ft_square.c‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_square.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: TheTerror <jfaye@student.42lyon.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023年08月23日 15:54:01 by TheTerror #+# #+# */
9+
/* Updated: 2023年08月23日 15:55:37 by TheTerror ### ########lyon.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "mathtools.h"
14+
15+
double ft_square(double n)
16+
{
17+
return (n * n);
18+
}

‎mathtools/mathtools.h‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: TheTerror <jfaye@student.42lyon.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023年08月18日 18:36:23 by TheTerror #+# #+# */
9-
/* Updated: 2023/08/21 20:36:15 by TheTerror ### ########lyon.fr */
9+
/* Updated: 2023/08/23 16:35:58 by TheTerror ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -15,14 +15,15 @@
1515

1616
# include "../minirt.h"
1717

18-
t_coord *ft_pointsdiff(t_coord *end, t_coord *origin);
18+
t_coord ft_pointsdiff(t_coord *end, t_coord *origin);
1919
double ft_vectornorm(t_vec *vector);
2020
double ft_vectornormsqr(t_vec *vector);
2121
void ft_setvec_coords(t_vec *vector);
2222
double ft_vecdotvec(t_vec *vec2, t_vec *vec1, const double angle);
23-
t_vec *ft_vecdotpt(t_vec *vector, t_coord *point);
24-
t_vec *ft_vecdotconst(t_vec *vector, const double k);
23+
t_vec ft_vecdotpt(t_vec *vector, t_coord *point);
24+
t_vec ft_vecdotconst(t_vec *vector, const double k);
2525
double ft_degtorad(double alpha);
2626
double ft_radtodeg(double alpha);
27+
double ft_square(double n);
2728

2829
#endif

‎mathtools/products.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,30 @@
66
/* By: TheTerror <jfaye@student.42lyon.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023年08月17日 20:30:44 by TheTerror #+# #+# */
9-
/* Updated: 2023/08/18 18:54:17 by TheTerror ### ########lyon.fr */
9+
/* Updated: 2023/08/23 16:36:24 by TheTerror ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

1313
#include "mathtools.h"
1414

15-
t_vec *ft_vecdotconst(t_vec *vector, const double k)
15+
t_vec ft_vecdotconst(t_vec *vector, const double k)
1616
{
1717
t_vec res;
1818

1919
res.x = vector->x * k;
2020
res.y = vector->y * k;
2121
res.z = vector->z * k;
22-
return (&res);
22+
return (res);
2323
}
2424

25-
t_vec *ft_vecdotpt(t_vec *vector, t_coord *point)
25+
t_vec ft_vecdotpt(t_vec *vector, t_coord *point)
2626
{
2727
t_vec res;
2828

2929
res.x = vector->x * point->x;
3030
res.y = vector->y * point->y;
3131
res.z = vector->z * point->z;
32-
return (&res);
32+
return (res);
3333
}
3434

3535
double ft_vecdotvec(t_vec *vec2, t_vec *vec1, const double angle)

‎mathtools/subtractions.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
/* By: TheTerror <jfaye@student.42lyon.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023年08月17日 20:30:44 by TheTerror #+# #+# */
9-
/* Updated: 2023/08/18 18:43:09 by TheTerror ### ########lyon.fr */
9+
/* Updated: 2023/08/23 16:35:01 by TheTerror ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

1313
#include "mathtools.h"
1414

15-
t_coord *ft_pointsdiff(t_coord *end, t_coord *origin)
15+
t_coord ft_pointsdiff(t_coord *end, t_coord *origin)
1616
{
1717
t_coord res;
1818

1919
res.x = end->x - origin->x;
2020
res.y = end->y - origin->y;
2121
res.z = end->z - origin->z;
22-
return (&res);
22+
return (res);
2323
}

‎mathtools/vectors.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: TheTerror <jfaye@student.42lyon.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023年08月17日 20:30:44 by TheTerror #+# #+# */
9-
/* Updated: 2023/08/18 18:43:48 by TheTerror ### ########lyon.fr */
9+
/* Updated: 2023/08/23 18:35:20 by TheTerror ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -19,12 +19,12 @@ double ft_vectornorm(t_vec *vector)
1919

2020
void ft_setvec_coords(t_vec *vector)
2121
{
22-
t_coord *pt;
22+
t_coord pt;
2323

24-
pt = ft_pointsdiff(vector->e, vector->o);
25-
vector->x = pt->x;
26-
vector->y = pt->y;
27-
vector->z = pt->z;
24+
pt = ft_pointsdiff(&vector->e, &vector->o);
25+
vector->x = pt.x;
26+
vector->y = pt.y;
27+
vector->z = pt.z;
2828
}
2929

3030
double ft_vectornormsqr(t_vec *vector)

0 commit comments

Comments
(0)

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