-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector3.c
83 lines (61 loc) · 1.59 KB
/
vector3.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "vector3.h"
VECTOR3 vector3(float x, float y, float z)
{
VECTOR3 new_vector;
new_vector.x = x;
new_vector.y = y;
new_vector.z = z;
return new_vector;
}
VECTOR3 sum_v3(VECTOR3 vector_a, VECTOR3 vector_b)
{
VECTOR3 new_vector;
new_vector.x = vector_a.x + vector_b.x;
new_vector.y = vector_a.y + vector_b.y;
new_vector.z = vector_a.z + vector_b.z;
return new_vector;
}
VECTOR3 neg_v3(VECTOR3 vector)
{
VECTOR3 new_vector;
new_vector.x = -vector.x;
new_vector.y = -vector.y;
new_vector.z = -vector.z;
return new_vector;
}
VECTOR3 sub_v3(VECTOR3 vector_a, VECTOR3 vector_b)
{
VECTOR3 new_vector;
new_vector.x = vector_a.x - vector_b.x;
new_vector.y = vector_a.y - vector_b.y;
new_vector.z = vector_a.z - vector_b.z;
return new_vector;
}
VECTOR3 element_scale_v3(VECTOR3 vector, VECTOR3 scale)
{
VECTOR3 new_vector;
new_vector.x = vector.x * scale.x;
new_vector.y = vector.y * scale.y;
new_vector.z = vector.z * scale.z;
return new_vector;
}
VECTOR3 scale_v3(VECTOR3 vector, float scalar)
{
VECTOR3 new_vector;
new_vector.x = vector.x * scalar;
new_vector.y = vector.y * scalar;
new_vector.z = vector.z * scalar;
return new_vector;
}
float dot_v3(VECTOR3 vector_a, VECTOR3 vector_b)
{
return (vector_a.x*vector_b.x) + (vector_a.y*vector_b.y) + (vector_a.z*vector_b.z);
}
VECTOR3 cross_v3(VECTOR3 vector_a, VECTOR3 vector_b)
{
VECTOR3 new_vector;
new_vector.x = (vector_a.y*vector_b.z) - (vector_a.z*vector_b.y);
new_vector.y = (vector_a.z*vector_b.x) - (vector_a.x*vector_b.z);
new_vector.z = (vector_a.x*vector_b.y) - (vector_a.y*vector_b.x);
return new_vector;
}