Advertisement
Ember

fast inverse

Dec 29th, 2015
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. static Float4x4 Inverse(const Float4x4& matrix)
  2. {
  3.     Float4x4 out(Float4(0.0));
  4.     // Inverse of the 3x3 rotation matrix is just its transpose
  5.     out.x.x = matrix.x.x;
  6.     out.x.y = matrix.y.x;
  7.     out.x.z = matrix.z.x;
  8.     // -- //
  9.     out.y.x = matrix.x.y;
  10.     out.y.y = matrix.y.y;
  11.     out.y.z = matrix.z.y;
  12.     // -- //
  13.     out.z.x = matrix.x.z;
  14.     out.z.y = matrix.y.z;
  15.     out.z.z = matrix.z.z;
  16.     // Inverse of the translation vector is Multiply(-translationVector, Transpose(rotationMatrix));
  17.     Float3 negativePosition = -Float3(matrix.x.w, matrix.y.w, matrix.z.w);
  18.     // -- //
  19.     out.x.w = Dot(negativePosition, out.x.xyz);
  20.     out.y.w = Dot(negativePosition, out.y.xyz);
  21.     out.z.w = Dot(negativePosition, out.z.xyz);
  22.     // .w.w should be 1.0 :p
  23.     out.w.w = 1.0;
  24.  
  25.     return out;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement