|
@@ -70,7 +70,7 @@ namespace Framework
|
|
|
Mat4 getInverse()
|
|
|
{
|
|
|
Mat4 ret;
|
|
|
- ret.elements[ 0 ][ 0 ] =
|
|
|
+ ret.elements[ 0 ][ 0 ] =
|
|
|
elements[ 1 ][ 1 ] * elements[ 2 ][ 2 ] * elements[ 3 ][ 3 ] -
|
|
|
elements[ 1 ][ 1 ] * elements[ 2 ][ 3 ] * elements[ 3 ][ 2 ] -
|
|
|
elements[ 2 ][ 1 ] * elements[ 1 ][ 2 ] * elements[ 3 ][ 3 ] +
|
|
@@ -78,7 +78,7 @@ namespace Framework
|
|
|
elements[ 3 ][ 1 ] * elements[ 1 ][ 2 ] * elements[ 2 ][ 3 ] -
|
|
|
elements[ 3 ][ 1 ] * elements[ 1 ][ 3 ] * elements[ 2 ][ 2 ];
|
|
|
|
|
|
- ret.elements[ 1 ][ 0 ] =
|
|
|
+ ret.elements[ 1 ][ 0 ] =
|
|
|
-elements[ 1 ][ 0 ] * elements[ 2 ][ 2 ] * elements[ 3 ][ 3 ] +
|
|
|
elements[ 1 ][ 0 ] * elements[ 2 ][ 3 ] * elements[ 3 ][ 2 ] +
|
|
|
elements[ 2 ][ 0 ] * elements[ 1 ][ 2 ] * elements[ 3 ][ 3 ] -
|
|
@@ -86,7 +86,7 @@ namespace Framework
|
|
|
elements[ 3 ][ 0 ] * elements[ 1 ][ 2 ] * elements[ 2 ][ 3 ] +
|
|
|
elements[ 3 ][ 0 ] * elements[ 1 ][ 3 ] * elements[ 2 ][ 2 ];
|
|
|
|
|
|
- ret.elements[ 2 ][ 0 ] =
|
|
|
+ ret.elements[ 2 ][ 0 ] =
|
|
|
elements[ 1 ][ 0 ] * elements[ 2 ][ 1 ] * elements[ 3 ][ 3 ] -
|
|
|
elements[ 1 ][ 0 ] * elements[ 2 ][ 3 ] * elements[ 3 ][ 1 ] -
|
|
|
elements[ 2 ][ 0 ] * elements[ 1 ][ 1 ] * elements[ 3 ][ 3 ] +
|
|
@@ -94,7 +94,7 @@ namespace Framework
|
|
|
elements[ 3 ][ 0 ] * elements[ 1 ][ 1 ] * elements[ 2 ][ 3 ] -
|
|
|
elements[ 3 ][ 0 ] * elements[ 1 ][ 3 ] * elements[ 2 ][ 1 ];
|
|
|
|
|
|
- ret.elements[ 3 ][ 0 ] =
|
|
|
+ ret.elements[ 3 ][ 0 ] =
|
|
|
-elements[ 1 ][ 0 ] * elements[ 2 ][ 1 ] * elements[ 3 ][ 2 ] +
|
|
|
elements[ 1 ][ 0 ] * elements[ 2 ][ 2 ] * elements[ 3 ][ 1 ] +
|
|
|
elements[ 2 ][ 0 ] * elements[ 1 ][ 1 ] * elements[ 3 ][ 2 ] -
|
|
@@ -102,7 +102,7 @@ namespace Framework
|
|
|
elements[ 3 ][ 0 ] * elements[ 1 ][ 1 ] * elements[ 2 ][ 2 ] +
|
|
|
elements[ 3 ][ 0 ] * elements[ 1 ][ 2 ] * elements[ 2 ][ 1 ];
|
|
|
|
|
|
- ret.elements[ 0 ][ 1 ] =
|
|
|
+ ret.elements[ 0 ][ 1 ] =
|
|
|
-elements[ 0 ][ 1 ] * elements[ 2 ][ 2 ] * elements[ 3 ][ 3 ] +
|
|
|
elements[ 0 ][ 1 ] * elements[ 2 ][ 3 ] * elements[ 3 ][ 2 ] +
|
|
|
elements[ 2 ][ 1 ] * elements[ 0 ][ 2 ] * elements[ 3 ][ 3 ] -
|
|
@@ -110,7 +110,7 @@ namespace Framework
|
|
|
elements[ 3 ][ 1 ] * elements[ 0 ][ 2 ] * elements[ 2 ][ 3 ] +
|
|
|
elements[ 3 ][ 1 ] * elements[ 0 ][ 3 ] * elements[ 2 ][ 2 ];
|
|
|
|
|
|
- ret.elements[ 1 ][ 1 ] =
|
|
|
+ ret.elements[ 1 ][ 1 ] =
|
|
|
elements[ 0 ][ 0 ] * elements[ 2 ][ 2 ] * elements[ 3 ][ 3 ] -
|
|
|
elements[ 0 ][ 0 ] * elements[ 2 ][ 3 ] * elements[ 3 ][ 2 ] -
|
|
|
elements[ 2 ][ 0 ] * elements[ 0 ][ 2 ] * elements[ 3 ][ 3 ] +
|
|
@@ -118,7 +118,7 @@ namespace Framework
|
|
|
elements[ 3 ][ 0 ] * elements[ 0 ][ 2 ] * elements[ 2 ][ 3 ] -
|
|
|
elements[ 3 ][ 0 ] * elements[ 0 ][ 3 ] * elements[ 2 ][ 2 ];
|
|
|
|
|
|
- ret.elements[ 2 ][ 1 ] =
|
|
|
+ ret.elements[ 2 ][ 1 ] =
|
|
|
-elements[ 0 ][ 0 ] * elements[ 2 ][ 1 ] * elements[ 3 ][ 3 ] +
|
|
|
elements[ 0 ][ 0 ] * elements[ 2 ][ 3 ] * elements[ 3 ][ 1 ] +
|
|
|
elements[ 2 ][ 0 ] * elements[ 0 ][ 1 ] * elements[ 3 ][ 3 ] -
|
|
@@ -126,7 +126,7 @@ namespace Framework
|
|
|
elements[ 3 ][ 0 ] * elements[ 0 ][ 1 ] * elements[ 2 ][ 3 ] +
|
|
|
elements[ 3 ][ 0 ] * elements[ 0 ][ 3 ] * elements[ 2 ][ 1 ];
|
|
|
|
|
|
- ret.elements[ 3 ][ 1 ] =
|
|
|
+ ret.elements[ 3 ][ 1 ] =
|
|
|
elements[ 0 ][ 0 ] * elements[ 2 ][ 1 ] * elements[ 3 ][ 2 ] -
|
|
|
elements[ 0 ][ 0 ] * elements[ 2 ][ 2 ] * elements[ 3 ][ 1 ] -
|
|
|
elements[ 2 ][ 0 ] * elements[ 0 ][ 1 ] * elements[ 3 ][ 2 ] +
|
|
@@ -134,7 +134,7 @@ namespace Framework
|
|
|
elements[ 3 ][ 0 ] * elements[ 0 ][ 1 ] * elements[ 2 ][ 2 ] -
|
|
|
elements[ 3 ][ 0 ] * elements[ 0 ][ 2 ] * elements[ 2 ][ 1 ];
|
|
|
|
|
|
- ret.elements[ 0 ][ 2 ] =
|
|
|
+ ret.elements[ 0 ][ 2 ] =
|
|
|
elements[ 0 ][ 1 ] * elements[ 1 ][ 2 ] * elements[ 3 ][ 3 ] -
|
|
|
elements[ 0 ][ 1 ] * elements[ 1 ][ 3 ] * elements[ 3 ][ 2 ] -
|
|
|
elements[ 1 ][ 1 ] * elements[ 0 ][ 2 ] * elements[ 3 ][ 3 ] +
|
|
@@ -142,7 +142,7 @@ namespace Framework
|
|
|
elements[ 3 ][ 1 ] * elements[ 0 ][ 2 ] * elements[ 1 ][ 3 ] -
|
|
|
elements[ 3 ][ 1 ] * elements[ 0 ][ 3 ] * elements[ 1 ][ 2 ];
|
|
|
|
|
|
- ret.elements[ 1 ][ 2 ] =
|
|
|
+ ret.elements[ 1 ][ 2 ] =
|
|
|
-elements[ 0 ][ 0 ] * elements[ 1 ][ 2 ] * elements[ 3 ][ 3 ] +
|
|
|
elements[ 0 ][ 0 ] * elements[ 1 ][ 3 ] * elements[ 3 ][ 2 ] +
|
|
|
elements[ 1 ][ 0 ] * elements[ 0 ][ 2 ] * elements[ 3 ][ 3 ] -
|
|
@@ -150,7 +150,7 @@ namespace Framework
|
|
|
elements[ 3 ][ 0 ] * elements[ 0 ][ 2 ] * elements[ 1 ][ 3 ] +
|
|
|
elements[ 3 ][ 0 ] * elements[ 0 ][ 3 ] * elements[ 1 ][ 2 ];
|
|
|
|
|
|
- ret.elements[ 2 ][ 2 ] =
|
|
|
+ ret.elements[ 2 ][ 2 ] =
|
|
|
elements[ 0 ][ 0 ] * elements[ 1 ][ 1 ] * elements[ 3 ][ 3 ] -
|
|
|
elements[ 0 ][ 0 ] * elements[ 1 ][ 3 ] * elements[ 3 ][ 1 ] -
|
|
|
elements[ 1 ][ 0 ] * elements[ 0 ][ 1 ] * elements[ 3 ][ 3 ] +
|
|
@@ -158,7 +158,7 @@ namespace Framework
|
|
|
elements[ 3 ][ 0 ] * elements[ 0 ][ 1 ] * elements[ 1 ][ 3 ] -
|
|
|
elements[ 3 ][ 0 ] * elements[ 0 ][ 3 ] * elements[ 1 ][ 1 ];
|
|
|
|
|
|
- ret.elements[ 3 ][ 2 ] =
|
|
|
+ ret.elements[ 3 ][ 2 ] =
|
|
|
-elements[ 0 ][ 0 ] * elements[ 1 ][ 1 ] * elements[ 3 ][ 2 ] +
|
|
|
elements[ 0 ][ 0 ] * elements[ 1 ][ 2 ] * elements[ 3 ][ 1 ] +
|
|
|
elements[ 1 ][ 0 ] * elements[ 0 ][ 1 ] * elements[ 3 ][ 2 ] -
|
|
@@ -166,7 +166,7 @@ namespace Framework
|
|
|
elements[ 3 ][ 0 ] * elements[ 0 ][ 1 ] * elements[ 1 ][ 2 ] +
|
|
|
elements[ 3 ][ 0 ] * elements[ 0 ][ 2 ] * elements[ 1 ][ 1 ];
|
|
|
|
|
|
- ret.elements[ 0 ][ 3 ] =
|
|
|
+ ret.elements[ 0 ][ 3 ] =
|
|
|
-elements[ 0 ][ 1 ] * elements[ 1 ][ 2 ] * elements[ 2 ][ 3 ] +
|
|
|
elements[ 0 ][ 1 ] * elements[ 1 ][ 3 ] * elements[ 2 ][ 2 ] +
|
|
|
elements[ 1 ][ 1 ] * elements[ 0 ][ 2 ] * elements[ 2 ][ 3 ] -
|
|
@@ -174,7 +174,7 @@ namespace Framework
|
|
|
elements[ 2 ][ 1 ] * elements[ 0 ][ 2 ] * elements[ 1 ][ 3 ] +
|
|
|
elements[ 2 ][ 1 ] * elements[ 0 ][ 3 ] * elements[ 1 ][ 2 ];
|
|
|
|
|
|
- ret.elements[ 1 ][ 3 ] =
|
|
|
+ ret.elements[ 1 ][ 3 ] =
|
|
|
elements[ 0 ][ 0 ] * elements[ 1 ][ 2 ] * elements[ 2 ][ 3 ] -
|
|
|
elements[ 0 ][ 0 ] * elements[ 1 ][ 3 ] * elements[ 2 ][ 2 ] -
|
|
|
elements[ 1 ][ 0 ] * elements[ 0 ][ 2 ] * elements[ 2 ][ 3 ] +
|
|
@@ -182,7 +182,7 @@ namespace Framework
|
|
|
elements[ 2 ][ 0 ] * elements[ 0 ][ 2 ] * elements[ 1 ][ 3 ] -
|
|
|
elements[ 2 ][ 0 ] * elements[ 0 ][ 3 ] * elements[ 1 ][ 2 ];
|
|
|
|
|
|
- ret.elements[ 2 ][ 3 ] =
|
|
|
+ ret.elements[ 2 ][ 3 ] =
|
|
|
-elements[ 0 ][ 0 ] * elements[ 1 ][ 1 ] * elements[ 2 ][ 3 ] +
|
|
|
elements[ 0 ][ 0 ] * elements[ 1 ][ 3 ] * elements[ 2 ][ 1 ] +
|
|
|
elements[ 1 ][ 0 ] * elements[ 0 ][ 1 ] * elements[ 2 ][ 3 ] -
|
|
@@ -190,7 +190,7 @@ namespace Framework
|
|
|
elements[ 2 ][ 0 ] * elements[ 0 ][ 1 ] * elements[ 1 ][ 3 ] +
|
|
|
elements[ 2 ][ 0 ] * elements[ 0 ][ 3 ] * elements[ 1 ][ 1 ];
|
|
|
|
|
|
- ret.elements[ 3 ][ 3 ] =
|
|
|
+ ret.elements[ 3 ][ 3 ] =
|
|
|
elements[ 0 ][ 0 ] * elements[ 1 ][ 1 ] * elements[ 2 ][ 2 ] -
|
|
|
elements[ 0 ][ 0 ] * elements[ 1 ][ 2 ] * elements[ 2 ][ 1 ] -
|
|
|
elements[ 1 ][ 0 ] * elements[ 0 ][ 1 ] * elements[ 2 ][ 2 ] +
|
|
@@ -281,5 +281,25 @@ namespace Framework
|
|
|
Mat4 i = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
|
|
|
return i;
|
|
|
}
|
|
|
+
|
|
|
+ // Gibt eine Rotationsmatrix zurück, so dass vector a wenn man ihn damit dreht in richtung des vectors b zeigt
|
|
|
+ // a: der vector der gedreht werden soll
|
|
|
+ // b: der vector zu dem gedreht werden soll
|
|
|
+ static Mat4 rotationTo( Vec3<T> &a, Vec3<T> &b )
|
|
|
+ {
|
|
|
+ Vec3 aNorm = Vec3( a ).normalize();
|
|
|
+ Vec3 bNorm = Vec3( b ).normalize();
|
|
|
+ Vec3 v = aNotm.crossProduct( bNorm );
|
|
|
+ T s = v.getLengthSq();
|
|
|
+ T c = aNorm * bNorm;
|
|
|
+ T m = ( 1 - c ) / s;
|
|
|
+ Mat3<T> cpm( { 0, -v.z, v.y, v.z, 0, -v.x, -v.y, v.x, 0 } );
|
|
|
+ Mat3<T> cpm2 = cpm * cpm;
|
|
|
+ Mat3<T> res = Mat3<T>::identity() + cpm + cpm2 * m;
|
|
|
+ return Mat4( { res.elements[ 0 ][ 0 ], res.elements[ 0 ][ 1 ], res.elements[ 0 ][ 2 ], 0,
|
|
|
+ res.elements[ 1 ][ 0 ], res.elements[ 1 ][ 1 ], res.elements[ 1 ][ 2 ], 0,
|
|
|
+ res.elements[ 2 ][ 0 ], res.elements[ 2 ][ 1 ], res.elements[ 2 ][ 2 ], 0,
|
|
|
+ 0, 0, 0, 1 } )
|
|
|
+ }
|
|
|
};
|
|
|
}
|