clray
view src/vector.inl @ 62:d9520da6b801
minor readme fix
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 28 Dec 2015 10:31:58 +0200 |
parents | 51f115e337c2 |
children |
line source
1 #include <math.h>
3 inline float Vector3::length()
4 {
5 return sqrt(x * x + y * y + z * z);
6 }
8 inline float Vector3::lengthsq()
9 {
10 return x * x + y * y + z * z;
11 }
13 inline Vector3 operator +(const Vector3 &a, const Vector3 &b)
14 {
15 return Vector3(a.x + b.x, a.y + b.y, a.z + b.z);
16 }
18 inline Vector3 operator -(const Vector3 &a, const Vector3 &b)
19 {
20 return Vector3(a.x - b.x, a.y - b.y, a.z - b.z);
21 }
23 inline Vector3 operator *(const Vector3 &a, const Vector3 &b)
24 {
25 return Vector3(a.x * b.x, a.y * b.y, a.z * b.z);
26 }
28 inline Vector3 operator /(const Vector3 &a, const Vector3 &b)
29 {
30 return Vector3(a.x / b.x, a.y / b.y, a.z / b.z);
31 }
34 inline Vector3 operator -(const Vector3 &vec)
35 {
36 return Vector3(-vec.x, -vec.y, -vec.z);
37 }
39 inline Vector3 operator *(const Vector3 &vec, float s)
40 {
41 return Vector3(vec.x * s, vec.y * s, vec.z * s);
42 }
44 inline Vector3 operator /(const Vector3 &vec, float s)
45 {
46 return Vector3(vec.x / s, vec.y / s, vec.z / s);
47 }
49 inline float dot(const Vector3 &a, const Vector3 &b)
50 {
51 return a.x * b.x + a.y * b.y + a.z * b.z;
52 }
54 inline Vector3 cross(const Vector3 &a, const Vector3 &b)
55 {
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);
57 }
59 inline Vector3 reflect(const Vector3 &v, const Vector3 &n)
60 {
61 return n * (2.0 * dot(v, n)) - v;
62 }