Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private FloatBuffer generateBox() {
- FloatBuffer boxData = BufferUtils.createFloatBuffer(6 * 6 * 3);
- float halfWidth = width / 2;
- float halfHeight = height / 2;
- float halfDepth = depth / 2;
- //calculate nodes
- float topN1X = -halfWidth;
- float topN1Y = halfHeight;
- float topN1Z = -halfDepth;
- float topN2X = -halfWidth;
- float topN2Y = halfHeight;
- float topN2Z = halfDepth;
- float topN3X = halfWidth;
- float topN3Y = halfHeight;
- float topN3Z = halfDepth;
- float topN4X = halfWidth;
- float topN4Y = halfHeight;
- float topN4Z = -halfDepth;
- float bottomN1X = -halfWidth;
- float bottomN1Y = -halfHeight;
- float bottomN1Z = -halfDepth;
- float bottomN2X = -halfWidth;
- float bottomN2Y = -halfHeight;
- float bottomN2Z = halfDepth;
- float bottomN3X = halfWidth;
- float bottomN3Y = -halfHeight;
- float bottomN3Z = halfDepth;
- float bottomN4X = halfWidth;
- float bottomN4Y = -halfHeight;
- float bottomN4Z = -halfDepth;
- //top face
- boxData
- .put(topN4X).put(topN4Y).put(topN4Z) //first triangle
- .put(topN1X).put(topN1Y).put(topN1Z)
- .put(topN2X).put(topN2Y).put(topN2Z)
- .put(topN2X).put(topN2Y).put(topN2Z) //second triangle
- .put(topN3X).put(topN3Y).put(topN3Z)
- .put(topN4X).put(topN4Y).put(topN4Z);
- //bottom face
- boxData
- .put(bottomN4X).put(bottomN4Y).put(bottomN4Z) //first triangle
- .put(bottomN1X).put(bottomN1Y).put(bottomN1Z)
- .put(bottomN2X).put(bottomN2Y).put(bottomN2Z)
- .put(bottomN2X).put(bottomN2Y).put(bottomN2Z) //second triangle
- .put(bottomN3X).put(bottomN3Y).put(bottomN3Z)
- .put(bottomN4X).put(bottomN4Y).put(bottomN4Z);
- //face from N1 to N2
- boxData
- .put(topN1X).put(topN1Y).put(topN1Z) //first triangle
- .put(bottomN1X).put(bottomN1Y).put(bottomN1Z)
- .put(bottomN2X).put(bottomN2Y).put(bottomN2Z)
- .put(bottomN2X).put(bottomN2Y).put(bottomN2Z) //second triangle
- .put(topN2X).put(topN2Y).put(topN2Z)
- .put(topN1X).put(topN1Y).put(topN1Z);
- //face from N2 to N3
- boxData
- .put(topN2X).put(topN2Y).put(topN2Z) //first triangle
- .put(bottomN2X).put(bottomN2Y).put(bottomN2Z)
- .put(bottomN3X).put(bottomN3Y).put(bottomN3Z)
- .put(bottomN3X).put(bottomN3Y).put(bottomN3Z) //second triangle
- .put(topN3X).put(topN3Y).put(topN3Z)
- .put(topN2X).put(topN2Y).put(topN2Z);
- //face from N3 to N4
- boxData
- .put(topN3X).put(topN3Y).put(topN3Z) //first triangle
- .put(bottomN3X).put(bottomN3Y).put(bottomN3Z)
- .put(bottomN4X).put(bottomN4Y).put(bottomN4Z)
- .put(bottomN4X).put(bottomN4Y).put(bottomN4Z) //second triangle
- .put(topN4X).put(topN4Y).put(topN4Z)
- .put(topN3X).put(topN3Y).put(topN3Z);
- //face from N4 to N1
- boxData
- .put(topN4X).put(topN4Y).put(topN4Z) //first triangle
- .put(bottomN4X).put(bottomN4Y).put(bottomN4Z)
- .put(bottomN1X).put(bottomN1Y).put(bottomN1Z)
- .put(bottomN1X).put(bottomN1Y).put(bottomN1Z) //second triangle
- .put(topN1X).put(topN1Y).put(topN1Z)
- .put(topN4X).put(topN4Y).put(topN4Z);
- return (FloatBuffer)boxData.clear();
- }
Advertisement
Add Comment
Please, Sign In to add comment