4
#include "../Exception.h"
15
inline Vec3(const T&, const T&, const T&);
17
inline Vec3(const Vec3&);
19
inline Vec3<T>& operator = (const Vec3<T>&);
20
inline Vec3<T>& operator = (const Vec4<T>&);
22
inline t_bool operator == (const Vec3<T>&) const;
23
inline t_bool operator != (const Vec3<T>&) const;
24
inline Vec3<T> operator + (const Vec3<T>&) const;
25
inline Vec3<T> operator * (const Vec3<T>&) const;
26
inline Vec3<T> operator - (const Vec3<T>&) const;
27
inline Vec3<T> operator - () const;
29
inline Vec3<T>& operator *= (const Vec3<T>&);
30
inline Vec3<T>& operator += (const Vec3<T>&);
31
inline Vec3<T>& operator -= (const Vec3<T>&);
33
inline Vec3<T> operator / (const T&) const;
34
inline Vec3<T> operator * (const T&) const;
35
inline Vec3<T>& operator /= (const T&);
36
inline Vec3<T>& operator *= (const T&);
38
inline T& operator [](int i);
39
inline const T& operator [](int i) const;
41
inline T Length() const;
42
inline T LengthSquared() const;
43
inline T DotProduct(const Vec3<T>&) const;
44
inline Vec3 CrossProduct(const Vec3<T>&) const;
45
inline void Normalize();
47
template <typename U> friend Vec3<U> operator* (const U&, const Vec3<U>&);
49
//friend Vec3<T> operator * (T, Vec3&);
55
inline Vec3<T>::Vec3()
63
inline Vec3<T>::~Vec3()
69
inline Vec3<T>::Vec3(const T& fx, const T& fy, const T& fz)
76
//Vec3::Vec3(t_double fx, t_double fy, t_double fz)
83
//Vec3::Vec3(t_int fx, t_int fy, t_int fz)
91
Vec3<T>::Vec3(const Vec3<T>& v)
99
Vec3<T>& Vec3<T>::operator = (const Vec3<T>& v)
107
template <typename T>
108
Vec3<T>& Vec3<T>::operator = (const Vec4<T>& v)
116
template <typename T>
117
t_bool Vec3<T>::operator == (const Vec3<T>& v) const
128
template <typename T>
129
t_bool Vec3<T>::operator != (const Vec3<T>& v) const
131
return !(*this == v);
134
template <typename T>
135
Vec3<T> Vec3<T>::operator + (const Vec3<T>& v) const
137
return Vec3<T>(x + v.x, y + v.y, z + v.z);
140
template <typename T>
141
Vec3<T> Vec3<T>::operator * (const Vec3& v) const
143
return Vec3<T>(x * v.x, y * v.y, z * v.z);
146
template <typename T>
147
Vec3<T> Vec3<T>::operator - (const Vec3& v) const
149
return Vec3<T>(x - v.x, y - v.y, z - v.z);
152
template <typename T>
153
Vec3<T> Vec3<T>::operator - () const
155
return Vec3(-x, -y, -z);
158
template <typename T>
159
Vec3<T>& Vec3<T>::operator *= (const Vec3& v)
167
template <typename T>
168
Vec3<T>& Vec3<T>::operator += (const Vec3& v)
176
template <typename T>
177
Vec3<T>& Vec3<T>::operator -= (const Vec3& v)
185
template <typename T>
186
Vec3<T> Vec3<T>::operator / (const T& f) const
190
throw DivisionByZeroException();
192
return Vec3<T>(x / f, y / f, z / f);
195
template <typename T>
196
Vec3<T> Vec3<T>::operator * (const T& f) const
198
return Vec3<T>(x * f, y * f, z * f);
201
template <typename T>
202
Vec3<T>& Vec3<T>::operator /= (const T& f)
206
throw DivisionByZeroException();
214
template <typename T>
215
Vec3<T>& Vec3<T>::operator *= (const T& f)
224
template <typename T>
225
T& Vec3<T>::operator [](int i)
232
/// element access (const)
233
template <typename T>
234
const T& Vec3<T>::operator [](int i) const
241
template <typename T>
242
T Vec3<T>::Length() const
244
return sqrt(x*x + y*y + z*z);
247
template <typename T>
248
T Vec3<T>::LengthSquared() const
250
return (x*x + y*y + z*z);
253
template <typename T>
254
T Vec3<T>::DotProduct(const Vec3<T>& v) const
256
return x * v.x + y * v.y + z * v.z;
259
template <typename T>
260
Vec3<T> Vec3<T>::CrossProduct(const Vec3<T>& v) const
262
return Vec3<T>(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x);
265
template <typename T>
266
void Vec3<T>::Normalize()
273
throw DivisionByZeroException();
280
template <typename T>
281
T DotProduct(const Vec3<T>& lhs, const Vec3<T>& rhs)
284
out = lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z;
288
template <typename T>
289
const Vec3<T> CrossProduct(const Vec3<T>& lhs, const Vec3<T>& rhs)
292
out.x = lhs.y * rhs.z - lhs.z * rhs.y;
293
out.y = lhs.z * rhs.x - lhs.x * rhs.z;
294
out.z = lhs.x * rhs.y - lhs.y * rhs.x;
299
template <typename U>
300
inline Vec3<U> operator * (const U& f, const Vec3<U>& v)
305
typedef Vec3<float> Vector3;