Line | |
---|
1 | #include <math.h> |
---|
2 | #include "vector.h" |
---|
3 | |
---|
4 | float vlen(vector v){ |
---|
5 | return sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); |
---|
6 | } |
---|
7 | |
---|
8 | void vsub(vector v1, vector v2, vector result){ |
---|
9 | int i; |
---|
10 | for(i = 0 ; i < 3 ; i++) result[i] = v1[i] - v2[i]; |
---|
11 | } |
---|
12 | |
---|
13 | void vnormalise(vector v, vector result){ |
---|
14 | float len = vlen(v); |
---|
15 | int i; |
---|
16 | for(i = 0 ; i < 3 ; i++) result[i] = v[i] / len; |
---|
17 | } |
---|
18 | |
---|
19 | void vcross(vector v1, vector v2, vector result){ |
---|
20 | result[0] = v1[1] * v2[2] - v1[2] * v2[1]; |
---|
21 | result[1] = v1[2] * v2[0] - v1[0] * v2[2]; |
---|
22 | result[2] = v1[0] * v2[1] - v1[1] * v2[0]; |
---|
23 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.