-
Notifications
You must be signed in to change notification settings - Fork 0
/
vecteur.c
51 lines (45 loc) · 1.23 KB
/
vecteur.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
** vecteur.c for vecteur in /home/nicolas/Modules/gfx_raytracer1
**
** Made by menett_a
** Login <[email protected]>
**
** Started on Wed Mar 9 20:08:38 2016 menett_a
** Last update Sun Mar 13 23:53:48 2016 menett_a
*/
#include <lapin.h>
#include <math.h>
#include "struct.h"
#include "proto.h"
void vec_light(t_loop *data, int i)
{
data->ray.light_x = data->info.light[i].pos_x - data->collision.pos_x;
data->ray.light_y = data->info.light[i].pos_y - data->collision.pos_y;
data->ray.light_z = data->info.light[i].pos_z - data->collision.pos_z;
}
void vec_normalize(double *x, double *y, double *z)
{
double coef;
coef = 0;
coef = sqrt((*x * *x) + (*y * *y) + (*z * *z));
*x = *x / coef;
*y = *y / coef;
*z = *z / coef;
}
void vec_scalaire(t_ray *ray, t_norm *norm, double *res)
{
*res =
norm->n_x * ray->light_x +
norm->n_y * ray->light_y +
norm->n_z * ray->light_z;
}
void vec_reflexion(t_ray *ray, t_norm *norm,
t_ray* new, t_norm *_new)
{
_new->n_x = norm->n_x;
_new->n_y = norm->n_y;
_new->n_z = norm->n_z;
new->light_x = ray->light_x - 2 * norm->res * norm->n_x;
new->light_y = ray->light_y - 2 * norm->res * norm->n_y;
new->light_z = ray->light_z - 2 * norm->res * norm->n_z;
}