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 475b862

Browse files
Great, plane tracing is now done
My new assumption worked: When the given 3d orientation vector is viewed like the normal to the plane, that allows to choose accurately the plane the given point belongs to.
1 parent 12d139d commit 475b862

File tree

6 files changed

+28
-58
lines changed

6 files changed

+28
-58
lines changed

‎display.c‎

Lines changed: 3 additions & 3 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/23 16:27:26 by TheTerror ### ########lyon.fr */
9+
/* Updated: 2023/09/07 21:26:18 by TheTerror ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -45,8 +45,8 @@ t_bool ft_displayothers(t_vars *v)
4545
{
4646
printf(\
4747
"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]->rgb.r, v->pl[i]->rgb.g, v->pl[i]->rgb.b);
48+
v->pl[i]->p.y, v->pl[i]->p.z, v->pl[i]->normal.x, v->pl[i]->normal.y, \
49+
v->pl[i]->normal.z, v->pl[i]->rgb.r, v->pl[i]->rgb.g, v->pl[i]->rgb.b);
5050
i++;
5151
}
5252
i = 0;

‎inters/ray_plane.c‎

Lines changed: 13 additions & 15 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日 21:27:05 by TheTerror #+# #+# */
9-
/* Updated: 2023年09月07日 17:22:54 by TheTerror ### ########lyon.fr */
9+
/* Updated: 2023年09月07日 22:32:56 by TheTerror ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -16,7 +16,6 @@ t_bool ft_define_pl_normal(t_pl *pl, t_vec *pl_n);
1616

1717
t_bool ft_ray_inter_pl(t_vars *v, t_pl *pl)
1818
{
19-
t_vec pl_n;
2019
t_vec p_ro;
2120
t_coord ray_o;
2221
double nom;
@@ -26,19 +25,18 @@ t_bool ft_ray_inter_pl(t_vars *v, t_pl *pl)
2625
ray_o.x = v->ray.o.x;
2726
ray_o.y = v->ray.o.y;
2827
ray_o.z = v->ray.o.z;
29-
ft_vectornormalize(&pl->dir, &pl->dir);
28+
ft_vectornormalize(&pl->normal, &pl->normal);
3029
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);
30+
denom = ft_vecdotvec(&pl->normal, &v->ray.dir);
3331
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)
32+
nom = ft_vecdotvec(&p_ro, &pl->normal);
33+
if (!nom && denom > -0.000000000000001 && denom < 0.000000000000001)
34+
return (v->ray.color = ft_color(&pl->rgb), __TRUE);
35+
if (!nom || (denom > -0.000000000000001 && denom < 0.000000000000001))
3736
return (__FALSE);
3837
length = nom / denom;
3938
if (ft_assess_color(v, length))
4039
return (v->ray.color = ft_color(&pl->rgb), __TRUE);
41-
// return (v->ray.color = ft_color(&v->cy[0]->rgb), __TRUE);
4240
return (__FALSE);
4341
}
4442

@@ -51,12 +49,12 @@ t_bool ft_define_pl_normal(t_pl *pl, t_vec *pl_n)
5149
op.y = pl->p.y;
5250
op.z = pl->p.z;
5351
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);
52+
pm.x = (pl->normal.y * op.z) - (pl->normal.z * op.y);
53+
pm.y = (pl->normal.z * op.x) - (pl->normal.x * op.z);
54+
pm.z = (pl->normal.x * op.y) - (pl->normal.y * op.x);
5755
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);
56+
pl_n->x = (pm.y * pl->normal.z) - (pm.z * pl->normal.y);
57+
pl_n->y = (pm.z * pl->normal.x) - (pm.x * pl->normal.z);
58+
pl_n->z = (pm.x * pl->normal.y) - (pm.y * pl->normal.x);
6159
return (__TRUE);
6260
}

‎minirt.c‎

Lines changed: 1 addition & 18 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年09月07日 17:23:35 by TheTerror ### ########lyon.fr */
9+
/* Updated: 2023年09月07日 22:41:45 by TheTerror ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -35,23 +35,6 @@ t_bool ft_minirt(t_vars *v)
3535
return (__TRUE);
3636
}
3737

38-
39-
// t_bool ft_ray_fit_fov(t_vars *v)
40-
// {
41-
// double alpha;
42-
// double beta;
43-
// double ray_dot_c;
44-
// double cosbeta;
45-
46-
// alpha = ft_degtorad(v->c->fov);
47-
// ray_dot_c = ft_vecdotvec(&v->c->dir, &v->ray.dir);
48-
// cosbeta = ray_dot_c / (ft_vectornorm(&v->c->dir) * ft_vectornorm(&v->ray.dir));
49-
// beta = acos(cosbeta);
50-
// if (beta <= alpha / 2.00)
51-
// return (__TRUE);
52-
// return (__FALSE);
53-
// }
54-
5538
t_bool ft_intersections(t_vars *v, int i, int j)
5639
{
5740
int x;

‎parsing/plane.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月19日 21:54:13 by TheTerror #+# #+# */
9-
/* Updated: 2023/09/06 22:43:01 by TheTerror ### ########lyon.fr */
9+
/* Updated: 2023/09/07 21:23:34 by TheTerror ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -84,12 +84,12 @@ t_bool ft_set_pldir(t_pl *pl, char *infodir)
8484
ft_error("plane: expecting only decimal numbers"));
8585
i++;
8686
}
87-
pl->dir.x = ft_atod(dir[0]);
88-
pl->dir.y = ft_atod(dir[1]);
89-
pl->dir.z = ft_atod(dir[2]);
87+
pl->normal.x = ft_atod(dir[0]);
88+
pl->normal.y = ft_atod(dir[1]);
89+
pl->normal.z = ft_atod(dir[2]);
9090
ft_free2str(&dir);
91-
if (pl->dir.x < -1 || pl->dir.x > 1 || pl->dir.y < -1 || \
92-
pl->dir.y > 1 || pl->dir.z < -1 || pl->dir.z > 1)
91+
if (pl->normal.x < -1 || pl->normal.x > 1 || pl->normal.y < -1 || \
92+
pl->normal.y > 1 || pl->normal.z < -1 || pl->normal.z > 1)
9393
return (ft_error("plane: incorrect orientation vector format"));
9494
return (__TRUE);
9595
}

‎preprocss.h‎

Lines changed: 2 additions & 3 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:41:14 by TheTerror #+# #+# */
9-
/* Updated: 2023/08/25 15:29:22 by TheTerror ### ########lyon.fr */
9+
/* Updated: 2023/09/07 21:40:37 by TheTerror ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -76,7 +76,6 @@ typedef struct s_img
7676
int bpp;
7777
int size_line;
7878
int endian;
79-
int color;
8079
void *img;
8180
} t_img;
8281

@@ -110,7 +109,7 @@ typedef struct s_sphere
110109
typedef struct s_plane
111110
{
112111
t_coord p;
113-
t_vec dir;
112+
t_vec normal;
114113
t_rgb rgb;
115114
} t_pl;
116115

‎scenes/exemple.rt‎

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

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

55

66

77
L -40,0,30 0.7 255,255,255
8-
pl 0,-105,0 -1,0,0 5,0,225
9-
pl 0,-105,0 1,0.0000000001,0.00000000001 113,113,55
8+
pl 0,-100,0 0.08,1,0.1 0,215,145
109

1110

1211
sp 0,0,-100 10 255,200,200
@@ -33,13 +32,4 @@ sp 0,100,0 10 255,0,0
3332
sp 20,200,20 20 25,89,213
3433
sp 20,105,20 20 25,129,13
3534

36-
cy 50.0,0.0,20.6 0,0,1.0 14.2 21.42 10,225,255
37-
38-
39-
40-
pl 0,0,0 0,1.0,0 255,0,225
41-
42-
43-
cy 50.0,0.0,20.6 0,0,1.0 14.2 21.42 10,0,255
44-
45-
35+
cy 50.0,0.0,20.6 0,0,1.0 14.2 21.42 10,225,255

0 commit comments

Comments
(0)

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