Want more features on Pastebin? Sign Up, it's FREE!
Guest

Matrix4f Array optimized

By: a guest on Jul 24th, 2011  |  syntax: Java 5  |  size: 2.05 KB  |  views: 77  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public void mul4f(Matrix4fArray leftM, Matrix4fArray rightM) {
  2.         final float[] left = leftM.buffer;
  3.         final float[] right = rightM.buffer;
  4.         final float[] buffer = this.buffer;
  5.  
  6.         float lm00 = left[0];
  7.         float rm00 = right[0];
  8.  
  9.         float lm10 = left[1];
  10.         float rm01 = right[4];
  11.  
  12.         float lm20 = left[2];
  13.         float rm02 = right[8];
  14.  
  15.         float lm30 = left[3];
  16.  
  17.         buffer[0] = lm00 * rm00 + lm10 * rm01 + lm20 * rm02 + lm30 * right[12];
  18.  
  19.         float rm10 = right[1];
  20.         float rm11 = right[5];
  21.         float rm12 = right[9];
  22.  
  23.         buffer[1] = lm00 * rm10 + lm10 * rm11 + lm20 * rm12 + lm30 * right[13];
  24.  
  25.         float rm20 = right[2];
  26.         float rm21 = right[6];
  27.         float rm22 = right[10];
  28.  
  29.         buffer[2] = lm00 * rm20 + lm10 * rm21 + lm20 * rm22 + lm30 * right[14];
  30.  
  31.         float rm30 = right[3];
  32.         float rm31 = right[7];
  33.         float rm32 = right[11];
  34.  
  35.         buffer[3] = lm00 * rm30 + lm10 * rm31 + lm20 * rm32 + lm30 * right[15];
  36.  
  37.         float lm01 = left[4];
  38.         float lm11 = left[5];
  39.         float lm21 = left[6];
  40.         float lm31 = left[7];
  41.  
  42.         buffer[4] = lm01 * rm00 + lm11 * rm01 + lm21 * rm02 + lm31 * right[12];
  43.         buffer[5] = lm01 * rm10 + lm11 * rm11 + lm21 * rm12 + lm31 * right[13];
  44.         buffer[6] = lm01 * rm20 + lm11 * rm21 + lm21 * rm22 + lm31 * right[14];
  45.         buffer[7] = lm01 * rm30 + lm11 * rm31 + lm21 * rm32 + lm31 * right[15];
  46.  
  47.         float lm02 = left[8];
  48.         float lm12 = left[9];
  49.         float lm22 = left[10];
  50.         float lm32 = left[11];
  51.  
  52.         buffer[8] = lm02 * rm00 + lm12 * rm01 + lm22 * rm02 + lm32 * right[12];
  53.         buffer[9] = lm02 * rm10 + lm12 * rm11 + lm22 * rm12 + lm32 * right[13];
  54.         buffer[10] = lm02 * rm20 + lm12 * rm21 + lm22 * rm22 + lm32 * right[14];
  55.         buffer[11] = lm02 * rm30 + lm12 * rm31 + lm22 * rm32 + lm32 * right[15];
  56.  
  57.         float lm03 = left[12];
  58.         float lm13 = left[13];
  59.         float lm23 = left[14];
  60.         float lm33 = left[15];
  61.  
  62.         buffer[12] = lm03 * rm00 + lm13 * rm01 + lm23 * rm02 + lm33 * right[12];
  63.         buffer[13] = lm03 * rm10 + lm13 * rm11 + lm23 * rm12 + lm33 * right[13];
  64.         buffer[14] = lm03 * rm20 + lm13 * rm21 + lm23 * rm22 + lm33 * right[14];
  65.         buffer[15] = lm03 * rm30 + lm13 * rm31 + lm23 * rm32 + lm33 * right[15];
  66. }
clone this paste RAW Paste Data