-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector_op.c
63 lines (52 loc) · 1.55 KB
/
vector_op.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
52
53
54
55
56
57
58
59
60
61
62
63
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vector_op.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gphilips <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/29 17:09:39 by gphilips #+# #+# */
/* Updated: 2017/12/22 16:15:27 by gphilips ### ########.fr */
/* */
/* ************************************************************************** */
#include "rtv1.h"
t_vec vec_add(t_vec *v1, t_vec *v2)
{
t_vec v;
v.x = v1->x + v2->x;
v.y = v1->y + v2->y;
v.z = v1->z + v2->z;
return (v);
}
t_vec vec_sub(t_vec *v1, t_vec *v2)
{
t_vec v;
v.x = v1->x - v2->x;
v.y = v1->y - v2->y;
v.z = v1->z - v2->z;
return (v);
}
t_vec vec_scale(double scale, t_vec *v1)
{
t_vec v;
v.x = scale * v1->x;
v.y = scale * v1->y;
v.z = scale * v1->z;
return (v);
}
t_vec vec_negative(t_vec *v)
{
t_vec n;
n.x = -v->x;
n.y = -v->y;
n.z = -v->z;
return (n);
}
t_vec vec_cross(t_vec *v1, t_vec *v2)
{
t_vec v;
v.x = v1->y * v2->z - v1->z * v2->y;
v.y = v2->x * v1->z - v2->z * v1->x;
v.z = v1->x * v2->y - v1->y * v2->x;
return (v);
}