Advertisement
Guest User

Matrix3f

a guest
Nov 24th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | None | 0 0
  1.         public Matrix3f mul(Matrix3f otherMatrix){
  2.     Matrix3f res = new Matrix3f();
  3.  
  4.     for(int i = 0; i < 3; i++){
  5.         for(int j = 0; j < 3; j++){
  6.         res.set(i, j,
  7.             m[i][0] * otherMatrix.get(0, j) +
  8.             m[i][1] * otherMatrix.get(1, j) +
  9.             m[i][2] * otherMatrix.get(2, j));
  10.         }
  11.     }
  12.     return res;
  13.     }
  14.     public Matrix3f initIdentity(){
  15.     m[0][0] = 1; m[0][1] = 0; m[0][2] = 0;
  16.     m[1][0] = 0; m[1][1] = 1; m[1][2] = 0;
  17.     m[2][0] = 0; m[2][1] = 0; m[2][2] = 1;
  18.     return this;
  19.     }
  20.  
  21.     public Matrix3f initTranslationIdentity(float x, float y) {
  22.     m[0][0] = 1; m[0][1] = 0; m[0][2] = x;
  23.     m[1][0] = 0; m[1][1] = 1; m[1][2] = y;
  24.     m[2][0] = 0; m[2][1] = 0; m[2][2] = 1;
  25.     return this;
  26.     }
  27.  
  28.     public Matrix3f initRotationIdentity(double angle) {
  29.     float cos = (float) Math.cos(angle);
  30.     float sin = (float) Math.sin(angle);
  31.     m[0][0] = cos;  m[0][1] = sin; m[0][2] = 0;
  32.     m[1][0] = -sin; m[1][1] = cos; m[1][2] = 0;
  33.     m[2][0] = 0;    m[2][1] = 0;   m[2][2] = 1;
  34.     return this;
  35.     }
  36.  
  37.     public Matrix3f initScaleIdentity(float x, float y) {
  38.     m[0][0] = x; m[0][1] = 0; m[0][2] = 0;
  39.     m[1][0] = 0; m[1][1] = y; m[1][2] = 0;
  40.     m[2][0] = 0; m[2][1] = 0; m[2][2] = 1;
  41.     return this;
  42.     }
  43.  
  44.     public Matrix3f initShearXIdentity(float shearX) {
  45.     m[0][0] = 1; m[0][1] = shearX; m[0][2] = 0;
  46.     m[1][0] = 0; m[1][1] = 1; m[1][2] = 0;
  47.     m[2][0] = 0; m[2][1] = 0; m[2][2] = 1;
  48.     return this;
  49.     }
  50.  
  51.     public Matrix3f initShearYIdentity(float shearY) {
  52.     m[0][0] = 1;      m[0][1] = 0; m[0][2] = 0;
  53.     m[1][0] = shearY; m[1][1] = 1; m[1][2] = 0;
  54.     m[2][0] = 0;      m[2][1] = 0; m[2][2] = 1;
  55.     return this;
  56.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement