89 inline Vector2& operator=(
const T*);
90 inline void set(T, T);
92 inline bool operator==(
const Vector2<T>&)
const;
93 inline bool operator!=(
const Vector2<T>&)
const;
95 inline const T& operator[](
int x)
const;
96 inline T& operator[](
int);
97 inline operator const T*()
const;
102 inline void operator*=(T);
103 inline void operator/=(T);
108 inline Vector2 operator-()
const;
109 inline Vector2 operator+()
const;
111 inline Vector2 operator*(T)
const;
112 inline Vector2 operator/(T)
const;
117 inline T length()
const;
118 inline T lengthSquared()
const;
119 inline void normalize();
128 template<
class T>
class Vector3 138 inline Vector3& operator=(
const T*);
140 inline void set(T, T, T);
142 inline bool operator==(
const Vector3<T>&)
const;
143 inline bool operator!=(
const Vector3<T>&)
const;
145 inline bool fuzzyEquals(
const Vector3<T>&, T epsilon = std::numeric_limits<T>::epsilon())
const;
147 inline T& operator[](
int);
148 inline const T& operator[](
int)
const;
149 inline operator const T*()
const;
150 inline operator T*();
151 inline const T* data()
const {
return v;}
152 inline T* data() {
return v;}
156 inline void operator*=(T);
157 inline void operator/=(T);
165 inline Vector3 operator*(T)
const;
173 inline T latitude()
const;
175 inline T longitude()
const;
179 inline T angleNormalized(
const Vector3<T>&)
const;
181 inline T length()
const;
182 inline T lengthSquared()
const;
183 inline void normalize();
185 inline void transfo4d(
const Mat4d&);
186 inline void transfo4d(
const Mat4f&);
189 inline Vec3f toVec3f()
const;
190 inline Vec3d toVec3d()
const;
194 QString toString()
const {
return QString(
"[%1, %2, %3]").arg(v[0]).arg(v[1]).arg(v[2]);}
195 QString toStringLonLat()
const {
return QString(
"[") + QString::number(longitude()*180./M_PI,
'g', 12) +
"," + QString::number(latitude()*180./M_PI,
'g', 12)+
"]";}
202 template<
class T>
class Vector4 211 inline Vector4& operator=(
const T*);
212 inline void set(T, T, T, T);
214 inline bool operator==(
const Vector4<T>&)
const;
215 inline bool operator!=(
const Vector4<T>&)
const;
217 inline T& operator[](
int);
218 inline const T& operator[](
int)
const;
219 inline operator T*();
220 inline operator const T*()
const;
224 inline void operator*=(T);
225 inline void operator/=(T);
233 inline Vector4 operator*(T)
const;
239 inline T length()
const;
240 inline T lengthSquared()
const;
241 inline void normalize();
243 inline void transfo4d(
const Mat4d&);
244 QString toString()
const {
return QString(
"[%1, %2, %3, %4]").arg(v[0]).arg(v[1]).arg(v[2]).arg(v[3]);}
252 template<
class T>
class Matrix3 260 inline Matrix3& operator=(
const T*);
261 inline void set(T,T,T,T,T,T,T,T,T);
263 inline T& operator[](
int);
264 inline operator T*();
265 inline operator const T*()
const;
278 inline T
trace()
const {
return r[0]+r[4]+r[8];}
280 inline T
angle()
const {
return acos(0.5*(this->trace()-1.0));}
282 inline void print(
void)
const;
283 QString toString(
int fieldWidth=0,
char format=
'g',
int precision=-1)
const {
return QString(
"[[%1, %2, %3], [%4, %5, %6], [%7, %8, %9]]")
284 .arg(r[0], fieldWidth, format, precision)
285 .arg(r[1], fieldWidth, format, precision)
286 .arg(r[2], fieldWidth, format, precision)
287 .arg(r[3], fieldWidth, format, precision)
288 .arg(r[4], fieldWidth, format, precision)
289 .arg(r[5], fieldWidth, format, precision)
290 .arg(r[6], fieldWidth, format, precision)
291 .arg(r[7], fieldWidth, format, precision)
292 .arg(r[8], fieldWidth, format, precision);}
300 template<
class T>
class Matrix4 304 Matrix4(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T);
309 inline Matrix4& operator=(
const T*);
310 inline void set(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T);
312 inline T& operator[](
int);
313 inline operator T*();
314 inline operator const T*()
const;
344 inline Vector4<T> getRow(
const int row)
const;
345 inline Vector4<T> getColumn(
const int column)
const;
348 inline QMatrix4x4 convertToQMatrix()
const;
350 inline void print(
void)
const;
351 QString toString(
int fieldWidth=0,
char format=
'g',
int precision=-1)
const {
return QString(
"[[%1, %2, %3, %4], [%5, %6, %7, %8], [%9, %10, %11, %12], [%13, %14, %15, %16]]")
352 .arg(r[0], fieldWidth, format, precision)
353 .arg(r[1], fieldWidth, format, precision)
354 .arg(r[2], fieldWidth, format, precision)
355 .arg(r[3], fieldWidth, format, precision)
356 .arg(r[4], fieldWidth, format, precision)
357 .arg(r[5], fieldWidth, format, precision)
358 .arg(r[6], fieldWidth, format, precision)
359 .arg(r[7], fieldWidth, format, precision)
360 .arg(r[8], fieldWidth, format, precision)
361 .arg(r[9], fieldWidth, format, precision)
362 .arg(r[10], fieldWidth, format, precision)
363 .arg(r[11], fieldWidth, format, precision)
364 .arg(r[12], fieldWidth, format, precision)
365 .arg(r[13], fieldWidth, format, precision)
366 .arg(r[14], fieldWidth, format, precision)
367 .arg(r[15], fieldWidth, format, precision);}
373 template<
class T> QDataStream& operator<<(QDataStream& out, const Vector2<T>& v) {out << v[0] << v[1];
return out;}
374 template<
class T> QDataStream& operator<<(QDataStream& out, const Vector3<T>& v) {out << v[0] << v[1] << v[2];
return out;}
375 template<
class T> QDataStream& operator<<(QDataStream& out, const Vector4<T>& v) {out << v[0] << v[1] << v[2] << v[3];
return out;}
376 template<
class T> QDataStream& operator<<(QDataStream& out, const Matrix4<T>& m) {out << m[0] << m[1] << m[2] << m[3] << m[4] << m[5] << m[6] << m[7] << m[8] << m[9] << m[10] << m[11] << m[12] << m[13] << m[14] << m[15];
return out;}
377 template<
class T> QDataStream& operator<<(QDataStream& out, const Matrix3<T>& m) {out << m[0] << m[1] << m[2] << m[3] << m[4] << m[5] << m[6] << m[7] << m[8];
return out;}
379 template<
class T> QDataStream&
operator>>(QDataStream& in,
Vector2<T>& v) {in >> v[0] >> v[1];
return in;}
380 template<
class T> QDataStream&
operator>>(QDataStream& in,
Vector3<T>& v) {in >> v[0] >> v[1] >> v[2];
return in;}
381 template<
class T> QDataStream&
operator>>(QDataStream& in,
Vector4<T>& v) {in >> v[0] >> v[1] >> v[2] >> v[3];
return in;}
382 template<
class T> QDataStream&
operator>>(QDataStream& in,
Matrix4<T>& m) {in >> m[0] >> m[1] >> m[2] >> m[3] >> m[4] >> m[5] >> m[6] >> m[7] >> m[8] >> m[9] >> m[10] >> m[11] >> m[12] >> m[13] >> m[14] >> m[15];
return in;}
383 template<
class T> QDataStream&
operator>>(QDataStream& in,
Matrix3<T>& m) {in >> m[0] >> m[1] >> m[2] >> m[3] >> m[4] >> m[5] >> m[6] >> m[7] >> m[8];
return in;}
386 template <
class T>
inline bool fuzzyEquals(T a, T b, T eps = std::numeric_limits<T>::epsilon())
388 if(a == b)
return true;
389 if(((a+eps) < b) || ((a-eps) > b))
return false;
410 v[0]=a[0]; v[1]=a[1];
422 return (v[0] == a.v[0] && v[1] == a.v[1]);
427 return (v[0] != a.v[0] || v[1] != a.v[1]);
453 v[0] += a.v[0]; v[1] += a.v[1];
458 v[0] -= a.v[0]; v[1] -= a.v[1];
463 v[0] *= s; v[1] *= s;
468 v[0] /= s; v[1] /= s;
483 return Vector2<T>(v[0] + b.v[0], v[1] + b.v[1]);
488 return Vector2<T>(v[0] - b.v[0], v[1] - b.v[1]);
504 return v[0] * b.v[0] + v[1] * b.v[1];
510 return (T) std::sqrt(v[0] * v[0] + v[1] * v[1]);
515 return v[0] * v[0] + v[1] * v[1];
520 T s = (T) 1 / std::sqrt(v[0] * v[0] + v[1] * v[1]);
546 v[0]=x; v[1]=x; v[2]=x;
551 v[0]=x; v[1]=y; v[2]=z;
568 v[0]=a[0]; v[1]=a[1]; v[2]=a[2];
574 v[0]=x; v[1]=y; v[2]=z;
580 return (v[0] == a.v[0] && v[1] == a.v[1] && v[2] == a.v[2]);
585 return (v[0] != a.v[0] || v[1] != a.v[1] || v[2] != a.v[2]);
590 return ::fuzzyEquals(v[0], a.v[0], eps) && ::fuzzyEquals(v[1], a.v[1], eps) && ::fuzzyEquals(v[2], a.v[2], eps);
615 v[0] += a.v[0]; v[1] += a.v[1]; v[2] += a.v[2];
620 v[0] -= a.v[0]; v[1] -= a.v[1]; v[2] -= a.v[2];
625 v[0] *= s; v[1] *= s; v[2] *= s;
630 v[0] /= s; v[1] /= s; v[2] /= s;
645 return Vector3<T>(v[0] + b.v[0], v[1] + b.v[1], v[2] + b.v[2]);
650 return Vector3<T>(v[0] - b.v[0], v[1] - b.v[1], v[2] - b.v[2]);
655 return Vector3<T>(s * v[0], s * v[1], s * v[2]);
666 return v[0] * b.v[0] + v[1] * b.v[1] + v[2] * b.v[2];
673 return Vector3<T>(v[1] * b.v[2] - v[2] * b.v[1],
674 v[2] * b.v[0] - v[0] * b.v[2],
675 v[0] * b.v[1] - v[1] * b.v[0]);
681 const T cosAngle = dot(b)/std::sqrt(lengthSquared()*b.lengthSquared());
682 return cosAngle>=1 ? 0 : (cosAngle<=-1 ? M_PI : std::acos(cosAngle));
688 const T cosAngle = dot(b);
689 return cosAngle>=1 ? 0 : (cosAngle<=-1 ? M_PI : std::acos(cosAngle));
694 return (T) std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
699 return v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
704 T s = (T) (1. / std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]));
714 v[0]=m.r[0]*v0 + m.r[4]*v1 + m.r[8]*v[2] + m.r[12];
715 v[1]=m.r[1]*v0 + m.r[5]*v1 + m.r[9]*v[2] + m.r[13];
716 v[2]=m.r[2]*v0 + m.r[6]*v1 + m.r[10]*v[2] + m.r[14];
723 v[0]=m.r[0]*v0 + m.r[4]*v1 + m.r[8]*v[2] + m.r[12];
724 v[1]=m.r[1]*v0 + m.r[5]*v1 + m.r[9]*v[2] + m.r[13];
725 v[2]=m.r[2]*v0 + m.r[6]*v1 + m.r[10]*v[2] + m.r[14];
730 return Vec3f(v[0],v[1],v[2]);
735 return Vec3d(v[0],v[1],v[2]);
741 return std::asin(v[2]/length());
747 return std::atan2(v[1],v[0]);
757 v[0]=a.v[0]; v[1]=a.v[1]; v[2]=a.v[2]; v[3]=1;
762 v[0]=x; v[1]=y; v[2]=z; v[3]=1;
767 v[0]=x; v[1]=y; v[2]=z; v[3]=a;
772 v[0]=a.v[0]; v[1]=a.v[1]; v[2]=a.v[2]; v[3]=1;
778 v[0]=a[0]; v[1]=a[1]; v[2]=a[2]; v[3]=a[3];
784 v[0]=x; v[1]=y; v[2]=z; v[3]=a;
789 return (v[0] == a.v[0] && v[1] == a.v[1] && v[2] == a.v[2] && v[3] == a.v[3]);
794 return (v[0] != a.v[0] || v[1] != a.v[1] || v[2] != a.v[2] || v[3] != a.v[3]);
819 v[0] += a.v[0]; v[1] += a.v[1]; v[2] += a.v[2]; v[3] += a.v[3];
824 v[0] -= a.v[0]; v[1] -= a.v[1]; v[2] -= a.v[2]; v[3] -= a.v[3];
829 v[0] *= s; v[1] *= s; v[2] *= s; v[3] *= s;
834 v[0] /= s; v[1] /= s; v[2] /= s; v[3] /= s;
839 return Vector4<T>(-v[0], -v[1], -v[2], -v[3]);
849 return Vector4<T>(v[0] + b.v[0], v[1] + b.v[1], v[2] + b.v[2], v[3] + b.v[3]);
854 return Vector4<T>(v[0] - b.v[0], v[1] - b.v[1], v[2] - b.v[2], v[3] - b.v[3]);
859 return Vector4<T>(s * v[0], s * v[1], s * v[2], s * v[3]);
864 return Vector4<T>(v[0]/s, v[1]/s, v[2]/s, v[3]/s);
869 return v[0] * b.v[0] + v[1] * b.v[1] + v[2] * b.v[2] + v[3] * b.v[3];
874 return (T) std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3]);
879 return v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3];
884 T s = (T) (1. / std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3]));
908 memcpy(r,m,
sizeof(T)*9);
913 r[0] = v0.v[0]; r[3] = v1.v[0]; r[6] = v2.v[0];
914 r[1] = v0.v[1]; r[4] = v1.v[1]; r[7] = v2.v[1];
915 r[2] = v0.v[2]; r[5] = v1.v[2]; r[8] = v2.v[2];
920 r[0] = a; r[3] = d; r[6] = g;
921 r[1] = b; r[4] = e; r[7] = h;
922 r[2] = c; r[5] = f; r[8] = i;
925 template<
class T>
void Matrix3<T>::set(T a, T b, T c, T d, T e, T f, T g, T h, T i)
927 r[0] = a; r[3] = d; r[6] = g;
928 r[1] = b; r[4] = e; r[7] = h;
929 r[2] = c; r[5] = f; r[8] = i;
957 return Vector3<T>(r[0]*a.v[0] + r[3]*a.v[1] + r[6]*a.v[2],
958 r[1]*a.v[0] + r[4]*a.v[1] + r[7]*a.v[2],
959 r[2]*a.v[0] + r[5]*a.v[1] + r[8]*a.v[2]);
971 #define MATMUL(R, C) (r[R] * a.r[C] + r[R+3] * a.r[C+1] + r[R+6] * a.r[C+2]) 972 return Matrix3<T>(MATMUL(0,0), MATMUL(1,0), MATMUL(2,0),
973 MATMUL(0,3), MATMUL(1,3), MATMUL(2,3),
974 MATMUL(0,6), MATMUL(1,6), MATMUL(2,6));
981 return Matrix3<T>(r[0]+a.r[0], r[1]+a.r[1], r[2]+a.r[2],
982 r[3]+a.r[3], r[4]+a.r[4], r[5]+a.r[5],
983 r[6]+a.r[6], r[7]+a.r[7], r[8]+a.r[8]);
988 return Matrix3<T>(r[0]-a.r[0], r[1]-a.r[1], r[2]-a.r[2],
989 r[3]-a.r[3], r[4]-a.r[4], r[5]-a.r[5],
990 r[6]-a.r[6], r[7]-a.r[7], r[8]-a.r[8]);
1003 #define SWAP_ROWS(a, b) { T *_tmp = a; (a)=(b); (b)=_tmp; } 1004 #define MAT(m,r,c) (m)[(c)*3+(r)] 1010 r0 = wtmp[0], r1 = wtmp[1], r2 = wtmp[2];
1012 r0[0] = MAT(m, 0, 0), r0[1] = MAT(m, 0, 1), r0[2] = MAT(m, 0, 2),
1013 r0[3] = 1.0, r0[4] = r0[5] = 0.0,
1014 r1[0] = MAT(m, 1, 0), r1[1] = MAT(m, 1, 1), r1[2] = MAT(m, 1, 2),
1015 r1[4] = 1.0, r1[3] = r1[5] = 0.0,
1016 r2[0] = MAT(m, 2, 0), r2[1] = MAT(m, 2, 1), r2[2] = MAT(m, 2, 2),
1017 r2[5] = 1.0, r2[3] = r2[4] = 0.0;
1020 if (fabs(r2[0]) > fabs(r1[0]))
1022 if (fabs(r1[0]) > fabs(r0[0]))
1056 if (fabs(r2[1]) > fabs(r1[1]))
1063 r2[2] -= m2 * r1[2];
1087 r1[3] = s * (r1[3] - r2[3] * m1), r1[4] = s * (r1[4] - r2[4] * m1), r1[5] = s * (r1[5] - r2[5] * m1);
1089 r0[3] -= r2[3] * m0, r0[4] -= r2[4] * m0, r0[5] -= r2[5] * m0;
1093 r0[3] = s * (r0[3] - r1[3] * m0), r0[4] = s * (r0[4] - r1[4] * m0), r0[5] = s * (r0[5] - r1[5] * m0);
1095 MAT(out, 0, 0) = r0[3]; MAT(out, 0, 1) = r0[4]; MAT(out, 0, 2) = r0[5];
1096 MAT(out, 1, 0) = r1[3]; MAT(out, 1, 1) = r1[4]; MAT(out, 1, 2) = r1[5];
1097 MAT(out, 2, 0) = r2[3]; MAT(out, 2, 1) = r2[4]; MAT(out, 2, 2) = r2[5];
1107 printf(
"[%5.2lf %5.2lf %5.2lf]\n" 1108 "[%5.2lf %5.2lf %5.2lf]\n" 1109 "[%5.2lf %5.2lf %5.2lf]\n",
1121 memcpy(r,m,
sizeof(T)*16);
1148 template<
class T>
Matrix4<T>::Matrix4(T a, T b, T c, T d, T e, T f, T g, T h, T i, T j, T k, T l, T m, T n, T o, T p)
1150 r[0]=a; r[1]=b; r[2]=c; r[3]=d; r[4]=e; r[5]=f; r[6]=g; r[7]=h;
1151 r[8]=i; r[9]=j; r[10]=k; r[11]=l; r[12]=m; r[13]=n; r[14]=o; r[15]=p;
1154 template<
class T>
void Matrix4<T>::set(T a, T b, T c, T d, T e, T f, T g, T h, T i, T j, T k, T l, T m, T n, T o, T p)
1156 r[0]=a; r[1]=b; r[2]=c; r[3]=d; r[4]=e; r[5]=f; r[6]=g; r[7]=h;
1157 r[8]=i; r[9]=j; r[10]=k; r[11]=l; r[12]=m; r[13]=n; r[14]=o; r[15]=p;
1189 a.v[0], a.v[1], a.v[2], 1);
1197 const T c = (T) cos(angle);
1198 const T s = (T) sin(angle);
1200 return Matrix4<T>(a[0]*a[0]*d+c , a[1]*a[0]*d+a[2]*s, a[0]*a[2]*d-a[1]*s, 0,
1201 a[0]*a[1]*d-a[2]*s, a[1]*a[1]*d+c , a[1]*a[2]*d+a[0]*s, 0,
1202 a[0]*a[2]*d+a[1]*s, a[1]*a[2]*d-a[0]*s, a[2]*a[2]*d+c , 0,
1208 T c = (T) cos(angle);
1209 T s = (T) sin(angle);
1220 T c = (T) cos(angle);
1221 T s = (T) sin(angle);
1232 T c = (T) cos(angle);
1233 T s = (T) sin(angle);
1253 return scaling(
Vector3<T>(scale, scale, scale));
1259 return Vector3<T>(r[0]*a.v[0] + r[4]*a.v[1] + r[8]*a.v[2] + r[12],
1260 r[1]*a.v[0] + r[5]*a.v[1] + r[9]*a.v[2] + r[13],
1261 r[2]*a.v[0] + r[6]*a.v[1] + r[10]*a.v[2] + r[14]);
1266 return Vector3<T>(r[0]*a.v[0] + r[4]*a.v[1] + r[8]*a.v[2],
1267 r[1]*a.v[0] + r[5]*a.v[1] + r[9]*a.v[2],
1268 r[2]*a.v[0] + r[6]*a.v[1] + r[10]*a.v[2]);
1274 return Vector4<T>(r[0]*a.v[0] + r[4]*a.v[1] + r[8]*a.v[2] + r[12]*a.v[3],
1275 r[1]*a.v[0] + r[5]*a.v[1] + r[9]*a.v[2] + r[13]*a.v[3],
1276 r[2]*a.v[0] + r[6]*a.v[1] + r[10]*a.v[2] + r[14]*a.v[3]);
1281 a.set(r[0]*a.v[0] + r[4]*a.v[1] + r[8]*a.v[2] + r[12],
1282 r[1]*a.v[0] + r[5]*a.v[1] + r[9]*a.v[2] + r[13],
1283 r[2]*a.v[0] + r[6]*a.v[1] + r[10]*a.v[2] + r[14]);
1289 r[1], r[5], r[9], r[13],
1290 r[2], r[6], r[10], r[14],
1291 r[3], r[7], r[11], r[15]);
1296 #define MATMUL(R, C) (r[R] * a.r[C] + r[R+4] * a.r[C+1] + r[R+8] * a.r[C+2] + r[R+12] * a.r[C+3]) 1297 return Matrix4<T>(MATMUL(0,0) , MATMUL(1,0) , MATMUL(2,0) , MATMUL(3,0) ,
1298 MATMUL(0,4) , MATMUL(1,4) , MATMUL(2,4) , MATMUL(3,4) ,
1299 MATMUL(0,8) , MATMUL(1,8) , MATMUL(2,8) , MATMUL(3,8) ,
1300 MATMUL(0,12), MATMUL(1,12), MATMUL(2,12), MATMUL(3,12));
1307 return Matrix4<T>(r[0]+a.r[0] , r[1]+a.r[1] , r[2]+a.r[2] , r[3]+a.r[3] ,
1308 r[4]+a.r[4] , r[5]+a.r[5] , r[6]+a.r[6] , r[7]+a.r[7] ,
1309 r[8]+a.r[8] , r[9]+a.r[9] , r[10]+a.r[10], r[11]+a.r[11],
1310 r[12]+a.r[12], r[13]+a.r[13], r[14]+a.r[14], r[15]+a.r[15]);
1315 return Matrix4<T>(r[0]-a.r[0] , r[1]-a.r[1] , r[2]-a.r[2] , r[3]-a.r[3] ,
1316 r[4]-a.r[4] , r[5]-a.r[5] , r[6]-a.r[6] , r[7]-a.r[7] ,
1317 r[8]-a.r[8] , r[9]-a.r[9] , r[10]-a.r[10], r[11]-a.r[11],
1318 r[12]-a.r[12], r[13]-a.r[13], r[14]-a.r[14], r[15]-a.r[15]);
1333 #define SWAP_ROWS(a, b) { T *_tmp = a; (a)=(b); (b)=_tmp; } 1334 #define MAT(m,r,c) (m)[(c)*4+(r)] 1337 T m0, m1, m2, m3, s;
1338 T *r0, *r1, *r2, *r3;
1340 r0 = wtmp[0], r1 = wtmp[1], r2 = wtmp[2], r3 = wtmp[3];
1342 r0[0] = MAT(m, 0, 0), r0[1] = MAT(m, 0, 1),
1343 r0[2] = MAT(m, 0, 2), r0[3] = MAT(m, 0, 3),
1344 r0[4] = 1.0, r0[5] = r0[6] = r0[7] = 0.0,
1345 r1[0] = MAT(m, 1, 0), r1[1] = MAT(m, 1, 1),
1346 r1[2] = MAT(m, 1, 2), r1[3] = MAT(m, 1, 3),
1347 r1[5] = 1.0, r1[4] = r1[6] = r1[7] = 0.0,
1348 r2[0] = MAT(m, 2, 0), r2[1] = MAT(m, 2, 1),
1349 r2[2] = MAT(m, 2, 2), r2[3] = MAT(m, 2, 3),
1350 r2[6] = 1.0, r2[4] = r2[5] = r2[7] = 0.0,
1351 r3[0] = MAT(m, 3, 0), r3[1] = MAT(m, 3, 1),
1352 r3[2] = MAT(m, 3, 2), r3[3] = MAT(m, 3, 3),
1353 r3[7] = 1.0, r3[4] = r3[5] = r3[6] = 0.0;
1356 if (fabs(r3[0]) > fabs(r2[0]))
1358 if (fabs(r2[0]) > fabs(r1[0]))
1360 if (fabs(r1[0]) > fabs(r0[0]))
1407 if (fabs(r3[1]) > fabs(r2[1]))
1409 if (fabs(r2[1]) > fabs(r1[1]))
1417 r2[2] -= m2 * r1[2];
1418 r3[2] -= m3 * r1[2];
1419 r2[3] -= m2 * r1[3];
1420 r3[3] -= m3 * r1[3];
1443 if (fabs(r3[2]) > fabs(r2[2]))
1450 r3[3] -= m3 * r2[3], r3[4] -= m3 * r2[4],
1451 r3[5] -= m3 * r2[5], r3[6] -= m3 * r2[6], r3[7] -= m3 * r2[7];
1465 r2[4] = s * (r2[4] - r3[4] * m2), r2[5] = s * (r2[5] - r3[5] * m2),
1466 r2[6] = s * (r2[6] - r3[6] * m2), r2[7] = s * (r2[7] - r3[7] * m2);
1468 r1[4] -= r3[4] * m1, r1[5] -= r3[5] * m1,
1469 r1[6] -= r3[6] * m1, r1[7] -= r3[7] * m1;
1471 r0[4] -= r3[4] * m0, r0[5] -= r3[5] * m0,
1472 r0[6] -= r3[6] * m0, r0[7] -= r3[7] * m0;
1476 r1[4] = s * (r1[4] - r2[4] * m1), r1[5] = s * (r1[5] - r2[5] * m1),
1477 r1[6] = s * (r1[6] - r2[6] * m1), r1[7] = s * (r1[7] - r2[7] * m1);
1479 r0[4] -= r2[4] * m0, r0[5] -= r2[5] * m0,
1480 r0[6] -= r2[6] * m0, r0[7] -= r2[7] * m0;
1484 r0[4] = s * (r0[4] - r1[4] * m0), r0[5] = s * (r0[5] - r1[5] * m0),
1485 r0[6] = s * (r0[6] - r1[6] * m0), r0[7] = s * (r0[7] - r1[7] * m0);
1487 MAT(out, 0, 0) = r0[4];
1488 MAT(out, 0, 1) = r0[5], MAT(out, 0, 2) = r0[6];
1489 MAT(out, 0, 3) = r0[7], MAT(out, 1, 0) = r1[4];
1490 MAT(out, 1, 1) = r1[5], MAT(out, 1, 2) = r1[6];
1491 MAT(out, 1, 3) = r1[7], MAT(out, 2, 0) = r2[4];
1492 MAT(out, 2, 1) = r2[5], MAT(out, 2, 2) = r2[6];
1493 MAT(out, 2, 3) = r2[7], MAT(out, 3, 0) = r3[4];
1494 MAT(out, 3, 1) = r3[5], MAT(out, 3, 2) = r3[6];
1495 MAT(out, 3, 3) = r3[7];
1518 return Vector4<T>(r[0 + row], r[4 + row], r[8 + row], r[12 + row]);
1523 return Vector4<T>(r[0 + column * 4], r[1 + column * 4], r[2 + column * 4], r[3 + column * 4]);
1528 return QMatrix4x4( r[0], r[4], r[8],r[12],
1529 r[1], r[5], r[9],r[13],
1530 r[2], r[6],r[10],r[14],
1531 r[3], r[7],r[11],r[15] );
1536 printf(
"[%5.2lf %5.2lf %5.2lf %17.12le]\n" 1537 "[%5.2lf %5.2lf %5.2lf %17.12le]\n" 1538 "[%5.2lf %5.2lf %5.2lf %17.12le]\n" 1539 "[%5.2lf %5.2lf %5.2lf %17.12le]\n\n",
1540 r[0],r[4],r[8],r[12],
1541 r[1],r[5],r[9],r[13],
1542 r[2],r[6],r[10],r[14],
1543 r[3],r[7],r[11],r[15]);
1547 template<
class T>
inline 1550 return a.v[0] * b.v[0] + a.v[1] * b.v[1];
1553 template<
class T>
inline 1556 return a.v[0] * b.v[0] + a.v[1] * b.v[1] + a.v[2] * b.v[2];
1559 template<
class T>
inline 1562 return a.v[0]*b.v[0] + a.v[1]*b.v[1] + a.v[2]*b.v[2] + a.v[3]*b.v[3];
1565 template<
class T>
inline 1571 template<
class T>
inline 1577 template<
class T>
inline 1580 return Vector4<T>(s*v[0],s*v[1],s*v[2],s*v[3]);
1584 Q_DECLARE_TYPEINFO(
Vec2d, Q_PRIMITIVE_TYPE);
1585 Q_DECLARE_TYPEINFO(
Vec2f, Q_PRIMITIVE_TYPE);
1586 Q_DECLARE_TYPEINFO(
Vec2i, Q_PRIMITIVE_TYPE);
1587 Q_DECLARE_TYPEINFO(
Vec3d, Q_PRIMITIVE_TYPE);
1588 Q_DECLARE_TYPEINFO(
Vec3f, Q_PRIMITIVE_TYPE);
1589 Q_DECLARE_TYPEINFO(
Vec4d, Q_PRIMITIVE_TYPE);
1590 Q_DECLARE_TYPEINFO(
Vec4f, Q_PRIMITIVE_TYPE);
1591 Q_DECLARE_TYPEINFO(
Vec4i, Q_PRIMITIVE_TYPE);
1592 Q_DECLARE_TYPEINFO(
Mat4d, Q_PRIMITIVE_TYPE);
1593 Q_DECLARE_TYPEINFO(
Mat4f, Q_PRIMITIVE_TYPE);
1594 Q_DECLARE_TYPEINFO(
Mat3d, Q_PRIMITIVE_TYPE);
1595 Q_DECLARE_TYPEINFO(
Mat3f, Q_PRIMITIVE_TYPE);
1599 Q_DECLARE_METATYPE(
Vec2d)
1600 Q_DECLARE_METATYPE(
Vec2f)
1601 Q_DECLARE_METATYPE(
Vec2i)
1602 Q_DECLARE_METATYPE(
Vec3d)
1603 Q_DECLARE_METATYPE(
Vec3f)
1604 Q_DECLARE_METATYPE(
Vec4d)
1605 Q_DECLARE_METATYPE(
Vec4f)
1606 Q_DECLARE_METATYPE(
Vec4i)
1607 Q_DECLARE_METATYPE(
Mat4d)
1608 Q_DECLARE_METATYPE(
Mat4f)
1609 Q_DECLARE_METATYPE(
Mat3d)
1610 Q_DECLARE_METATYPE(
Mat3f)
1613 inline QVector3D operator*(
const QMatrix3x3& mat,
const QVector3D& vec)
1617 x = vec.x() * mat(0,0) +
1618 vec.y() * mat(0,1) +
1620 y = vec.x() * mat(1,0) +
1621 vec.y() * mat(1,1) +
1623 z = vec.x() * mat(2,0) +
1624 vec.y() * mat(2,1) +
1626 return QVector3D(x,y,z);
1629 #endif // _VECMATH_H_ bool fuzzyEquals(const Vector3< T > &, T epsilon=std::numeric_limits< T >::epsilon()) const
allows for a fuzzy comparison using some epsilon value
T trace() const
return trace (sum of diagonal elements).
A templatized column-major 3x3 matrix compatible with openGL (mostly for NormalMatrix calculation)...
T angle() const
return rotational angle
A templatized 2d vector compatible with openGL.
A templatized column-major 4x4 matrix compatible with openGL.
A templatized 4d vector compatible with openGL.
QDataStream & operator>>(QDataStream &in, SphericalRegionP ®ion)
Load the SphericalRegionP from a binary blob.
A templatized 3d vector compatible with openGL.
const QCPRange operator-(const QCPRange &range, double value)
const QCPRange operator/(const QCPRange &range, double value)
const QCPRange operator+(const QCPRange &range, double value)