21 #include <Shoemake/Decompose.h> 
   22 #include <Shoemake/EulerAngles.h> 
   60                                  T M1, T M5, T M9,  T M13,
 
   61                                  T M2, T M6, T M10, T M14,
 
   62                                  T M3, T M7, T M11, T M15);
 
   84                                  T M1, T M5, T M9 , T M13,
 
   85                                  T M2, T M6, T M10, T M14,
 
   86                                  T M3, T M7, T M11, T M15); 
 
   90         void        setMatrix   (
const int16_t i, 
const SLfloat value) { assert(i >= 0 && i < 16); 
_m[i] = value; }
 
   93         void        m           (
int i, T val) {assert(i>=0 && i<16); 
_m[i] = val;}
 
   96   const T*          
m           ()
 const        {
return _m;}
 
   97         T           
m           (
int i)
 const   {assert(i>=0 && i<16); 
return _m[i];}
 
  126                                  T axisx, T axisy, T axisz);
 
  146         void        ortho       (T l, T r, T b, T t, T n, T f);
 
  149         void        viewport    (T x, T y, T ww, T wh, T n=0.0f, T f=1.0f);
 
  153                                  T AtX=0, T AtY=0, T AtZ=0,
 
  154                                  T UpX=0, T UpY=0, T UpZ=0);
 
  169                                  T AtX=0, T AtY=0, T AtZ=0,
 
  170                                  T UpX=0, T UpY=0, T UpZ=0);
 
  177                                  T dirAtX=0, T dirAtY=0, T dirAtZ=0,
 
  178                                  T dirUpX=0, T dirUpY=0, T dirUpZ=0);
 
  198                                   SLbool keepTranslation=
true);
 
  200                                   T axisx, T axisy, T axisz,
 
  201                                   SLbool keepTranslation=
true);
 
  214                                         bool keepTranslation=
true);
 
  218                                         bool keepTranslation=
