rev |
line source |
nuclear@23
|
1 #include <math.h>
|
nuclear@23
|
2
|
nuclear@23
|
3 inline float Vector3::length()
|
nuclear@23
|
4 {
|
nuclear@23
|
5 return sqrt(x * x + y * y + z * z);
|
nuclear@23
|
6 }
|
nuclear@23
|
7
|
nuclear@23
|
8 inline float Vector3::lengthsq()
|
nuclear@23
|
9 {
|
nuclear@23
|
10 return x * x + y * y + z * z;
|
nuclear@23
|
11 }
|
nuclear@23
|
12
|
nuclear@23
|
13 inline Vector3 operator +(const Vector3 &a, const Vector3 &b)
|
nuclear@23
|
14 {
|
nuclear@23
|
15 return Vector3(a.x + b.x, a.y + b.y, a.z + b.z);
|
nuclear@23
|
16 }
|
nuclear@23
|
17
|
nuclear@23
|
18 inline Vector3 operator -(const Vector3 &a, const Vector3 &b)
|
nuclear@23
|
19 {
|
nuclear@23
|
20 return Vector3(a.x - b.x, a.y - b.y, a.z - b.z);
|
nuclear@23
|
21 }
|
nuclear@23
|
22
|
nuclear@23
|
23 inline Vector3 operator *(const Vector3 &a, const Vector3 &b)
|
nuclear@23
|
24 {
|
nuclear@23
|
25 return Vector3(a.x * b.x, a.y * b.y, a.z * b.z);
|
nuclear@23
|
26 }
|
nuclear@23
|
27
|
nuclear@23
|
28 inline Vector3 operator /(const Vector3 &a, const Vector3 &b)
|
nuclear@23
|
29 {
|
nuclear@23
|
30 return Vector3(a.x / b.x, a.y / b.y, a.z / b.z);
|
nuclear@23
|
31 }
|
nuclear@23
|
32
|
nuclear@23
|
33
|
nuclear@23
|
34 inline Vector3 operator -(const Vector3 &vec)
|
nuclear@23
|
35 {
|
nuclear@23
|
36 return Vector3(-vec.x, -vec.y, -vec.z);
|
nuclear@23
|
37 }
|
nuclear@23
|
38
|
nuclear@23
|
39 inline Vector3 operator *(const Vector3 &vec, float s)
|
nuclear@23
|
40 {
|
nuclear@23
|
41 return Vector3(vec.x * s, vec.y * s, vec.z * s);
|
nuclear@23
|
42 }
|
nuclear@23
|
43
|
nuclear@54
|
44 inline Vector3 operator /(const Vector3 &vec, float s)
|
nuclear@54
|
45 {
|
nuclear@54
|
46 return Vector3(vec.x / s, vec.y / s, vec.z / s);
|
nuclear@54
|
47 }
|
nuclear@23
|
48
|
nuclear@23
|
49 inline float dot(const Vector3 &a, const Vector3 &b)
|
nuclear@23
|
50 {
|
nuclear@23
|
51 return a.x * b.x + a.y * b.y + a.z * b.z;
|
nuclear@23
|
52 }
|
nuclear@23
|
53
|
nuclear@23
|
54 inline Vector3 cross(const Vector3 &a, const Vector3 &b)
|
nuclear@23
|
55 {
|
nuclear@23
|
56 return Vector3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
|
nuclear@23
|
57 }
|
nuclear@54
|
58
|
nuclear@54
|
59 inline Vector3 reflect(const Vector3 &v, const Vector3 &n)
|
nuclear@54
|
60 {
|
nuclear@54
|
61 return n * (2.0 * dot(v, n)) - v;
|
nuclear@54
|
62 }
|