Advertisement
baryonSasuke

4x4 trans matrix to pos, scale, orient

Dec 31st, 2020
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. public Transformation(Matrix transformation) {
  2.         this.pos = transformation.getColumn(3).removeDimensionFromVec(3);
  3.  
  4.         var rotScaleMatrix = transformation.getSubMatrix(0,0,2,2);
  5.  
  6.         List<Vector> rotCols = new ArrayList<>();
  7.         var scale = new Vector(1,1,1);
  8.         for(int i = 0;i < 3;i++) {
  9.             var v = rotScaleMatrix.getColumn(i);
  10.             scale.setDataElement(i, v.getNorm());
  11.             v.normalise();
  12.             rotCols.add(v);
  13.         }
  14.  
  15.         var rotMatrix = new Matrix(rotCols);
  16.         this.orientation = new Quaternion(rotMatrix);
  17.         this.orientation.normalise();
  18.         this.scale = scale;
  19.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement