Trying To Create 3x3x3 Cube But Created 4x4x4 Instead In OpenGL
I am trying to create a 3d rubiks cube, however the dimensions are not aligning with the dimensions set. When I set the dimensions to 3 and create a 3x3x3 cube, I end up creating a
Solution 1:
It might look that way because your pieces are overlapping.
You create your pieces at distances of scale
. If we visualize that in 1D, we get (s
stands for scale
):
o o o
`-- s --´ `-- s --´
The pieces extend between pos - len
and pos + len
. You set len = scale
. Hence, what you get is:
---------o---------
---------o--------- ---------o----------
`-- s --´ `-- s --´
To solve this, you should specify a length that is half the spacing. So, either:
cube[i][j][k] = Piece(2 * i * scale, 2 * j * scale, 2 * k * scale, scale)
or
cube[i][j][k] = Piece(i * scale, j * scale, k * scale, 0.5 * scale)
Post a Comment for "Trying To Create 3x3x3 Cube But Created 4x4x4 Instead In OpenGL"