true);
 
  252   static void        swap        (T& a, T& b) {T t; t=a;a=b;b=t;}
 
  278                   T M1, T M5, T M9,  T M13,
 
  279                   T M2, T M6, T M10, T M14,
 
  280                   T M3, T M7, T M11, T M15)
 
  282     setMatrix(M0, M4, M8, M12,
 
  297     translation(tx, ty, tz, 
false);
 
  303     translation(translationVec.
x, translationVec.
y, translationVec.
z, 
false);
 
  309     rotation(degAng, ax, ay, az, 
false);
 
  321     rotation(fromUnitVec, toUnitVec);
 
  329     setMatrix(translation, rotation, scale);
 
  337     for (
int i=0; i<16; ++i) _m[i] = A.
_m[i];
 
  343     _m[0]=A.
_m[0]; _m[4]=A.
_m[3]; _m[ 8]=A.
_m[6];  _m[12]=0;
 
  344     _m[1]=A.
_m[1]; _m[5]=A.
_m[4]; _m[ 9]=A.
_m[7];  _m[13]=0;
 
  345     _m[2]=A.
_m[2]; _m[6]=A.
_m[5]; _m[10]=A.
_m[8];  _m[14]=0;
 
  346     _m[3]=0;       _m[7]=0;       _m[11]=0;        _m[15]=1;
 
  352     for (
int i=0; i<16; ++i) _m[i] = A->
_m[i];
 
  358     for (
int i=0; i<16; ++i) _m[i] = M[i];
 
  363                           T M1, T M5, T M9 , T M13,
 
  364                           T M2, T M6, T M10, T M14,
 
  365                           T M3, T M7, T M11, T M15)
 
  367     _m[0]=M0; _m[4]=M4; _m[ 8]=M8;  _m[12]=M12;
 
  368     _m[1]=M1; _m[5]=M5; _m[ 9]=M9;  _m[13]=M13;
 
  369     _m[2]=M2; _m[6]=M6; _m[10]=M10; _m[14]=M14;
 
  370     _m[3]=M3; _m[7]=M7; _m[11]=M11; _m[15]=M15;
 
  378     setMatrix(scale.
x * rotation[0], scale.
y * rotation[3], scale.
z * rotation[6], translation.
x,
 
  379               scale.
x * rotation[1], scale.
y * rotation[4], scale.
z * rotation[7], translation.
y,
 
  380               scale.
x * rotation[2], scale.
y * rotation[5], scale.
z * rotation[8], translation.
z,
 
  387     _m[0]=rotation[0]; _m[4]=rotation[3]; _m[8]=rotation[6];
 
  388     _m[1]=rotation[1]; _m[5]=rotation[4]; _m[9]=rotation[7];
 
  389     _m[2]=rotation[2]; _m[6]=rotation[5]; _m[10]=rotation[8];
 
  395     _m[12]=translation.
x;
 
  396     _m[13]=translation.
y;
 
  397     _m[14]=translation.
z;
 
  408     _m[0]=A.
_m[0]; _m[4]=A.
_m[4]; _m[ 8]=A.
_m[ 8]; _m[12]=A.
_m[12];
 
  409     _m[1]=A.
_m[1]; _m[5]=A.
_m[5]; _m[ 9]=A.
_m[ 9]; _m[13]=A.
_m[13];
 
  410     _m[2]=A.
_m[2]; _m[6]=A.
_m[6]; _m[10]=A.
_m[10]; _m[14]=A.
_m[14];
 
  411     _m[3]=A.
_m[3]; _m[7]=A.
_m[7]; _m[11]=A.
_m[11]; _m[15]=A.
_m[15];
 
  454     T W = 1 / (_m[3]*v.
x + _m[7]*v.
y + _m[11]*v.
z + _m[15]);
 
  455     return SLVec3<T>((_m[0]*v.
x + _m[4]*v.
y + _m[ 8]*v.
z + _m[12]) * W,
 
  456                      (_m[1]*v.
x + _m[5]*v.
y + _m[ 9]*v.
z + _m[13]) * W,
 
  457                      (_m[2]*v.
x + _m[6]*v.
y + _m[10]*v.
z + _m[14]) * W);
 
  466     return SLVec4<T>(_m[0]*v.
x + _m[4]*v.
y + _m[ 8]*v.
z + _m[12]*v.
w,
 
  467                      _m[1]*v.
x + _m[5]*v.
y + _m[ 9]*v.
z + _m[13]*v.
w,
 
  468                      _m[2]*v.
x + _m[6]*v.
y + _m[10]*v.
z + _m[14]*v.
w,
 
  469                      _m[3]*v.
x + _m[7]*v.
y + _m[11]*v.
z + _m[15]*v.
w);
 
  478     return SLMat4<T>(_m[ 0]*a, _m[ 1]*a, _m[ 2]*a, _m[ 3]*a, 
 
  479                      _m[ 4]*a, _m[ 5]*a, _m[ 6]*a, _m[ 7]*a,
 
  480                      _m[ 8]*a, _m[ 9]*a, _m[10]*a, _m[11]*a, 
 
  481                      _m[12]*a, _m[13]*a, _m[14]*a, _m[15]*a);
 
  490     for (
auto & i : _m) i *= a;
 
  501     SLMat4<T> newM(_m[ 0]*invA, _m[ 1]*invA, _m[ 2]*invA, _m[ 3]*invA, 
 
  502                    _m[ 4]*invA, _m[ 5]*invA, _m[ 6]*invA, _m[ 7]*invA,
 
  503                    _m[ 8]*invA, _m[ 9]*invA, _m[10]*invA, _m[11]*invA, 
 
  504                    _m[12]*invA, _m[13]*invA, _m[14]*invA, _m[15]*invA);
 
  515     for (
auto & i : _m) i *= invA;
 
  523     for (
SLuint i = 0; i < 16; ++i)
 
  538     setMatrix(_m[0]*A.
_m[ 0] + _m[4]*A.
_m[ 1] + _m[8] *A.
_m[ 2] + _m[12]*A.
_m[ 3], 
 
  539               _m[0]*A.
_m[ 4] + _m[4]*A.
_m[ 5] + _m[8] *A.
_m[ 6] + _m[12]*A.
_m[ 7],
 
  540               _m[0]*A.
_m[ 8] + _m[4]*A.
_m[ 9] + _m[8] *A.
_m[10] + _m[12]*A.
_m[11],
 
  541               _m[0]*A.
_m[12] + _m[4]*A.
_m[13] + _m[8] *A.
_m[14] + _m[12]*A.
_m[15],
 
  542               _m[1]*A.
_m[ 0] + _m[5]*A.
_m[ 1] + _m[9] *A.
_m[ 2] + _m[13]*A.
_m[ 3], 
 
  543               _m[1]*A.
_m[ 4] + _m[5]*A.
_m[ 5] + _m[9] *A.
_m[ 6] + _m[13]*A.
_m[ 7],
 
  544               _m[1]*A.
_m[ 8] + _m[5]*A.
_m[ 9] + _m[9] *A.
_m[10] + _m[13]*A.
_m[11],
 
  545               _m[1]*A.
_m[12] + _m[5]*A.
_m[13] + _m[9] *A.
_m[14] + _m[13]*A.
_m[15],
 
  546               _m[2]*A.
_m[ 0] + _m[6]*A.
_m[ 1] + _m[10]*A.
_m[ 2] + _m[14]*A.
_m[ 3], 
 
  547               _m[2]*A.
_m[ 4] + _m[6]*A.
_m[ 5] + _m[10]*A.
_m[ 6] + _m[14]*A.
_m[ 7],
 
  548               _m[2]*A.
_m[ 8] + _m[6]*A.
_m[ 9] + _m[10]*A.
_m[10] + _m[14]*A.
_m[11],
 
  549               _m[2]*A.
_m[12] + _m[6]*A.
_m[13] + _m[10]*A.
_m[14] + _m[14]*A.
_m[15],
 
  550               _m[3]*A.
_m[ 0] + _m[7]*A.
_m[ 1] + _m[11]*A.
_m[ 2] + _m[15]*A.
_m[ 3], 
 
  551               _m[3]*A.
_m[ 4] + _m[7]*A.
_m[ 5] + _m[11]*A.
_m[ 6] + _m[15]*A.
_m[ 7],
 
  552               _m[3]*A.
_m[ 8] + _m[7]*A.
_m[ 9] + _m[11]*A.
_m[10] + _m[15]*A.
_m[11],
 
  553               _m[3]*A.
_m[12] + _m[7]*A.
_m[13] + _m[11]*A.
_m[14] + _m[15]*A.
_m[15]);
 
  568     for (
SLint i = 0; i < 16; ++i)
 
  569         _m[i] = _m[i] + A.
_m[i];
 
  578     T W = 1 / (_m[3]*v.
x + _m[7]*v.
y + _m[11]*v.
z + _m[15]);
 
  579     return SLVec3<T>((_m[0]*v.
x + _m[4]*v.
y + _m[ 8]*v.
z + _m[12]) * W,
 
  580                      (_m[1]*v.
x + _m[5]*v.
y + _m[ 9]*v.
z + _m[13]) * W,
 
  581                      (_m[2]*v.
x + _m[6]*v.
y + _m[10]*v.
z + _m[14]) * W);
 
  590     return SLVec4<T>(_m[0]*v.
x + _m[4]*v.
y + _m[ 8]*v.
z + _m[12]*v.
w,
 
  591                      _m[1]*v.
x + _m[5]*v.
y + _m[ 9]*v.
z + _m[13]*v.
w,
 
  592                      _m[2]*v.
x + _m[6]*v.
y + _m[10]*v.
z + _m[14]*v.
w,
 
  593                      _m[3]*v.
x + _m[7]*v.
y + _m[11]*v.
z + _m[15]*v.
w);
 
  658     SLMat4<T> R(degAng, axisx, axisy, axisz);
 
  709                         const T  AtX, 
const T  AtY, 
const T  AtZ,
 
  710                         const T  UpX, 
const T  UpY, 
const T  UpZ)
 
  749     setMatrix(VX.
x, VX.
y, VX.
z, VX*VT,
 
  750               VY.
x, VY.
y, VY.
z, VY*VT,
 
  751               VZ.
x, VZ.
y, VZ.
z, VZ*VT,
 
  769     ri->
set( _m[0], _m[4], _m[8]);            
 
  770     up->
set( _m[1], _m[5], _m[9]);            
 
  771     at->
set(-_m[2],-_m[6],-_m[10]);           
 
  779                         const T  AtX, 
const T  AtY, 
const T  AtZ,
 
  780                         const T  UpX, 
const T  UpY, 
const T  UpZ)
 
  814     setMatrix(VX.
x, VY.
x, VZ.
x, pos.
x,
 
  815               VX.
y, VY.
y, VZ.
y, pos.
y,
 
  816               VX.
z, VY.
z, VZ.
z, pos.
z,
 
  823                         const T dirAtX, 
const T dirAtY, 
const T dirAtZ,
 
  824                         const T dirUpX, 
const T dirUpY, 
const T dirUpZ)
 
  838     lightAt(pos, dirAt, dirUp);
 
  856                         const T n, 
