7 #ifndef __math_Matrix3x4_h__ 8 #define __math_Matrix3x4_h__ 52 #if FE_VEC_CHECK_VALID 54 set(column(0), 0.0f, 0.0f, 0.0f);
55 set(column(1), 0.0f, 0.0f, 0.0f);
56 set(column(2), 0.0f, 0.0f, 0.0f);
57 set(column(3), 0.0f, 0.0f, 0.0f);
64 template<
int M,
int N,
class U>
78 direction()=other.direction();
81 translation()=other.translation();
86 template<
int M,
int N,
class U>
89 direction()=other.column(0);
90 left()=other.column(1);
92 translation()=other.column(3);
98 {
return !operator==(other); }
109 void copy16(U* array)
const;
114 void copyTranslation(U* array)
const;
117 {
return m_vector[index]; }
119 {
return m_vector[index]; }
122 {
return m_vector[0]; }
124 {
return m_vector[1]; }
126 {
return m_vector[2]; }
128 {
return m_vector[3]; }
131 {
return m_vector[0]; }
133 {
return m_vector[1]; }
135 {
return m_vector[2]; }
137 {
return m_vector[3]; }
141 {
return m_vector[j][i]; }
144 {
return m_vector[j][i]; }
162 return (0 == memcmp(reinterpret_cast<const void *>(m_vector),
163 reinterpret_cast<const void *>(other.m_vector),
170 template<
class T,
class U>
174 return (equivalent(lhs.direction(), rhs.direction(), margin) &&
175 equivalent(lhs.left(), rhs.left(), margin) &&
176 equivalent(lhs.up(), rhs.up(), margin) &&
177 equivalent(lhs.translation(), rhs.translation(), margin));
187 template<
class T,
class U>
190 set(lhs.column(0), pArray[0], pArray[1], pArray[2]);
191 set(lhs.column(1), pArray[4], pArray[5], pArray[6]);
192 set(lhs.column(2), pArray[8], pArray[9], pArray[10]);
193 set(lhs.column(3), pArray[12], pArray[13], pArray[14]);
209 if(isZero(from) || isZero(to))
211 feX(
"Matrix<3,4,T>:set (from,to)",
"zero length vector");
214 F32 cosa=dot(from,to);
223 if(cosa< -FE_ALMOST1)
227 set(axis,0.0,from[0],-from[1]);
229 T len=sqrt(axis[1]*axis[1] + axis[2]*axis[2]);
230 if (len < FE_SLERP_DELTA)
232 set(axis,-from[2],0.0,from[0]);
237 sina=sin(acos(cosa));
243 const F32 mcosa=1-cosa;
246 axis[0]*axis[0]*mcosa + cosa,
247 axis[1]*axis[0]*mcosa + axis[2]*sina,
248 axis[2]*axis[0]*mcosa - axis[1]*sina);
251 axis[0]*axis[1]*mcosa - axis[2]*sina,
252 axis[1]*axis[1]*mcosa + cosa,
253 axis[2]*axis[1]*mcosa + axis[0]*sina);
256 axis[0]*axis[2]*mcosa + axis[1]*sina,
257 axis[1]*axis[2]*mcosa - axis[0]*sina,
258 axis[2]*axis[2]*mcosa + cosa);
260 set(lhs.column(3), 0.0f, 0.0f, 0.0f);
265 template <
typename T>
268 set(lhs.column(0), 1.0f, 0.0f, 0.0f);
269 set(lhs.column(1), 0.0f, 1.0f, 0.0f);
270 set(lhs.column(2), 0.0f, 0.0f, 1.0f);
271 set(lhs.column(3), 0.0f, 0.0f, 0.0f);
282 template <
typename T>
286 set(lhs.column(0), rotation(0, 0), rotation(1, 0), rotation(2, 0));
287 set(lhs.column(1), rotation(0, 1), rotation(1, 1), rotation(2, 1));
288 set(lhs.column(2), rotation(0, 2), rotation(1, 2), rotation(2, 2));
299 template <
int N,
typename T>
304 lhs.translation()=translation;
315 template <
int N,
typename T>
320 fe::set(out,in[0]*lhs(0,0)+in[1]*lhs(0,1)+in[2]*lhs(0,2),
321 in[0]*lhs(1,0)+in[1]*lhs(1,1)+in[2]*lhs(1,2),
322 in[0]*lhs(2,0)+in[1]*lhs(2,1)+in[2]*lhs(2,2));
325 template <
int N,
typename T>
330 rotateVector(lhs,in,out);
334 template <
int N,
typename T>
341 return rotateVector(inverse,in);
350 template <
int N,
typename T>
355 fe::set(out,in[0]*lhs(0,0)+in[1]*lhs(0,1)+in[2]*lhs(0,2)+lhs(0,3),
356 in[0]*lhs(1,0)+in[1]*lhs(1,1)+in[2]*lhs(1,2)+lhs(1,3),
357 in[0]*lhs(2,0)+in[1]*lhs(2,1)+in[2]*lhs(2,2)+lhs(2,3));
360 template <
int N,
typename T>
366 transformVector(lhs,in,out);
370 template <
int N,
typename T>
377 return transformVector(inverse,in);
387 template <
int N,
typename T>
393 rotateVector(lhs,translation,rotated);
395 lhs.translation()+=rotated;
399 template <
typename T>
405 template <
typename T>
417 template <
typename T,
typename U>
420 const T sina=sin(radians);
421 const T cosa=cos(radians);
423 static const U32 index[3][2]={{1,2},{2,0},{0,1}};
424 U32 x1=index[axis][0];
425 U32 x2=index[axis][1];
429 lhs(0,x1)=c*sina+b*cosa;
430 lhs(0,x2)=c*cosa-b*sina;
433 lhs(1,x1)=c*sina+b*cosa;
434 lhs(1,x2)=c*cosa-b*sina;
437 lhs(2,x1)=c*sina+b*cosa;
438 lhs(2,x2)=c*cosa-b*sina;
476 template <
typename T,
typename U>
479 lhs(0,0)*=scalefactor;
480 lhs(1,1)*=scalefactor;
481 lhs(2,2)*=scalefactor;
485 template <
typename T,
typename U,
int N>
488 lhs(0,0)*=scalefactor[0];
489 lhs(1,1)*=scalefactor[1];
490 lhs(2,2)*=scalefactor[2];
494 template <
typename T,
typename U>
497 lhs(0,0)*=scalefactor[0];
498 lhs(1,1)*=scalefactor[1];
502 template <
typename T,
typename U>
505 lhs(0,0)*=scalefactor[0];
509 template <
typename T>
510 template <
typename U>
513 array[0]=m_vector[0][0];
514 array[1]=m_vector[0][1];
515 array[2]=m_vector[0][2];
518 array[4]=m_vector[1][0];
519 array[5]=m_vector[1][1];
520 array[6]=m_vector[1][2];
523 array[8]=m_vector[2][0];
524 array[9]=m_vector[2][1];
525 array[10]=m_vector[2][2];
528 array[12]=m_vector[3][0];
529 array[13]=m_vector[3][1];
530 array[14]=m_vector[3][2];
534 template<
int M,
int N,
class T>
545 for(
int i = 0;i < m; i++)
547 for(
int j = 0;j < n; j++)
551 for(
int j = n;j < 4; j++)
556 for(
int i = m;i < 3; i++)
558 for(
int j = 0;j < 4; j++)
565 template<
int M,
int N,
class T>
577 for(
int i = 0;i < m; i++)
579 for(
int j = 0;j < n; j++)
583 for(
int j = n;j < N; j++)
588 for(
int i = m;i < M; i++)
590 for(
int j = 0;j < N; j++)
597 template <
typename T>
598 template <
typename U>
601 array[0]=m_vector[3][0];
602 array[1]=m_vector[3][1];
603 array[2]=m_vector[3][2];
606 template <
typename T>
614 template <
typename T>
617 const T x2=quat[0]+quat[0];
618 const T y2=quat[1]+quat[1];
619 const T z2=quat[2]+quat[2];
620 const T xx=quat[0]*x2;
621 const T xy=quat[0]*y2;
622 const T xz=quat[0]*z2;
623 const T yy=quat[1]*y2;
624 const T yz=quat[1]*z2;
625 const T zz=quat[2]*z2;
626 const T wx=quat[3]*x2;
627 const T wy=quat[3]*y2;
628 const T wz=quat[3]*z2;
631 set(m_vector[0], 1.0f-(yy+zz), xy+wz, xz-wy);
632 set(m_vector[1], xy-wz, 1.0f-(xx+zz), yz+wx);
633 set(m_vector[2], xz+wy, yz-wx, 1.0f-(xx+yy));
634 set(m_vector[3], 0.0f, 0.0f, 0.0f);
643 template<
typename T,
typename U>
647 R[0] = A[0]*B[0] + A[3]*B[1] + A[6]*B[2] + A[9];
648 R[1] = A[1]*B[0] + A[4]*B[1] + A[7]*B[2] + A[10];
649 R[2] = A[2]*B[0] + A[5]*B[1] + A[8]*B[2] + A[11];
651 R[3] = A[0]*B[3] + A[3]*B[4] + A[6]*B[5] + A[9];
652 R[4] = A[1]*B[3] + A[4]*B[4] + A[7]*B[5] + A[10];
653 R[5] = A[2]*B[3] + A[5]*B[4] + A[8]*B[5] + A[11];
655 R[6] = A[0]*B[6] + A[3]*B[7] + A[6]*B[8] + A[9];
656 R[7] = A[1]*B[6] + A[4]*B[7] + A[7]*B[8] + A[10];
657 R[8] = A[2]*B[6] + A[5]*B[7] + A[8]*B[8] + A[11];
659 R[9] = A[0]*B[9] + A[3]*B[10]+ A[6]*B[11]+ A[9];
660 R[10]= A[1]*B[9] + A[4]*B[10]+ A[7]*B[11]+ A[10];
661 R[11]= A[2]*B[9] + A[5]*B[10]+ A[8]*B[11]+ A[11];
668 template<
typename T,
typename U>
681 template<
class T,
class U>
685 result.column(0) = lhs.column(0) + rhs.column(0);
686 result.column(1) = lhs.column(1) + rhs.column(1);
687 result.column(2) = lhs.column(2) + rhs.column(2);
688 result.column(3) = lhs.column(3) + rhs.column(3);
695 template<
class T,
class U>
699 result.column(0) = lhs.column(0) - rhs.column(0);
700 result.column(1) = lhs.column(1) - rhs.column(1);
701 result.column(2) = lhs.column(2) - rhs.column(2);
702 result.column(3) = lhs.column(3) - rhs.column(3);
709 template<
class T,
class U>
713 result.column(0) = lhs * rhs.column(0);
714 result.column(1) = lhs * rhs.column(1);
715 result.column(2) = lhs * rhs.column(2);
716 result.column(3) = lhs * rhs.column(3);
723 template<
class T,
class U>
727 result.column(0) = rhs * lhs.column(0);
728 result.column(1) = rhs * lhs.column(1);
729 result.column(2) = rhs * lhs.column(2);
730 result.column(3) = rhs * lhs.column(3);
737 template<
typename T,
typename U>
749 template<
typename T,
typename U>
761 template<
class T,
class U>
772 template<
class T,
class U>
780 template <
typename T>
783 return *
this=preMatrix*(*this);
811 for(
unsigned int i = 0;i < 3; i++)
813 for(
unsigned int j = 0;j < 4; j++)
815 s.
catf(
"%6.3f ", a_matrix(i,j));
829 template <
typename T>
837 copy(matrix4x4,matrix);
839 invert(inverse4x4,matrix4x4);
840 copy(inverse,inverse4x4);
844 template <
typename T>
851 copy(matrix4x4,matrix);
853 return determinant(matrix4x4);
864 template <
typename T,
typename U>
870 invert(matrix1_inv,matrix1);
882 translate(result,move);
883 result=mspin*matrix1*result;
895 template <
typename T>
902 set(rotation,zAxis,unit(direction));
905 setTranslation(result,center);
918 set(matrix.column(0),
919 left(0,0)*right(0,0)+left(1,0)*right(0,1)+left(2,0)*right(0,2),
920 left(0,0)*right(1,0)+left(1,0)*right(1,1)+left(2,0)*right(1,2),
921 left(0,0)*right(2,0)+left(1,0)*right(2,1)+left(2,0)*right(2,2));
923 set(matrix.column(1),
924 left(0,1)*right(0,0)+left(1,1)*right(0,1)+left(2,1)*right(0,2),
925 left(0,1)*right(1,0)+left(1,1)*right(1,1)+left(2,1)*right(1,2),
926 left(0,1)*right(2,0)+left(1,1)*right(2,1)+left(2,1)*right(2,2));
928 set(matrix.column(2),
929 left(0,2)*right(0,0)+left(1,2)*right(0,1)+left(2,2)*right(0,2),
930 left(0,2)*right(1,0)+left(1,2)*right(1,1)+left(2,2)*right(1,2),
931 left(0,2)*right(2,0)+left(1,2)*right(2,1)+left(2,2)*right(2,2));
933 set(matrix.column(3),
934 left(0,3)*right(0,0)+left(1,3)*right(0,1)+left(2,3)*right(0,2)+
936 left(0,3)*right(1,0)+left(1,3)*right(1,1)+left(2,3)*right(1,2)+
938 left(0,3)*right(2,0)+left(1,3)*right(2,1)+left(2,3)*right(2,2)+
956 tr=matrix(0,0)+matrix(1,1)+matrix(2,2);
964 set(*
this,(matrix(2,1)-matrix(1,2))*s2,(matrix(0,2)-matrix(2,0))*s2,
965 (matrix(1,0)-matrix(0,1))*s2,0.5f*s);
971 if(matrix(1,1)>matrix(0,0))
976 if(matrix(2,2)>matrix(i,i))
981 const int nxt[3]={1,2,0};
985 s=sqrt((matrix(i,i)-(matrix(j,j)+matrix(k,k)))+1.0f);
994 q[3]=(matrix(k,j)-matrix(j,k))*s;
995 q[j]=(matrix(j,i)+matrix(i,j))*s;
996 q[k]=(matrix(k,i)+matrix(i,k))*s;
998 set(*
this,q[0],q[1],q[2],q[3]);
1010 FE_DL_PUBLIC BWORD makeFrame(SpatialTransform &a_frame,
1014 FE_DL_PUBLIC BWORD makeFrame(SpatialTransform &a_frame,
1018 FE_DL_PUBLIC BWORD makeFrame(SpatialTransform &a_frame,
1022 FE_DL_PUBLIC BWORD makeFrameCameraZ(SpatialTransform &a_frame,
1027 FE_DL_PUBLIC BWORD makeFrameTangentX(SpatialTransform &a_frame,
1031 FE_DL_PUBLIC BWORD makeFrameNormalY(SpatialTransform &a_frame,
1035 FE_DL_PUBLIC BWORD makeFrameNormalZ(SpatialTransform &a_frame,
T operator()(unsigned int i, unsigned int j) const
Column Major addressing.
Definition: Matrix3x4.h:140
Matrix< M, N, T > & subtract(Matrix< M, N, T > &R, const Matrix< M, N, T > &A, const Matrix< M, N, U > &B)
Matrix Matrix subtract.
Definition: Matrix.h:270
Matrix for 3D transformations.
Definition: Matrix3x4.h:47
kernel
Definition: namespace.dox:3
String print(const Matrix< M, N, T > &a_m)
Matrix print.
Definition: Matrix.h:368
Matrix< 4, 4, T > & invert(Matrix< 4, 4, T > &a_inverted, const Matrix< 4, 4, T > &a_matrix)
4x4 full matrix inversion
Definition: Matrix.h:1033
General template for fixed size numeric matrices.
Definition: Matrix.h:42
T & operator()(unsigned int i, unsigned int j)
Column Major addressing.
Definition: Matrix3x4.h:143
BWORD operator!=(const DualString &s1, const DualString &s2)
Compare two DualString's (reverse logic)
Definition: DualString.h:229
Matrix< M, L, T > operator*(const Matrix< M, N, T > &lhs, const Matrix< N, L, U > &rhs)
Matrix Matrix multiply.
Definition: Matrix.h:517
bool equivalent(const Matrix< 3, 4, T > &lhs, const Matrix< 3, 4, T > &rhs, U margin)
Equivalence test within the given tolerance margin.
Definition: Matrix3x4.h:171
String & cat(const char *operand)
Append the current String with the given text.
Definition: String.cc:545
U32 height(const Matrix< M, N, T > &matrix)
Return the vertical dimension.
Definition: Matrix.h:158
Matrix< M, N, T > operator+(const Matrix< M, N, T > &lhs, const Matrix< M, N, U > &rhs)
Matrix Matrix add.
Definition: Matrix.h:493
Automatically reference-counted string container.
Definition: String.h:128
U32 width(const Matrix< M, N, T > &matrix)
Return the horizonatal dimension.
Definition: Matrix.h:149
Matrix< M, N, T > operator-(const Matrix< M, N, T > &lhs, const Matrix< M, N, U > &rhs)
Matrix Matrix subtract.
Definition: Matrix.h:505
String & catf(const char *fmt,...)
Populate the string as with sPrintf(), but by concatenating the results to the existing string...
Definition: String.cc:554
Matrix< M, N, T > & add(Matrix< M, N, T > &R, const Matrix< M, N, T > &A, const Matrix< M, N, U > &B)
Matrix Matrix add.
Definition: Matrix.h:253
Matrix< M, N, T > & setIdentity(Matrix< M, N, T > &matrix)
Set matrix to identity matrix.
Definition: Matrix.h:176
void copy(Matrix< M, N, T > &lhs, const Matrix< I, J, U > &rhs)
Matrix copy.
Definition: Matrix.h:410
Matrix< M, N, T > & operator*=(Matrix< M, N, T > &lhs, const U rhs)
Matrix Scale.
Definition: Matrix.h:558
Matrix< M, N, T > & multiply(Matrix< M, N, T > &R, const Matrix< M, L, T > &A, const Matrix< L, N, U > &B)
Matrix Matrix multiply.
Definition: Matrix.h:287
Four-dimensional complex number.
Definition: Quaternion.h:32