59 #define ACG_MATRIX4X4_C 65 #include "Matrix4x4T.hh" 66 #include "../Utils/NumLimitsT.hh" 75 #define MAT(m,r,c) ((m)[(r)+((c)<<2)]) 76 #define M(r,w) (MAT(mat_,r,w)) 82 template <
typename Scalar>
87 #define RHS(row,col) MAT(_rhs.mat_, row,col) 88 #define TMP(row,col) MAT(tmp.mat_, row,col) 91 Scalar mi0, mi1, mi2, mi3;
94 for (i = 0; i < 4; i++) {
95 mi0=M(i,0); mi1=M(i,1); mi2=M(i,2); mi3=M(i,3);
96 TMP(i,0) = mi0*RHS(0,0) + mi1*RHS(1,0) + mi2*RHS(2,0) + mi3*RHS(3,0);
97 TMP(i,1) = mi0*RHS(0,1) + mi1*RHS(1,1) + mi2*RHS(2,1) + mi3*RHS(3,1);
98 TMP(i,2) = mi0*RHS(0,2) + mi1*RHS(1,2) + mi2*RHS(2,2) + mi3*RHS(3,2);
99 TMP(i,3) = mi0*RHS(0,3) + mi1*RHS(1,3) + mi2*RHS(2,3) + mi3*RHS(3,3);
112 template <
typename Scalar>
117 #define RHS(row,col) MAT(_rhs.mat_, row,col) 120 Scalar mi0, mi1, mi2, mi3;
122 for (i = 0; i < 4; i++)
124 mi0=M(i,0); mi1=M(i,1); mi2=M(i,2); mi3=M(i,3);
125 M(i,0) = mi0 * RHS(0,0) + mi1 * RHS(1,0) + mi2 * RHS(2,0) + mi3 * RHS(3,0);
126 M(i,1) = mi0 * RHS(0,1) + mi1 * RHS(1,1) + mi2 * RHS(2,1) + mi3 * RHS(3,1);
127 M(i,2) = mi0 * RHS(0,2) + mi1 * RHS(1,2) + mi2 * RHS(2,2) + mi3 * RHS(3,2);
128 M(i,3) = mi0 * RHS(0,3) + mi1 * RHS(1,3) + mi2 * RHS(2,3) + mi3 * RHS(3,3);
140 template <
typename Scalar>
145 #define RHS(row,col) MAT(_rhs.mat_, row,col) 147 Scalar m0i, m1i, m2i, m3i;
150 m0i = M(0,i); m1i = M(1,i); m2i = M(2,i); m3i = M(3,i);
151 M(0,i) = RHS(0,0)*m0i + RHS(0,1)*m1i + RHS(0,2)*m2i + RHS(0,3)*m3i;
152 M(1,i) = RHS(1,0)*m0i + RHS(1,1)*m1i + RHS(1,2)*m2i + RHS(1,3)*m3i;
153 M(2,i) = RHS(2,0)*m0i + RHS(2,1)*m1i + RHS(2,2)*m2i + RHS(2,3)*m3i;
154 M(3,i) = RHS(3,0)*m0i + RHS(3,1)*m1i + RHS(3,2)*m2i + RHS(3,3)*m3i;
164 template <
typename Scalar>
165 template <
typename T>
171 M(0,0)*_v[0] + M(0,1)*_v[1] + M(0,2)*_v[2] + M(0,3)*_v[3],
172 M(1,0)*_v[0] + M(1,1)*_v[1] + M(1,2)*_v[2] + M(1,3)*_v[3],
173 M(2,0)*_v[0] + M(2,1)*_v[1] + M(2,2)*_v[2] + M(2,3)*_v[3],
174 M(3,0)*_v[0] + M(3,1)*_v[1] + M(3,2)*_v[2] + M(3,3)*_v[3]);
181 template <
typename Scalar>
185 for (
int i = 0; i < 4; ++i) {
186 for (
int j = 0; j < 4; ++j) {
198 template <
typename Scalar>
199 template <
typename T>
204 Scalar x = M(0,0)*_v[0] + M(0,1)*_v[1] + M(0,2)*_v[2] + M(0,3);
205 Scalar y = M(1,0)*_v[0] + M(1,1)*_v[1] + M(1,2)*_v[2] + M(1,3);
206 Scalar z = M(2,0)*_v[0] + M(2,1)*_v[1] + M(2,2)*_v[2] + M(2,3);
207 Scalar w = M(3,0)*_v[0] + M(3,1)*_v[1] + M(3,2)*_v[2] + M(3,3);
221 template <
typename Scalar>
222 template <
typename T>
227 Scalar x = M(0,0)*_v[0] + M(0,1)*_v[1] + M(0,2)*_v[2];
228 Scalar y = M(1,0)*_v[0] + M(1,1)*_v[1] + M(1,2)*_v[2];
229 Scalar z = M(2,0)*_v[0] + M(2,1)*_v[1] + M(2,2)*_v[2];
237 template <
typename Scalar>
243 *m++ = 0.0; *m++ = 0.0; *m++ = 0.0; *m++ = 0.0;
244 *m++ = 0.0; *m++ = 0.0; *m++ = 0.0; *m++ = 0.0;
245 *m++ = 0.0; *m++ = 0.0; *m++ = 0.0; *m++ = 0.0;
246 *m++ = 0.0; *m++ = 0.0; *m++ = 0.0; *m = 0.0;
253 template <
typename Scalar>
259 *m++ = 1.0; *m++ = 0.0; *m++ = 0.0; *m++ = 0.0;
260 *m++ = 0.0; *m++ = 1.0; *m++ = 0.0; *m++ = 0.0;
261 *m++ = 0.0; *m++ = 0.0; *m++ = 1.0; *m++ = 0.0;
262 *m++ = 0.0; *m++ = 0.0; *m++ = 0.0; *m = 1.0;
269 template <
typename Scalar>
275 for(
int i=0; i<4; i++ )
277 for(
int j=i+1; j<4; j++ )
280 MAT(mat_,i,j) = MAT(mat_,j,i);
294 template <
typename Scalar>
299 #define SWAP_ROWS(a, b) { Scalar *_tmp = a; (a)=(b); (b)=_tmp; } 302 Scalar m0, m1, m2, m3, s;
303 Scalar *r0, *r1, *r2, *r3;
305 r0 = wtmp[0], r1 = wtmp[1], r2 = wtmp[2], r3 = wtmp[3];
307 r0[0] = M(0,0); r0[1] = M(0,1);
308 r0[2] = M(0,2); r0[3] = M(0,3);
309 r0[4] = 1.0, r0[5] = r0[6] = r0[7] = 0.0;
311 r1[0] = M(1,0); r1[1] = M(1,1);
312 r1[2] = M(1,2); r1[3] = M(1,3);
313 r1[5] = 1.0, r1[4] = r1[6] = r1[7] = 0.0;
315 r2[0] = M(2,0); r2[1] = M(2,1);
316 r2[2] = M(2,2); r2[3] = M(2,3);
317 r2[6] = 1.0, r2[4] = r2[5] = r2[7] = 0.0;
319 r3[0] = M(3,0); r3[1] = M(3,1);
320 r3[2] = M(3,2); r3[3] = M(3,3);
321 r3[7] = 1.0, r3[4] = r3[5] = r3[6] = 0.0;
325 if (fabs(r3[0])>fabs(r2[0])) SWAP_ROWS(r3, r2);
326 if (fabs(r2[0])>fabs(r1[0])) SWAP_ROWS(r2, r1);
327 if (fabs(r1[0])>fabs(r0[0])) SWAP_ROWS(r1, r0);
328 if (0.0 == r0[0])
return false;
332 m1 = r1[0]/r0[0]; m2 = r2[0]/r0[0]; m3 = r3[0]/r0[0];
333 s = r0[1]; r1[1] -= m1 * s; r2[1] -= m2 * s; r3[1] -= m3 * s;
334 s = r0[2]; r1[2] -= m1 * s; r2[2] -= m2 * s; r3[2] -= m3 * s;
335 s = r0[3]; r1[3] -= m1 * s; r2[3] -= m2 * s; r3[3] -= m3 * s;
337 if (s != 0.0) { r1[4] -= m1 * s; r2[4] -= m2 * s; r3[4] -= m3 * s; }
339 if (s != 0.0) { r1[5] -= m1 * s; r2[5] -= m2 * s; r3[5] -= m3 * s; }
341 if (s != 0.0) { r1[6] -= m1 * s; r2[6] -= m2 * s; r3[6] -= m3 * s; }
343 if (s != 0.0) { r1[7] -= m1 * s; r2[7] -= m2 * s; r3[7] -= m3 * s; }
347 if (fabs(r3[1])>fabs(r2[1])) SWAP_ROWS(r3, r2);
348 if (fabs(r2[1])>fabs(r1[1])) SWAP_ROWS(r2, r1);
349 if (0.0 == r1[1])
return false;
353 m2 = r2[1]/r1[1]; m3 = r3[1]/r1[1];
354 r2[2] -= m2 * r1[2]; r3[2] -= m3 * r1[2];
355 r2[3] -= m2 * r1[3]; r3[3] -= m3 * r1[3];
356 s = r1[4];
if (0.0 != s) { r2[4] -= m2 * s; r3[4] -= m3 * s; }
357 s = r1[5];
if (0.0 != s) { r2[5] -= m2 * s; r3[5] -= m3 * s; }
358 s = r1[6];
if (0.0 != s) { r2[6] -= m2 * s; r3[6] -= m3 * s; }
359 s = r1[7];
if (0.0 != s) { r2[7] -= m2 * s; r3[7] -= m3 * s; }
363 if (fabs(r3[2])>fabs(r2[2])) SWAP_ROWS(r3, r2);
364 if (0.0 == r2[2])
return false;
375 if (0.0 == r3[3])
return false;
378 r3[4] *= s; r3[5] *= s; r3[6] *= s; r3[7] *= s;
382 r2[4] = s * (r2[4] - r3[4] * m2); r2[5] = s * (r2[5] - r3[5] * m2);
383 r2[6] = s * (r2[6] - r3[6] * m2); r2[7] = s * (r2[7] - r3[7] * m2);
385 r1[4] -= r3[4] * m1; r1[5] -= r3[5] * m1;
386 r1[6] -= r3[6] * m1; r1[7] -= r3[7] * m1;
388 r0[4] -= r3[4] * m0; r0[5] -= r3[5] * m0;
389 r0[6] -= r3[6] * m0; r0[7] -= r3[7] * m0;
393 r1[4] = s * (r1[4] - r2[4] * m1); r1[5] = s * (r1[5] - r2[5] * m1);
394 r1[6] = s * (r1[6] - r2[6] * m1); r1[7] = s * (r1[7] - r2[7] * m1);
396 r0[4] -= r2[4] * m0; r0[5] -= r2[5] * m0;
397 r0[6] -= r2[6] * m0; r0[7] -= r2[7] * m0;
401 r0[4] = s * (r0[4] - r1[4] * m0); r0[5] = s * (r0[5] - r1[5] * m0);
402 r0[6] = s * (r0[6] - r1[6] * m0); r0[7] = s * (r0[7] - r1[7] * m0);
404 M(0,0) = r0[4]; M(0,1) = r0[5];
405 M(0,2) = r0[6]; M(0,3) = r0[7];
406 M(1,0) = r1[4]; M(1,1) = r1[5];
407 M(1,2) = r1[6]; M(1,3) = r1[7];
408 M(2,0) = r2[4]; M(2,1) = r2[5];
409 M(2,2) = r2[6]; M(2,3) = r2[7];
410 M(3,0) = r3[4]; M(3,1) = r3[5];
411 M(3,2) = r3[6]; M(3,3) = r3[7];
void transpose()
transpose matrix
VectorT< T, 3 > transform_point(const VectorT< T, 3 > &_v) const
transform point (x',y',z',1) = M * (x,y,z,1)
Matrix4x4T & operator*=(const Matrix4x4T< Scalar > &_rhs)
self *= _rhs
void identity()
setup an identity matrix
Matrix4x4T & leftMult(const Matrix4x4T< Scalar > &_rhs)
multiply from left: self = _rhs * self
Namespace providing different geometric functions concerning angles.
bool invert()
matrix inversion (returns true on success)
Matrix4x4T operator*(const Matrix4x4T< Scalar > &inst) const
self * _rhs
void clear()
sets all elements to zero
VectorT< T, 3 > transform_vector(const VectorT< T, 3 > &_v) const
transform vector (x',y',z',0) = A * (x,y,z,0)