Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static Float4x4 Inverse(const Float4x4& matrix)
- {
- Float4x4 out(Float4(0.0));
- // Inverse of the 3x3 rotation matrix is just its transpose
- out.x.x = matrix.x.x;
- out.x.y = matrix.y.x;
- out.x.z = matrix.z.x;
- // -- //
- out.y.x = matrix.x.y;
- out.y.y = matrix.y.y;
- out.y.z = matrix.z.y;
- // -- //
- out.z.x = matrix.x.z;
- out.z.y = matrix.y.z;
- out.z.z = matrix.z.z;
- // Inverse of the translation vector is Multiply(-translationVector, Transpose(rotationMatrix));
- Float3 negativePosition = -Float3(matrix.x.w, matrix.y.w, matrix.z.w);
- // -- //
- out.x.w = Dot(negativePosition, out.x.xyz);
- out.y.w = Dot(negativePosition, out.y.xyz);
- out.z.w = Dot(negativePosition, out.z.xyz);
- // .w.w should be 1.0 :p
- out.w.w = 1.0;
- return out;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement