clray
view src/vector.inl @ 23:51f115e337c2
separated obj loading and vector class
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 13 Aug 2010 18:20:45 +0100 |
parents | |
children | 6a30f27fa1e6 |
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 }
45 inline float dot(const Vector3 &a, const Vector3 &b)
46 {
47 return a.x * b.x + a.y * b.y + a.z * b.z;
48 }
50 inline Vector3 cross(const Vector3 &a, const Vector3 &b)
51 {
52 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);
53 }