const T f)
 
  858     _m[0]=2*n/(r-l); _m[4]=0;         _m[8] = (r+l)/(r-l); _m[12]=0;
 
  859     _m[1]=0;         _m[5]=2*n/(t-b); _m[9] = (t+b)/(t-b); _m[13]=0;
 
  860     _m[2]=0;         _m[6]=0;         _m[10]=-(f+n)/(f-n); _m[14]=-2*f*n/(f-n);
 
  861     _m[3]=0;         _m[7]=0;         _m[11]=-1;           _m[15]=0;
 
  875                             const T n, 
const T f)
 
  877    T t = (T)tan(fov * 
DEG2RAD * 0.5)*n;
 
  881    frustum(l,r,b,t,n,f);
 
  892     const T cx, 
const T cy, 
const T n, 
const T f)
 
  894     _m[0]=fx/cx; _m[4]=0;     _m[8] = 0;           _m[12]=0;
 
  895     _m[1]=0;     _m[5]=fy/cy; _m[9] = 0;           _m[13]=0;
 
  896     _m[2]=0;     _m[6]=0;     _m[10]=-(f+n)/(f-n); _m[14]=(-2*f*n)/(f-n);
 
  897     _m[3]=0;     _m[7]=0;     _m[11]=-1;           _m[15]=0;
 
  912                       const T n, 
const T f)
 
  914     _m[0]=2/(r-l); _m[4]=0;       _m[8]=0;         _m[12]=-(r+l)/(r-l);
 
  915     _m[1]=0;       _m[5]=2/(t-b); _m[9]=0;         _m[13]=-(t+b)/(t-b);
 
  916     _m[2]=0;       _m[6]=0;       _m[10]=-2/(f-n); _m[14]=-(f+n)/(f-n);
 
  917     _m[3]=0;       _m[7]=0;       _m[11]=0;        _m[15]=1;
 
  931                          const T n, 
