Added a ton of stuff, including the beginnings of a new UI system
[ne.git] / src / base / vec.h
blob92dc38144813bf7b7c2d65f6173afcce9e069ae9
1 /************************************************************************
2 This file is part of NE.
4 NE is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 NE is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with NE. If not, see <http://www.gnu.org/licenses/>.
16 ************************************************************************/
18 #ifndef VEC_H_
19 #define VEC_H_
21 template<class T>
22 class Vec
24 public:
25 Vec(T v=0) : m_x(v), m_y(v), m_z(v) {}
26 Vec(T x, T y, T z) : m_x(x), m_y(y), m_z(z) {}
28 ///////////////////////
29 // Set/Get functions //
30 ///////////////////////
31 inline const Vec<T> set(T v)
33 m_x = m_y = m_z = v;
34 return *this;
36 inline const Vec<T> &set(T x, T y, T z)
38 m_x = x; m_y = y; m_z = z;
39 return *this;
41 inline const T* get()
43 static T v[3];
44 v[0] = m_x;
45 v[1] = m_y;
46 v[2] = m_z;
47 return &v;
49 inline T x() { return m_x; }
50 inline T y() { return m_y; }
51 inline T z() { return m_z; }
53 ///////////////////////
54 // Equality overload //
55 ///////////////////////
56 inline const Vec<T> &operator = (const Vec<T> &q)
58 return set(q.m_x,q.m_y,q.m_z);
60 inline bool operator == (const Vec<T> &q)
62 return m_x==q.m_x && m_y==q.m_y && m_z==q.m_z;
65 /////////////////////
66 // Vector overload //
67 /////////////////////
68 inline const Vec<T> &operator + (const Vec<T> &v) const
70 return Vec<T>(m_x+v.m_x, m_y+v.m_y, m_z+v.m_z);
72 inline const Vec<T> &operator += (const Vec<T> &v)
74 return set(m_x+v, m_y+v, m_z+v);
77 inline const Vec<T> &operator - (const Vec<T> &v) const
79 return Vec<T>(m_x-v.m_x, m_y-v.m_y, m_z-v.m_z);
81 inline const Vec<T> &operator -= (const Vec<T> &v)
83 return set(m_x-v, m_y-v, m_z-v);
86 inline const Vec<T> &operator * (const Vec<T> &v) const
88 return Vec<T>(m_x*v.m_x, m_y*v.m_y, m_z*v.m_z);
90 inline const Vec<T> &operator *= (const Vec<T> &v)
92 return set(m_x*v, m_y*v, m_z*v);
95 inline const Vec<T> &operator / (const Vec<T> &v) const
97 return Vec<T>(m_x/v.m_x, m_y/v.m_y, m_z/v.m_z);
99 inline const Vec<T> &operator /= (const Vec<T> &v)
101 return set(m_x/v, m_y/v, m_z/v);
104 /////////////////////
105 // Scalar overload //
106 /////////////////////
107 inline const Vec<T> &operator + (T v) const
109 return *this + Vec<T>(v);
111 inline const Vec<T> &operator += (T v)
113 return *this += Vec<T>(v);
116 inline const Vec<T> &operator - (T v) const
118 return *this - Vec<T>(v);
120 inline const Vec<T> &operator -= (T v)
122 return *this -= Vec<T>(v);
125 inline const Vec<T> &operator * (T v) const
127 return *this * Vec<T>(v);
129 inline const Vec<T> &operator *= (T v)
131 return *this *= Vec<T>(v);
134 inline const Vec<T> &operator / (T v) const
136 return *this / Vec<T>(v);
138 inline const Vec<T> &operator /= (T v)
140 return *this /= Vec<T>(v);
143 protected:
144 T m_x, m_y, m_z;
147 typedef Vec<float> Vec3f;
148 typedef Vec<double> Vec3d;
150 #endif /*VEC_H_*/