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 12d139d

Browse files
plane tracing
here i assume that the 3d orientation vector given for the plane is a director vector of the plane so i had to define a normal vector to that plane. This hypotical way result in the fact that i can't really choose an arbitrary inclination of the plane. So what i am going to do is to assume that this normalized vector is the normal vector to the plane which make more sense so we can know exactly the orientation of the plane.
1 parent dd69702 commit 12d139d

File tree

9 files changed

+89
-35
lines changed

9 files changed

+89
-35
lines changed

‎inters/inters.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: TheTerror <jfaye@student.42lyon.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023年08月23日 20:21:23 by TheTerror #+# #+# */
9-
/* Updated: 2023/08/23 20:26:15 by TheTerror ### ########lyon.fr */
9+
/* Updated: 2023/09/06 22:31:29 by TheTerror ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -16,5 +16,7 @@
1616
# include "../minirt.h"
1717

1818
t_bool ft_ray_inter_sp(t_vars *v, t_sp *sp);
19+
t_bool ft_ray_inter_pl(t_vars *v, t_pl *pl);
20+
t_bool ft_assess_color(t_vars *v, double len_found);
1921

2022
#endif

‎inters/ray_plane.c‎

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,57 @@
66
/* By: TheTerror <jfaye@student.42lyon.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023年08月23日 21:27:05 by TheTerror #+# #+# */
9-
/* Updated: 2023/08/23 21:27:20 by TheTerror ### ########lyon.fr */
9+
/* Updated: 2023/09/07 17:22:54 by TheTerror ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

1313
#include "inters.h"
1414

15+
t_bool ft_define_pl_normal(t_pl *pl, t_vec *pl_n);
16+
17+
t_bool ft_ray_inter_pl(t_vars *v, t_pl *pl)
18+
{
19+
t_vec pl_n;
20+
t_vec p_ro;
21+
t_coord ray_o;
22+
double nom;
23+
double denom;
24+
double length;
25+
26+
ray_o.x = v->ray.o.x;
27+
ray_o.y = v->ray.o.y;
28+
ray_o.z = v->ray.o.z;
29+
ft_vectornormalize(&pl->dir, &pl->dir);
30+
ft_vectornormalize(&v->ray.dir, &v->ray.dir);
31+
ft_define_pl_normal(pl, &pl_n);
32+
denom = ft_vecdotvec(&pl_n, &v->ray.dir);
33+
ft_pointsdiff(&pl->p, &ray_o, &p_ro);
34+
nom = ft_vecdotvec(&p_ro, &pl_n);
35+
// return (v->ray.color = ft_color(&v->cy[0]->rgb), __FALSE);
36+
if (denom > -0.000000000001 && denom < 0.00000000001)
37+
return (__FALSE);
38+
length = nom / denom;
39+
if (ft_assess_color(v, length))
40+
return (v->ray.color = ft_color(&pl->rgb), __TRUE);
41+
// return (v->ray.color = ft_color(&v->cy[0]->rgb), __TRUE);
42+
return (__FALSE);
43+
}
44+
45+
t_bool ft_define_pl_normal(t_pl *pl, t_vec *pl_n)
46+
{
47+
t_vec op;
48+
t_vec pm;
49+
50+
op.x = pl->p.x;
51+
op.y = pl->p.y;
52+
op.z = pl->p.z;
53+
ft_vectornormalize(&op, &op);
54+
pm.x = (pl->dir.y * op.z) - (pl->dir.z * op.y);
55+
pm.y = (pl->dir.z * op.x) - (pl->dir.x * op.z);
56+
pm.z = (pl->dir.x * op.y) - (pl->dir.y * op.x);
57+
ft_vectornormalize(&pm, &pm);
58+
pl_n->x = (pm.y * pl->dir.z) - (pm.z * pl->dir.y);
59+
pl_n->y = (pm.z * pl->dir.x) - (pm.x * pl->dir.z);
60+
pl_n->z = (pm.x * pl->dir.y) - (pm.y * pl->dir.x);
61+
return (__TRUE);
62+
}

‎inters/ray_sphere.c‎

Lines changed: 14 additions & 7 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月23日 20:19:01 by TheTerror #+# #+# */
9-
/* Updated: 2023年09月06日 15:43:30 by TheTerror ### ########lyon.fr */
9+
/* Updated: 2023年09月06日 22:15:51 by TheTerror ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -20,19 +20,26 @@ t_bool ft_ray_inter_sp(t_vars *v, t_sp *sp)
2020
double s;
2121

2222
s = ft_ray_inter_sp_op(v, sp);
23+
if (ft_assess_color(v, s))
24+
return (v->ray.color = ft_color(&sp->rgb), __TRUE);
25+
return (__FALSE);
26+
}
27+
28+
t_bool ft_assess_color(t_vars *v, double len_found)
29+
{
2330
if (v->ray.len < 0)
2431
{
25-
if (s >= 0)
32+
if (len_found >= 0)
2633
{
27-
v->ray.len = s;
28-
return (v->ray.color=ft_color(&sp->rgb), __TRUE);
34+
v->ray.len = len_found;
35+
return (__TRUE);
2936
}
3037
return (__FALSE);
3138
}
32-
if (s >= 0 && s <= v->ray.len)
39+
if (len_found >= 0 && len_found <= v->ray.len)
3340
{
34-
v->ray.len = s;
35-
return (v->ray.color=ft_color(&sp->rgb), __TRUE);
41+
v->ray.len = len_found;
42+
return (__TRUE);
3643
}
3744
return (__FALSE);
3845
}

‎mathtools/mathtools.h‎

Lines changed: 2 additions & 2 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/25 20:56:52 by TheTerror ### ########lyon.fr */
9+
/* Updated: 2023/09/06 22:02:09 by TheTerror ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -15,7 +15,7 @@
1515

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

18-
t_coord ft_pointsdiff(t_coord *end, t_coord *origin);
18+
void ft_pointsdiff(t_coord *end, t_coord *origin, t_vec*res);
1919
double ft_vectornorm(t_vec *vector);
2020
double ft_vectornormsqr(t_vec *vector);
2121
void ft_setvec_coords(t_vec *vector);

‎mathtools/subtractions.c‎

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

1313
#include "mathtools.h"
1414

15-
t_coord ft_pointsdiff(t_coord *end, t_coord *origin)
15+
void ft_pointsdiff(t_coord *end, t_coord *origin, t_vec*res)
1616
{
17-
t_coord res;
17+
t_coord r;
1818

19-
res.x = end->x - origin->x;
20-
res.y = end->y - origin->y;
21-
res.z = end->z - origin->z;
22-
return (res);
19+
r.x = end->x - origin->x;
20+
r.y = end->y - origin->y;
21+
r.z = end->z - origin->z;
22+
res->x = r.x;
23+
res->y = r.y;
24+
res->z = r.z;
2325
}

‎mathtools/vectors.c‎

Lines changed: 2 additions & 7 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年09月06日 01:17:37 by TheTerror ### ########lyon.fr */
9+
/* Updated: 2023年09月06日 22:25:46 by TheTerror ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

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

2020
void ft_setvec_coords(t_vec *vector)
2121
{
22-
t_coord pt;
23-
24-
pt = ft_pointsdiff(&vector->e, &vector->o);
25-
vector->x = pt.x;
26-
vector->y = pt.y;
27-
vector->z = pt.z;
22+
ft_pointsdiff(&vector->e, &vector->o, vector);
2823
}
2924

3025
double ft_vectornormsqr(t_vec *vector)

‎minirt.c‎

Lines changed: 5 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日 16:29:22 by TheTerror #+# #+# */
9-
/* Updated: 2023/08/30 20:51:25 by TheTerror ### ########lyon.fr */
9+
/* Updated: 2023/09/07 17:23:35 by TheTerror ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -57,12 +57,11 @@ t_bool ft_intersections(t_vars *v, int i, int j)
5757
int x;
5858

5959
x = -1;
60-
while (v->sp[++x])
61-
{
62-
// if (!ft_ray_fit_fov(v))
63-
// break ;
60+
while (v->sp && v->sp[++x])
6461
ft_ray_inter_sp(v, v->sp[x]);
65-
}
62+
x = -1;
63+
while (v->pl && v->pl[++x])
64+
ft_ray_inter_pl(v, v->pl[x]);
6665
my_mlx_pixel_put(v->im, i, j, v->ray.color);
6766
return (__TRUE);
6867
}

‎parsing/plane.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: TheTerror <jfaye@student.42lyon.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023年08月19日 21:54:13 by TheTerror #+# #+# */
9-
/* Updated: 2023/08/23 16:24:51 by TheTerror ### ########lyon.fr */
9+
/* Updated: 2023/09/06 22:43:01 by TheTerror ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

‎scenes/exemple.rt‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
A 0.2 0,0,0
22

3-
C 1000,0,0 -1,0,0 50
3+
C -1000,-20,0 1,0,0 50
44

55

66

77
L -40,0,30 0.7 255,255,255
8-
pl 0,0,0 0,1.0,0 255,0,225
8+
pl 0,-105,0 -1,0,0 5,0,225
9+
pl 0,-105,0 1,0.0000000001,0.00000000001 113,113,55
910

1011

1112
sp 0,0,-100 10 255,200,200
@@ -32,7 +33,7 @@ sp 0,100,0 10 255,0,0
3233
sp 20,200,20 20 25,89,213
3334
sp 20,105,20 20 25,129,13
3435

35-
cy 50.0,0.0,20.6 0,0,1.0 14.2 21.42 10,0,255
36+
cy 50.0,0.0,20.6 0,0,1.0 14.2 21.42 10,225,255
3637

3738

3839

0 commit comments

Comments
(0)

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