# making a 3D tetris

This topic is 5021 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hi, i am trying a to make a tetris 3D i will put the 6 classic figures but in 3D. i plan to do a field where you can place the figures in 3D. well, i need some advices since all the figures are formed with cubes (for example, the "L" has 3 cubes in the Y axis and 2 in X axis. the "bar" has 4 cubes in the Y axis and 1 in the X): 1.- should i use AABB for collision? (bounding boxes). if the answer is yes, which way would it be better: 1.-considering that ALL the 6 figures has either 2 or 3 cubes in the Y or X axis (except for the bar that has 4 in the Y), should i create a bounding box for the Y -axis cubes (2 or 3 cubes) and another for the X-axis cubes (2 or 3 cubes also). or: 2.- should i create a bounding box for EVERY cube that forms the figure? 3.- if the other 2 options were crap...wich way should it be? (easier or better) and if the answer was no for using AABB for collision detection....which way should it be done? hope my questions were clear thanks in advance.

##### Share on other sites
In 2d Tetris, the usual approach is to imagine a 4x4 bounding box around the current piece - you check for filled squares within the box, then intersecting the piece. So it is a sort of AABB collision test, but it works at the resolution of the pieces, not at the resolution of their graphics. You do not try to intersect individual squares, but instead have a separate array indicating which squares are full and do comparisons within that.

For 3D-tris, do the analogous thing, with a 4x4x4 bounding cube.

##### Share on other sites
i dont understand something...
why 4x4?
the max amount of cubes in Y or X are 3 (except for the bar) and in Z is 1
if for example , i have the bar that is 1x4x1 (x,y,z) , having a 4x4x4 will be a waste no?

and also, how will i know if there is an empty cube?
wouldnt that be like doing a AABB for every cube forming the figure? (my option #2)

##### Share on other sites
Because it has to be a big enough 'box' to contain the current shape regardless of how it gets rotated. It is not a big deal anyway, not compared to the space your graphics resources are likely to take up, and certainly not compared to what you seemed about ready to implement.

You just represent the block with a data structure, for example just an array of bool[4][4][4]; set points to true to represent spaces filled by the block. Similarly you have an array of bool[x][y][z] representing the current contents of the playing field. For collision, you find the current coordinate (a,b,c) of your block's "AABB", and loop over 4 squares in each dimension, to see if there's a spot where the block and the field both have a true 'filled' value.

##### Share on other sites
so, for example.
if my world is 16x16x16 big
i will have and array of bools:
bool world[16][16][16];

and if for example, i have my "bar" (the one with 4 cubes)
i will have that bar represented by
bool figures[4][4][4] (for in the case if i rotated it)

but for example, if i place my bar in
(2,0,7) (in the x-axis) , it will cover:
for x [2,5]
for y [0,1]
for z [7,8]

how will i know which position i place my bar?

##### Share on other sites
You choose an orientation for the piece when you release it into the field, and for simplicity let's say we release it at (6,6,0), centered at the top of the field. Then the piece's AABB is in the cube from (6,6,0) to (9,9,3) inclusive, and it takes up some 4 out of those 64 spots. You examine those to see if any of them are already full; game over if so (couldn't put the block onto the field).

Otherwise, you continually try to move the block down, and also in other ways as requested by the user. Each time you would try to move the block, you test with that 'candidate' position for the block; if it won't work, then you just don't actually move it. When it can't move down, the piece is finished dropping.

So basically what you need to do is keep track of the location of the surrounding box, and separately keep track of what squares inside the box are filled. When you rotate the piece, you (try to) change the set of filled squares inside that box.

##### Share on other sites
ok, thanks a lot.
i also need another advice.

when drawing the figure
should i have only one function to do it?
for example:
i will have only one multidimensional array like this:

bool figures[4][4][4];
and i will fill it with "true or false" in every position to represent the figure like this for drawing an "L" (asumming the integer is the number of "trues").

figures[2][3][1]
and i will pass to a function the numbers of "tures" in each position like this:

void DrawFigure(int x, int y, int z, int size)
{
for(int i=x ; i>=0 ; i--)
// draw cube in x
}

and so on for Y and Z cubes

what do you think of it?

also, for counting the number of trues in each position should i have something like this?:
int trueX, trueY, trueZ ??

[Edited by - BlackWind on February 14, 2005 11:11:54 AM]

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633297
• Total Posts
3011247
• ### Who's Online (See full list)

There are no registered users currently online

×