Guest User

Untitled

a guest
Feb 25th, 2014
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.92 KB | None | 0 0
  1.     private FloatBuffer generateBox() {
  2.         FloatBuffer boxData = BufferUtils.createFloatBuffer(6 * 6 * 3);
  3.        
  4.         float halfWidth = width / 2;
  5.         float halfHeight = height / 2;
  6.         float halfDepth = depth / 2;
  7.        
  8.         //calculate nodes
  9.         float topN1X = -halfWidth;
  10.         float topN1Y = halfHeight;
  11.         float topN1Z = -halfDepth;
  12.        
  13.         float topN2X = -halfWidth;
  14.         float topN2Y = halfHeight;
  15.         float topN2Z = halfDepth;
  16.        
  17.         float topN3X = halfWidth;
  18.         float topN3Y = halfHeight;
  19.         float topN3Z = halfDepth;
  20.        
  21.         float topN4X = halfWidth;
  22.         float topN4Y = halfHeight;
  23.         float topN4Z = -halfDepth;
  24.        
  25.         float bottomN1X = -halfWidth;
  26.         float bottomN1Y = -halfHeight;
  27.         float bottomN1Z = -halfDepth;
  28.        
  29.         float bottomN2X = -halfWidth;
  30.         float bottomN2Y = -halfHeight;
  31.         float bottomN2Z = halfDepth;
  32.        
  33.         float bottomN3X = halfWidth;
  34.         float bottomN3Y = -halfHeight;
  35.         float bottomN3Z = halfDepth;
  36.        
  37.         float bottomN4X = halfWidth;
  38.         float bottomN4Y = -halfHeight;
  39.         float bottomN4Z = -halfDepth;
  40.        
  41.         //top face
  42.         boxData
  43.                 .put(topN4X).put(topN4Y).put(topN4Z)    //first triangle
  44.                 .put(topN1X).put(topN1Y).put(topN1Z)
  45.                 .put(topN2X).put(topN2Y).put(topN2Z)
  46.                 .put(topN2X).put(topN2Y).put(topN2Z)    //second triangle
  47.                 .put(topN3X).put(topN3Y).put(topN3Z)
  48.                 .put(topN4X).put(topN4Y).put(topN4Z);
  49.        
  50.         //bottom face
  51.         boxData
  52.                 .put(bottomN4X).put(bottomN4Y).put(bottomN4Z)    //first triangle
  53.                 .put(bottomN1X).put(bottomN1Y).put(bottomN1Z)
  54.                 .put(bottomN2X).put(bottomN2Y).put(bottomN2Z)
  55.                 .put(bottomN2X).put(bottomN2Y).put(bottomN2Z)   //second triangle
  56.                 .put(bottomN3X).put(bottomN3Y).put(bottomN3Z)
  57.                 .put(bottomN4X).put(bottomN4Y).put(bottomN4Z);
  58.        
  59.         //face from N1 to N2
  60.         boxData
  61.                 .put(topN1X).put(topN1Y).put(topN1Z)            //first triangle
  62.                 .put(bottomN1X).put(bottomN1Y).put(bottomN1Z)
  63.                 .put(bottomN2X).put(bottomN2Y).put(bottomN2Z)
  64.                 .put(bottomN2X).put(bottomN2Y).put(bottomN2Z)   //second triangle
  65.                 .put(topN2X).put(topN2Y).put(topN2Z)
  66.                 .put(topN1X).put(topN1Y).put(topN1Z);
  67.        
  68.         //face from N2 to N3
  69.         boxData
  70.                 .put(topN2X).put(topN2Y).put(topN2Z)            //first triangle
  71.                 .put(bottomN2X).put(bottomN2Y).put(bottomN2Z)
  72.                 .put(bottomN3X).put(bottomN3Y).put(bottomN3Z)
  73.                 .put(bottomN3X).put(bottomN3Y).put(bottomN3Z)   //second triangle
  74.                 .put(topN3X).put(topN3Y).put(topN3Z)
  75.                 .put(topN2X).put(topN2Y).put(topN2Z);
  76.        
  77.         //face from N3 to N4
  78.         boxData
  79.                 .put(topN3X).put(topN3Y).put(topN3Z)            //first triangle
  80.                 .put(bottomN3X).put(bottomN3Y).put(bottomN3Z)
  81.                 .put(bottomN4X).put(bottomN4Y).put(bottomN4Z)
  82.                 .put(bottomN4X).put(bottomN4Y).put(bottomN4Z)   //second triangle
  83.                 .put(topN4X).put(topN4Y).put(topN4Z)
  84.                 .put(topN3X).put(topN3Y).put(topN3Z);
  85.        
  86.         //face from N4 to N1
  87.         boxData
  88.                 .put(topN4X).put(topN4Y).put(topN4Z)            //first triangle
  89.                 .put(bottomN4X).put(bottomN4Y).put(bottomN4Z)
  90.                 .put(bottomN1X).put(bottomN1Y).put(bottomN1Z)
  91.                 .put(bottomN1X).put(bottomN1Y).put(bottomN1Z)   //second triangle
  92.                 .put(topN1X).put(topN1Y).put(topN1Z)
  93.                 .put(topN4X).put(topN4Y).put(topN4Z);
  94.        
  95.         return (FloatBuffer)boxData.clear();
  96.     }
Advertisement
Add Comment
Please, Sign In to add comment