Here is what I want to do : I want to have a modular cube that when touching an other one will disable the two faces between eachothers. Like so :
I want to make the grey faces disapear.
Looks rather simple in theory right ?
Except that this is how we are supposed to make a a shape in modern OpenGL. First we declare the vertices, then the indices to tell which is connected to which.
FloatBuffer vertices = BufferUtils.createFloatBuffer(8 * 6);
vertices.put(new float[]{
// front // color
-0.5f, -0.5f, 0.5f, 0.75f, 0.75f, 0.75f,
0.5f, -0.5f, 0.5f, 0.75f, 0.75f, 0.75f,
0.5f, 0.5f, 0.5f, 0.35f, 0.75f, 0.9f,
-0.5f, 0.5f, 0.5f, 0.35f, 0.75f, 0.9f,
// back
-0.5f, -0.5f, -0.5f, 0.75f, 0.75f, 0.75f,
0.5f, -0.5f, -0.5f, 0.75f, 0.75f, 0.75f,
0.5f, 0.5f, -0.5f, 0.35f, 0.75f, 0.9f,
-0.5f, 0.5f, -0.5f, 0.35f, 0.75f, 0.9f,
});
vertices.flip();
IntBuffer indices = BufferUtils.createIntBuffer(12 * 3);
indices.put(new int[]{
// front
0, 1, 2,
2, 3, 0,
// top
3, 2, 6,
6, 7, 3,
// back
7, 6, 5,
5, 4, 7,
// bottom
4, 5, 1,
1, 0, 4,
// left
4, 0, 3,
3, 7, 4,
// right
1, 5, 6,
6, 2, 1,
});
indices.flip();
This makes for a lightweight cube. But I don't see how I can disable the faces I want with this model.
Does anyone has a solution that doesn't imply me re-doing my cube ?
Thank you