const T f)
 
  937     _m[0]=ww2; _m[4]=0;    _m[8] =0;          _m[12]=x+ww2;
 
  938     _m[1]=0;   _m[5]=-wh2; _m[9] =0;          _m[13]=y+wh2;
 
  939     _m[2]=0;   _m[6]=0;    _m[10]=(f-n)*0.5f; _m[14]=(f+n)*0.5f;
 
  940     _m[3]=0;   _m[7]=0;    _m[11]=0;          _m[15]=1;
 
  950     translation(t.
x, t.
y, t.
z, keepLinear);
 
  966     {   _m[0]=1; _m[4]=0;  _m[8]=0;
 
  967         _m[1]=0; _m[5]=1;  _m[9]=0;  
 
  968         _m[2]=0; _m[6]=0;  _m[10]=1; 
 
  969         _m[3]=0; _m[7]=0;  _m[11]=0; _m[15]=1;
 
  981     rotation(degAng, axis.
x, axis.
y, axis.
z, keepTrans);
 
  990                          const T axisx, 
const T axisy, 
const T axisz,
 
  993     T RadAng = (T)degAng * 
DEG2RAD;
 
  994     T ca=(T)cos(RadAng), sa=(T)sin(RadAng);
 
  995     if (axisx==1 && axisy==0 && axisz==0)              
 
  996     {   _m[0]=1; _m[4]=0;  _m[8]=0;   
 
  997         _m[1]=0; _m[5]=ca; _m[9]=-sa; 
 
  998         _m[2]=0; _m[6]=sa; _m[10]=ca; 
 
 1000     if (axisx==0 && axisy==1 && axisz==0)              
 
 1001     {   _m[0]=ca;  _m[4]=0; _m[8]=sa; 
 
 1002         _m[1]=0;   _m[5]=1; _m[9]=0;  
 
 1003         _m[2]=-sa; _m[6]=0; _m[10]=ca;
 
 1005     if (axisx==0 && axisy==0 && axisz==1)              
 
 1006     {   _m[0]=ca; _m[4]=-sa; _m[8]=0; 
 
 1007         _m[1]=sa; _m[5]=ca;  _m[9]=0; 
 
 1008         _m[2]=0;  _m[6]=0;   _m[10]=1;
 
 1010     {   T l = axisx*axisx + axisy*axisy + axisz*axisz;  
 
 1012         x=axisx, y=axisy, z=axisz;
 
 1013         if ((l > T(1.0001) || l < T(0.9999)) && l!=0)
 
 1017         T xy=x*y, yz=y*z, xz=x*z, xx=x*x, yy=y*y, zz=z*z;
 
 1018         _m[0]=xx + ca*(1-xx);     _m[4]=xy - xy*ca - z*sa;  _m[8] =xz - xz*ca + y*sa;
 
 1019         _m[1]=xy - xy*ca + z*sa;  _m[5]=yy + ca*(1-yy);     _m[9] =yz - yz*ca - x*sa;
 
 1020         _m[2]=xz - xz*ca - y*sa;  _m[6]=yz - yz*ca + x*sa;  _m[10]=zz + ca*(1-zz);
 
 1022     _m[3]=_m[7]=_m[11]=0; _m[15]=1;
 
 1025         _m[12] = _m[13] = _m[14] = 0;
 
 1042     T cosAngle = from.
dot(to);
 
 1044     if (fabs(cosAngle-1.0) <= FLT_EPSILON) 
 
 1053     else if (fabs(cosAngle+1.0) <= FLT_EPSILON) 
 
 1073         if (fabs(side.
dot(side)) <= FLT_EPSILON)
 
 1082         up.
cross(side, from);
 
 1085         _m[ 0] = -(from.
x * from.
x) + (up.
x * up.
x) - (side.
x * side.
x);
 
 1086         _m[ 4] = -(from.
x * from.
y) + (up.
x * up.
y) - (side.
x * side.
y);
 
 1087         _m[ 8] = -(from.
x * from.
z) + (up.
x * up.
z) - (side.
x * side.
z);
 
 1089         _m[ 1] = -(from.
x * from.
y) + (up.
x * up.
y) - (side.
x * side.
y);
 
 1090         _m[ 5] = -(from.
y * from.
y) + (up.
y * up.
y) - (side.
y * side.
y);
 
 1091         _m[ 9] = -(from.
y * from.
z) + (up.
y * up.
z) - (side.
y * side.
z);
 
 1093         _m[ 2] = -(from.
x * from.
z) + (up.
x * up.
z) - (side.
x * side.
z);
 
 1094         _m[ 6] = -(from.
y * from.
z) + (up.
y * up.
z) - (side.
y * side.
z);
 
 1095         _m[10] = -(from.
z * from.
z) + (up.
z * up.
z) - (side.
z * side.
z);
 
 1120         T h = (1.f - cosAngle) / v.
dot(v);
 
 1122         _m[ 0] = cosAngle + h * v.
x * v.
x;
 
 1123         _m[ 4] = h * v.
x * v.
y - v.
z;
 
 1124         _m[ 8] = h * v.
x * v.
z + v.
y;
 
 1126         _m[ 1] = h * v.
x * v.
y + v.
z;
 
 1127         _m[ 5] = cosAngle + h * v.
y * v.
y;
 
 1128         _m[ 9] = h * v.
y * v.
z - v.
x;
 
 1130         _m[ 2] = h * v.
x * v.
z - v.
y;
 
 1131         _m[ 6] = h * v.
y * v.
z + v.
x;
 
 1132         _m[10] = cosAngle + h * v.
z * v.
z;
 
 1149     scaling(sxyz, sxyz, sxyz);
 
 1160     scaling(scale.
x, scale.
y, scale.
z);
 
 1171     _m[0]=sx; _m[4]=0;  _m[8]=0;   
 
 1172     _m[1]=0;  _m[5]=sy; _m[9]=0; 
 
 1173     _m[2]=0;  _m[6]=0;  _m[10]=sz;
 
 1174     _m[3]=0;  _m[7]=0;  _m[11]=0; _m[15]=1;
 
 1177         _m[12] = _m[13] = _m[14] = 0;
 
 1188                                    const double angle2RAD,
 
 1189                                    const double angle3RAD,
 
 1192     double s1 = sin(angle1RAD), c1 = cos(angle1RAD);
 
 1193     double s2 = sin(angle2RAD), c2 = cos(angle2RAD);
 
 1194     double s3 = sin(angle3RAD), c3 = cos(angle3RAD);
 
 1196     _m[0]=(T)( c1*c3 - s1*c2*s3); _m[4]=(T)( s1*c3 + c1*c2*s3);  _m[8] =(T)( s2*s3);
 
 1197     _m[1]=(T)(-c1*s3 - s1*c2*c3); _m[5]=(T)( c1*c2*c3 - s1*s3);  _m[9] =(T)( s2*c3);
 
 1198     _m[2]=(T)( s1*s2);            _m[6]=(T)(-c1*s2);             _m[10]=(T)( c2);
 
 1200     _m[3]=_m[7]=_m[11]=0; _m[15]=1;
 
 1203     {  _m[12] = _m[13] = _m[14] = 0;
 
 1215                                    const double angle2RAD,
 
 1216                                    const double angle3RAD,
 
 1219     double s1 = sin(angle1RAD), c1 = cos(angle1RAD);
 
 1220     double s2 = sin(angle2RAD), c2 = cos(angle2RAD);
 
 1221     double s3 = sin(angle3RAD), c3 = cos(angle3RAD);
 
 1223     _m[0]=(T) (c2*c3);              _m[4]=(T)-(c2*s3);              _m[8] =(T) s2;
 
 1224     _m[1]=(T) (s1*s2*c3) + (c1*s3); _m[5]=(T)-(s1*s2*s3) + (c1*c3); _m[9] =(T)-(s1*c2);
 
 1225     _m[2]=(T)-(c1*s2*c3) + (s1*s3); _m[6]=(T) (c1*s2*s3) + (s1*c3); _m[10]=(T) (c1*c2);
 
 1227     _m[3]=_m[7]=_m[11]=0; _m[15]=1;
 
 1230     {  _m[12] = _m[13] = _m[14] = 0;
 
 1248     Cy = (T)sqrt(1.0 - Sy*Sy);
 
 1253         T factor = (T)(1.0 / Cy);
 
 1267     zRotRAD = atan2f(Sz, Cz);
 
 1268     yRotRAD = atan2f(Sy, Cy);
 
 1269     xRotRAD = atan2f(Sx, Cx);
 
 1285     Cy = (T)sqrt(1.0 - Sy*Sy);
 
 1290         T factor = (T)(1.0 / Cy);
 
 1291         Sx = -_m[ 9]*factor;
 
 1293         Sz = -_m[ 4]*factor;
 
 1304     zRotRAD = atan2f(Sz, Cz);
 
 1305     yRotRAD = atan2f(Sy, Cy);
 
 1306     xRotRAD = atan2f(Sx, Cx);
 
 1313     A[0][0]=_m[0]; A[0][1]=_m[4]; A[0][2]=_m[ 8]; A[0][3]=_m[12];
 
 1314     A[1][0]=_m[1]; A[1][1]=_m[5]; A[1][2]=_m[ 9]; A[1][3]=_m[13];
 
 1315     A[2][0]=_m[2]; A[2][1]=_m[6]; A[2][2]=_m[10]; A[2][3]=_m[14];
 
 1316     A[3][0]=_m[3]; A[3][1]=_m[7]; A[3][2]=_m[11]; A[3][3]=_m[15];
 
 1318     EulerAngles eulerAngles = Eul_FromHMatrix(A, order);
 
 1321     angles.
x = eulerAngles.x;
 
 1322     angles.
y = eulerAngles.y;
 
 1323     angles.
z = eulerAngles.z;
 
 1335     _m[0]=_m[5]=_m[10]=_m[15]=1;
 
 1336     _m[1]=_m[2]=_m[3]=_m[4]=_m[6]=_m[7]=_m[8]=_m[9]=_m[11]=_m[12]=_m[13]=_m[14]=0;
 
 1343     swap(_m[1], _m[ 4]);
 
 1344     swap(_m[2], _m[ 8]);
 
 1345     swap(_m[6], _m[ 9]);
 
 1346     swap(_m[3], _m[12]);
 
 1347     swap(_m[7], _m[13]);
 
 1348     swap(_m[11],_m[14]);
 
 1355     SLMat4<T> t( _m[0], _m[1], _m[2], _m[3],
 
 1356                  _m[4], _m[5], _m[6], _m[7],
 
 1357                  _m[8], _m[9],_m[10],_m[11],
 
 1358                 _m[12],_m[13],_m[14],_m[15]);
 
 1366     setMatrix(inverted());
 
 1376     T det, d12, d13, d23, d24, d34, d41;
 
 1381     d12 = ( _m[2]*_m[ 7] - _m[ 3]*_m[ 6]);
 
 1382     d13 = ( _m[2]*_m[11] - _m[ 3]*_m[10]);
 
 1383     d23 = ( _m[6]*_m[11] - _m[ 7]*_m[10]);
 
 1384     d24 = ( _m[6]*_m[15] - _m[ 7]*_m[14]);
 
 1385     d34 = (_m[10]*_m[15] - _m[11]*_m[14]);
 
 1386     d41 = (_m[14]*_m[ 3] - _m[15]*_m[ 2]);
 
 1388     i.
_m[0] =  (_m[5]*d34 - _m[9]*d24 + _m[13]*d23);
 
 1389     i.
_m[1] = -(_m[1]*d34 + _m[9]*d41 + _m[13]*d13);
 
 1390     i.
_m[2] =  (_m[1]*d24 + _m[5]*d41 + _m[13]*d12);
 
 1391     i.
_m[3] = -(_m[1]*d23 - _m[5]*d13 + _m[ 9]*d12);
 
 1394     det = _m[0]*i.
_m[0] + _m[4]*i.
_m[1] + _m[8]*i.
_m[2] + _m[12]*i.
_m[3];
 
 1397     if (fabs(det) < FLT_EPSILON) 
 
 1399         SL_LOG(
"4x4-Matrix is singular. Inversion impossible.");
 
 1411         i.
_m[4] = -(_m[4]*d34 - _m[8]*d24 + _m[12]*d23)*invDet;
 
 1412         i.
_m[5] =  (_m[0]*d34 + _m[8]*d41 + _m[12]*d13)*invDet;
 
 1413         i.
_m[6] = -(_m[0]*d24 + _m[4]*d41 + _m[12]*d12)*invDet;
 
 1414         i.
_m[7] =  (_m[0]*d23 - _m[4]*d13 +  _m[8]*d12)*invDet;
 
 1418         d12 = _m[ 0]*_m[ 5] - _m[ 1]*_m[ 4];
 
 1419         d13 = _m[ 0]*_m[ 9] - _m[ 1]*_m[ 8];
 
 1420         d23 = _m[ 4]*_m[ 9] - _m[ 5]*_m[ 8];
 
 1421         d24 = _m[ 4]*_m[13] - _m[ 5]*_m[12];
 
 1422         d34 = _m[ 8]*_m[13] - _m[ 9]*_m[12];
 
 1423         d41 = _m[12]*_m[ 1] - _m[13]*_m[ 0];
 
 1425         i.
_m[ 8] =  (_m[7]*d34 - _m[11]*d24 + _m[15]*d23)*invDet;
 
 1426         i.
_m[ 9] = -(_m[3]*d34 + _m[11]*d41 + _m[15]*d13)*invDet;
 
 1427         i.
_m[10] =  (_m[3]*d24 + _m[ 7]*d41 + _m[15]*d12)*invDet;
 
 1428         i.
_m[11] = -(_m[3]*d23 - _m[ 7]*d13 + _m[11]*d12)*invDet;
 
 1429         i.
_m[12] = -(_m[6]*d34 - _m[10]*d24 + _m[14]*d23)*invDet;
 
 1430         i.
_m[13] =  (_m[2]*d34 + _m[10]*d41 + _m[14]*d13)*invDet;
 
 1431         i.
_m[14] = -(_m[2]*d24 + _m[ 6]*d41 + _m[14]*d12)*invDet;
 
 1432         i.
_m[15] =  (_m[2]*d23 - _m[ 6]*d13 + _m[10]*d12)*invDet;
 
 1444                 _m[1], _m[5], _m[9],
 
 1445                 _m[2], _m[6], _m[10]);
 
 1457     return _m[0] + _m[5] + _m[10] + _m[15];
 
 1472     fromEulerAnglesXYZ(rotEulerRAD.
x, rotEulerRAD.
y, rotEulerRAD.
z);
 
 1473     scale(scaleFactors);
 
 1487     A[0][0]=_m[0]; A[0][1]=_m[4]; A[0][2]=_m[ 8]; A[0][3]=_m[12]; 
 
 1488     A[1][0]=_m[1]; A[1][1]=_m[5]; A[1][2]=_m[ 9]; A[1][3]=_m[13]; 
 
 1489     A[2][0]=_m[2]; A[2][1]=_m[6]; A[2][2]=_m[10]; A[2][3]=_m[14]; 
 
 1490     A[3][0]=_m[3]; A[3][1]=_m[7]; A[3][2]=_m[11]; A[3][3]=_m[15]; 
 
 1493     decomp_affine(A, &parts);
 
 1495     trans.
set(parts.t.x, parts.t.y, parts.t.z);
 
 1496     scale.
set(parts.k.x, parts.k.y, parts.k.z);
 
 1497     rotQuat.
set(parts.q.x, parts.q.y, parts.q.z, parts.q.w);
 
 1509     decompose(trans, rotQuat, scale);
 
 1525     rotMat.
setMatrix(1.0f-(yy2 + zz2),       xy2 - wz2 ,       xz2 + wy2,
 
 1526                             xy2 + wz2 , 1.0f-(xx2 + zz2),       yz2 - wx2,
 
 1527                             xz2 - wy2 ,       yz2 + wx2 , 1.0f-(xx2 + yy2));
 
 1539     decompose(trans, rotMat, scale);
 
 1541     SLfloat rotAngleXRAD, rotAngleYRAD, rotAngleZRAD;
 
 1544     rotEulerRAD.
set(rotAngleXRAD, rotAngleYRAD, rotAngleZRAD);
 
 1556     if (str) 
SL_LOG(
"%s",str);
 
 1557     SL_LOG(
"% 3.2f % 3.2f % 3.2f % 3.2f",  _m[0],_m[4],_m[ 8],_m[12]);
 
 1558     SL_LOG(
"% 3.2f % 3.2f % 3.2f % 3.2f",  _m[1],_m[5],_m[ 9],_m[13]);
 
 1559     SL_LOG(
"% 3.2f % 3.2f % 3.2f % 3.2f",  _m[2],_m[6],_m[10],_m[14]);
 
 1560     SL_LOG(
"% 3.2f % 3.2f % 3.2f % 3.2f",  _m[3],_m[7],_m[11],_m[15]);
 
 1572             "% 3.3f % 3.3f % 3.3f % 3.3f\n% 3.3f % 3.3f % 3.3f % 3.3f\n% 3.3f % 3.3f % 3.3f % 3.3f\n% 3.3f % 3.3f % 3.3f % 3.3f",
 
 1573             _m[0],_m[4],_m[ 8],_m[12],
 
 1574             _m[1],_m[5],_m[ 9],_m[13],
 
 1575             _m[2],_m[6],_m[10],_m[14],
 
 1576             _m[3],_m[7],_m[11],_m[15]);
 
 1582 #ifdef SL_HAS_DOUBLE 
std::stack< SLMat4f > SLSMat4f
 
SLMat4< SLfloat > SLMat4f
 
vector< SLMat4f > SLVMat4f
 
void transpose()
Transposes the matrix.
 
void setMatrix(const SLMat3 &A)
 
void invert()
Inverts the matrix.
 
void toEulerAnglesXYZ(T &xRotRAD, T &yRotRAD, T &zRotRAD)
 
4x4 matrix template class
 
SLbool isEqual(const SLMat4 &A, SLfloat epsilon=0.01f)
Returns true if one element of the matrix differs more than epsilon.
 
void print(const SLchar *str=nullptr) const
 
void setMatrix(const SLMat3f &A)
Set matrix by other 3x3 matrix.
 
void scale(const SLVec3< T > &sxyz)
 
SLMat4< T > operator/(T a) const
scalar division
 
void transpose()
Sets the transposed matrix by swaping around the main diagonal.
 
SLMat4< T > operator*(const SLMat4 &A) const
matrix-matrix multiplication
 
SLVec3< T > translation() const
 
void lookAt(SLVec3< T > *eye, SLVec3< T > *at, SLVec3< T > *up, SLVec3< T > *right) const
Reads out of the matrix the look at parameters.
 
void lookAt(T EyeX, T EyeY, T EyeZ, T AtX=0, T AtY=0, T AtZ=0, T UpX=0, T UpY=0, T UpZ=0)
Defines the a view matrix as the corresponding gluLookAt function.
 
void posAtUp(T PosX, T PosY, T PosZ, T dirAtX=0, T dirAtY=0, T dirAtZ=0, T dirUpX=0, T dirUpY=0, T dirUpZ=0)
Same as lightAt.
 
SLMat4(T tx, T ty, T tz)
Sets translate matrix.
 
void translate(const SLVec2< T > &t)
 
void setTranslation(const SLVec3< T > &translation)
Set vector as submatrix describing the translational part.
 
void setRotation(const SLMat3< T > &rotation)
Set 3x3 submatrix describing the rotational part.
 
void toEulerAnglesZYX(T &zRotRAD, T &yRotRAD, T &xRotRAD)
 
SLMat4< T > operator+(const SLMat4 &A) const
matrix-matrix addition
 
void perspectiveCenteredPP(T w, T h, T fx, T fy, T cx, T cy, T n, T f)
Defines a projection matrix for a calibrated camera, the principle point has to be centered (from int...
 
SLMat4< T > & operator/=(T a)
scalar division
 
SLMat4(T scale_xyz)
Sets scaling matrix.
 
void setMatrix(const SLMat4 &A)
Set matrix by other 4x4 matrix.
 
SLVec3< T > axisX() const
 
void add(const SLMat4 &A)
 
void translation(T tx, T ty, T tz, SLbool keepLinear=true)
Sets the translation with or without overwriting the linear submatrix.
 
void setMatrix(const SLVec3< T > &translation, const SLMat3< T > &rotation, const SLVec3< T > &scale)
Set matrix by translation, rotation & scale.
 
void scaling(const SLVec3< T > &sxyz, SLbool keepTrans=true)
 
SLMat4< T > & operator=(const SLMat4 &A)
assignment operator
 
T _m[16]
The 16 elements of the matrix.
 
SLVec3< T > toEulerAngles(int order)
 
void scaling(T sx, T sy, T sz, SLbool keepTranslation=true)
 
SLMat4< T > & operator*=(const SLMat4 &A)
matrix-matrix multiplication
 
SLMat4< T > transposed()
Returns the transposed of the matrix and leaves the itself unchanged.
 
void setMatrix(T M0, T M4, T M8, T M12, T M1, T M5, T M9, T M13, T M2, T M6, T M10, T M14, T M3, T M7, T M11, T M15)
Set matrix by components.
 
SLVec4< T > multVec(SLVec4< T > v) const
 
void ortho(T l, T r, T b, T t, T n, T f)
Defines a orthographic projection matrix with a field of view angle.
 
SLMat4(const SLVec3< T > &translationVec)
Sets translate matrix.
 
void rotation(T degAng, const SLVec3< T > &axis, SLbool keepTranslation=true)
Sets the rotation with or without overwriting the translation.
 
SLVec3< T > axisY() const
 
void translation(const SLVec3< T > &t, SLbool keepLinear=true)
 
void invert()
Inverts the matrix.
 
void decompose(SLVec3f &trans, SLMat3f &rotMat, SLVec3f &scale)
 
void decompose(SLVec3f &trans, SLVec4f &rotQuat, SLVec3f &scale)
 
SLMat4(const SLVec3< T > &fromUnitVec, const SLVec3< T > &toUnitVec)
Sets rotation matrix.
 
void rotation(T degAng, T axisx, T axisy, T axisz, SLbool keepTranslation=true)
 
void rotate(T degAng, T axisx, T axisy, T axisz)
 
void compose(SLVec3f trans, SLVec3f rotEulerRAD, SLVec3f scale)
 
void lookAt(const SLVec3< T > &Eye, const SLVec3< T > &At=SLVec3< T >::ZERO, const SLVec3< T > &Up=SLVec3< T >::ZERO)
Defines the a view matrix as the corresponding gluLookAt function.
 
void rotate(T degAng, const SLVec3< T > &axis)
 
SLMat4()
Sets identity matrix.
 
void setMatrix(const SLMat4 *A)
Set matrix by other matrix pointer.
 
void multiply(const SLMat4 &A)
 
void scale(T sx, T sy, T sz)
 
SLstring toString() const
 
void lightAt(const SLVec3< T > &pos, const SLVec3< T > &At=SLVec3< T >::ZERO, const SLVec3< T > &Up=SLVec3< T >::ZERO)
Defines the a model matrix for light positioning.
 
void fromEulerAnglesXYZ(double angle1RAD, double angle2RAD, double angle3RAD, bool keepTranslation=true)
 
void fromEulerAnglesZXZ(double angle1RAD, double angle2RAD, double angle3RAD, bool keepTranslation=true)
 
SLVec3< T > multVec(SLVec3< T > v) const
 
SLMat4(const SLMat4 &A)
Sets mat by other SLMat4.
 
SLMat4< T > inverted() const
Computes the inverse of a 4x4 non-singular matrix.
 
SLVec3< T > axisZ() const
 
void perspective(T fov, T aspect, T n, T f)
Defines a perspective projection matrix with a field of view angle.
 
void identity()
Sets the identity matrix.
 
void rotation(const SLVec3< T > &fromUnitVec, const SLVec3< T > &toUnitVec)
 
static void swap(T &a, T &b)
 
SLMat4(T M0, T M4, T M8, T M12, T M1, T M5, T M9, T M13, T M2, T M6, T M10, T M14, T M3, T M7, T M11, T M15)
 
SLMat4(const SLMat3f &A)
Sets mat by other SLMat3.
 
void posAtUp(const SLVec3< T > &pos, const SLVec3< T > &dirAt=SLVec3< T >::ZERO, const SLVec3< T > &dirUp=SLVec3< T >::ZERO)
Same as lightAt.
 
SLMat4(const T *M)
Sets mat by array.
 
SLMat4(T degAng, T axis_x, T axis_y, T axis_z)
Sets rotation matrix.
 
void setMatrix(const int16_t i, const SLfloat value)
 
void translate(const SLVec3< T > &t)
 
void frustum(T l, T r, T b, T t, T n, T f)
Defines a view frustum projection matrix equivalent to glFrustum.
 
SLMat4(const SLVec3< T > &translation, const SLMat3< T > &rotation, const SLVec3< T > &scale)
Set matrix by translation, rotation & scale.
 
void scaling(T sxyz, SLbool keepTrans=true)
Sets the scaling with or without overwriting the translation.
 
void decompose(SLVec3f &trans, SLVec3f &rotEulerRAD, SLVec3f &scale)
 
void rotate(const SLVec3< T > &fromUnitVec, const SLVec3< T > &toUnitVec)
 
void lightAt(T PosX, T PosY, T PosZ, T AtX=0, T AtY=0, T AtZ=0, T UpX=0, T UpY=0, T UpZ=0)
Defines the a model matrix for light positioning.
 
SLMat3< T > inverseTransposed()
 
void setMatrix(const T *M)
Set matrix by float[16] array.
 
void toEulerAnglesXYZ(T &xRotRAD, T &yRotRAD, T &zRotRAD)
 
T & operator()(int row, int col)
 
void translate(T tx, T ty, T tz=0)
 
void viewport(T x, T y, T ww, T wh, T n=0.0f, T f=1.0f)
Defines the viewport matrix.
 
The SLScene class represents the top level instance holding the scene structure.
 
2D vector template class for standard 2D vector algebra.
 
3D vector template class for standard 3D vector algebra.
 
void cross(const SLVec3 &a, const SLVec3 &b)
 
void set(const T X, const T Y, const T Z)
 
T dot(const SLVec3 &v) const
 
4D vector template class for standard 4D vector algebra.
 
void set(const T X, const T Y, const T Z, const T W=1)
 
static const float DEG2RAD