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

Matrix4f NIO optimized

By: a guest on Jul 24th, 2011  |  syntax: Java 5  |  size: 2.28 KB  |  views: 132  |  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(Matrix4fBuffer leftM, Matrix4fBuffer rightM) {
  2.         final FloatBuffer left = leftM.buffer;
  3.         final FloatBuffer right = rightM.buffer;
  4.         final FloatBuffer buffer = this.buffer;
  5.  
  6.         float lm00 = left.get(0);
  7.         float rm00 = right.get(0);
  8.  
  9.         float lm10 = left.get(1);
  10.         float rm01 = right.get(4);
  11.  
  12.         float lm20 = left.get(2);
  13.         float rm02 = right.get(8);
  14.  
  15.         float lm30 = left.get(3);
  16.  
  17.         buffer.put(0, lm00 * rm00 + lm10 * rm01 + lm20 * rm02 + lm30 * right.get(12));
  18.  
  19.         float rm10 = right.get(1);
  20.         float rm11 = right.get(5);
  21.         float rm12 = right.get(9);
  22.  
  23.         buffer.put(1, lm00 * rm10 + lm10 * rm11 + lm20 * rm12 + lm30 * right.get(13));
  24.  
  25.         float rm20 = right.get(2);
  26.         float rm21 = right.get(6);
  27.         float rm22 = right.get(10);
  28.  
  29.         buffer.put(2, lm00 * rm20 + lm10 * rm21 + lm20 * rm22 + lm30 * right.get(14));
  30.  
  31.         float rm30 = right.get(3);
  32.         float rm31 = right.get(7);
  33.         float rm32 = right.get(11);
  34.  
  35.         buffer.put(3, lm00 * rm30 + lm10 * rm31 + lm20 * rm32 + lm30 * right.get(15));
  36.  
  37.         float lm01 = left.get(4);
  38.         float lm11 = left.get(5);
  39.         float lm21 = left.get(6);
  40.         float lm31 = left.get(7);
  41.  
  42.         buffer.put(4, lm01 * rm00 + lm11 * rm01 + lm21 * rm02 + lm31 * right.get(12));
  43.         buffer.put(5, lm01 * rm10 + lm11 * rm11 + lm21 * rm12 + lm31 * right.get(13));
  44.         buffer.put(6, lm01 * rm20 + lm11 * rm21 + lm21 * rm22 + lm31 * right.get(14));
  45.         buffer.put(7, lm01 * rm30 + lm11 * rm31 + lm21 * rm32 + lm31 * right.get(15));
  46.  
  47.         float lm02 = left.get(8);
  48.         float lm12 = left.get(9);
  49.         float lm22 = left.get(10);
  50.         float lm32 = left.get(11);
  51.  
  52.         buffer.put(8, lm02 * rm00 + lm12 * rm01 + lm22 * rm02 + lm32 * right.get(12));
  53.         buffer.put(9, lm02 * rm10 + lm12 * rm11 + lm22 * rm12 + lm32 * right.get(13));
  54.         buffer.put(10, lm02 * rm20 + lm12 * rm21 + lm22 * rm22 + lm32 * right.get(14));
  55.         buffer.put(11, lm02 * rm30 + lm12 * rm31 + lm22 * rm32 + lm32 * right.get(15));
  56.  
  57.         float lm03 = left.get(12);
  58.         float lm13 = left.get(13);
  59.         float lm23 = left.get(14);
  60.         float lm33 = left.get(15);
  61.  
  62.         buffer.put(12, lm03 * rm00 + lm13 * rm01 + lm23 * rm02 + lm33 * right.get(12));
  63.         buffer.put(13, lm03 * rm10 + lm13 * rm11 + lm23 * rm12 + lm33 * right.get(13));
  64.         buffer.put(14, lm03 * rm20 + lm13 * rm21 + lm23 * rm22 + lm33 * right.get(14));
  65.         buffer.put(15, lm03 * rm30 + lm13 * rm31 + lm23 * rm32 + lm33 * right.get(15));
  66. }
clone this paste RAW Paste Data