2 eqemu - electronic queue system emulator
3 Copyright (C) 2014 John Tsiombikas <nuclear@member.fsf.org>,
4 Eleni-Maria Stea <eleni@mutantstargoat.com>
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 Vector2() : x(0), y(0) {}
29 Vector2(float xa, float ya) : x(xa), y(ya) {}
31 float &operator [](int idx) { return (&x)[idx]; }
32 const float &operator [](int idx) const { return (&x)[idx]; }
39 Vector3() : x(0), y(0), z(0) {}
40 Vector3(float xa, float ya, float za) : x(xa), y(ya), z(za) {}
42 float &operator [](int idx) { return (&x)[idx]; }
43 const float &operator [](int idx) const { return (&x)[idx]; }
46 inline Vector3 operator +(const Vector3 &a, const Vector3 &b)
48 return Vector3(a.x + b.x, a.y + b.y, a.z + b.z);
51 inline Vector3 operator -(const Vector3 &a, const Vector3 &b)
53 return Vector3(a.x - b.x, a.y - b.y, a.z - b.z);
56 inline Vector3 operator *(const Vector3 &a, float s)
58 return Vector3(a.x * s, a.y * s, a.z * s);
61 inline float dot(const Vector3 &a, const Vector3 &b)
63 return a.x * b.x + a.y * b.y + a.z * b.z;
66 inline float length(const Vector3 &v)
68 return sqrt(dot(v, v));
71 inline Vector3 normalize(const Vector3 &v)
73 float len = length(v);
77 return Vector3(v.x / len, v.y / len, v.z / len);
84 Vector4() : x(0), y(0), z(0), w(0) {}
85 Vector4(float xa, float ya, float za, float wa) : x(xa), y(ya), z(za), w(wa) {}
87 float &operator [](int idx) { return (&x)[idx]; }
88 const float &operator [](int idx) const { return (&x)[idx]; }
95 Ray() : origin(0, 0, 0), dir(0, 0, 1) {}
96 Ray(const Vector3 &o, const Vector3 &d) : origin(o), dir(d) {}