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 51fbf30

Browse files
saving code ray_inter_extremities that doesn't work
1 parent 282db1c commit 51fbf30

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

‎inters/ray_extremities.c‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ray_extremities.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: TheTerror <jfaye@student.42lyon.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2024年02月04日 14:38:21 by TheTerror #+# #+# */
9+
/* Updated: 2024年02月04日 16:11:46 by TheTerror ### ########lyon.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "inters.h"
14+
15+
typedef struct s_consts
16+
{
17+
t_coord pt_ph;
18+
double t;
19+
double norm_phpi;
20+
double c1;
21+
double c2;
22+
double c3;
23+
double c4;
24+
double c5;
25+
double c6;
26+
} t_consts;
27+
28+
t_bool compute_pt_ph(t_cy *cy, t_consts *vars);
29+
t_bool compute_lenght_t(t_vars *v, t_cy *cy, t_consts *vars);
30+
t_bool compute_norm_vec_phpi(t_vars *v, t_consts *vars);
31+
32+
t_bool case_ray_inter_extremities(t_vars *v, t_cy *cy)
33+
{
34+
t_consts vars;
35+
36+
compute_pt_ph(cy, &vars);
37+
compute_lenght_t(v, cy, &vars);
38+
compute_norm_vec_phpi(v, &vars);
39+
if (vars.norm_phpi > (cy->d / 2))
40+
return (__FALSE);
41+
if (ft_assess_color(v, vars.t))
42+
return (v->ray.color = ft_color(&cy->rgb), __TRUE);
43+
return (__FALSE);
44+
}
45+
46+
t_bool compute_pt_ph(t_cy *cy, t_consts *vars)
47+
{
48+
vars->pt_ph.x = cy->o.x + (cy->h / 2) * cy->axis.x;
49+
vars->pt_ph.x = cy->o.y + (cy->h / 2) * cy->axis.y;
50+
vars->pt_ph.x = cy->o.z + (cy->h / 2) * cy->axis.z;
51+
return (__TRUE);
52+
}
53+
54+
t_bool compute_lenght_t(t_vars *v, t_cy *cy, t_consts *vars)
55+
{
56+
double num;
57+
double denom;
58+
59+
vars->c1 = v->ray.o.x - vars->pt_ph.x;
60+
vars->c2 = v->ray.o.y - vars->pt_ph.y;
61+
vars->c3 = v->ray.o.z - vars->pt_ph.z;
62+
vars->c4 = v->ray.o.x - cy->o.x;
63+
vars->c5 = v->ray.o.y - cy->o.y;
64+
vars->c6 = v->ray.o.z - cy->o.z;
65+
num = ft_sq(vars->c4) + ft_sq(vars->c5) + ft_sq(vars->c6) \
66+
- ft_sq(vars->c1) - ft_sq(vars->c2) - ft_sq(vars->c3) \
67+
- ft_sq(cy->h / 2);
68+
denom = 2 * (v->ray.dir.x * (vars->c1 - vars->c4) + v->ray.dir.y \
69+
* (vars->c2 - vars->c5) + v->ray.dir.z * (vars->c3 - vars->c6));
70+
if (!num || !denom)
71+
return(vars->t = 0, __TRUE);
72+
vars->t = num / denom;
73+
return (__TRUE);
74+
}
75+
76+
t_bool compute_norm_vec_phpi(t_vars *v, t_consts *vars)
77+
{
78+
vars->norm_phpi = sqrt(ft_sq(vars->t * v->ray.dir.x + vars->c1) \
79+
+ ft_sq(vars->t * v->ray.dir.y + vars->c2) + ft_sq(vars->t \
80+
* v->ray.dir.z + vars->c3));
81+
return (__TRUE);
82+
}

0 commit comments

Comments
(0)

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