   Tetris block rotation
  I have an 4x4 vector like this: {0, 0, 0, 0   0, 0, 0, 0   0, 0, 0, 0   0, 0, 0, 0}And I want to make it possible to rotate the blocks by pressing the up button. I managed to do it on one block by using the most inefficient and ugliest method ever and want to stay away from that method if possible..Let's say the current block is an L-block.   0 1 0 00 1 0 00 1 0 01 1 0 0And I want the vector to look like this for example, when pressing the up button.0 0 0 01 0 0 01 1 1 10 0 0 0And like this the next time I press it the next time. (in the same pattern)0 1 1 00 1 0 00 1 0 00 1 0 0Anyone have any ideas how to accomplish this?   
  If your going to store it as a vector, why not just keep 4 vectors for each shape in an array and index them depending on which one you want.Sometimes the simplest way to do something, is the simplest way to do something. Don't use complex rotation's if you really don't need them.   ;  I agree with the poster above. It is much easier to create a few extra vectors to make your life easier, since it won't have much of an impact on memory use.But, if you're determined to calculate the rotation, you might consider taking another approach than the 4x4 grid.One way of looking at a tetris-piece is seeing it as a center block with three blocks around it(or if you're set on having five blocks, there'll be four blocks around it). Because you have a center block you can pivot around, calculations to rotate the piece are that much easier.example:the "EL"#*##* would be the center block and # the surrounding ones.In a vector you'd put the coordinates of the center block in the first elements (which is always (0,0)) and the remaining blocks, by there relative coordinates to the center block, in the following elements((0,1) (0,-1) (1,-1))Now, to rotate a piece you just have to figure out where all the possible relative coordinates go(eg. (0,1) becomes (1,0), (0,-1) becomes (-1, 0) and (1, -1) becomes (-1,-1))I hope that made the slightest piece of sense... ^^Anyway, DO realise that Homers Pal's method is easier to implement.   ;  I guess I will use that method then, thank you.   ;  x2<yy2<-xperforms a 90 degree rotation on a 2D vector andy2<xx2<-yrotates the other wayif you store the pieces as a set of coordinates relative to a center(as @root suggested) then it is very easy to rotate by applying the above equations.Also, there is no such thing as a 4X4 vector. As defined by dictionary.com a vector  is: (Computers) an array of data ordered such that individual items can be located with a single index or subscript.If it has two subscripts it's a matrix.   ;Quote:Original post by Alrecenkx2<yy2<-xperforms a 90 degree rotation on a 2D vector andy2<xx2<-yrotates the other wayif you store the pieces as a set of coordinates relative to a center(as @root suggested) then it is very easy to rotate by applying the above equations.Also, there is no such thing as a 4X4 vector. As defined by dictionary.com a vector  is: (Computers) an array of data ordered such that individual items can be located with a single index or subscript.If it has two subscripts it's a matrix.You most have misunderstood what I meant with vector. I am referring to std::vector which is used as an array.Edit:seems like everyone misunderstood what I meant with vector. Well, I managed to get a decent idea from your replies so it doesn't matter.   ;  No I understood fine what you meant by vectors, but even then you don't need to do that, just index into a list of 4xshape1, 4xshape2, 4xshape3 egt to get to the right sequence of data you want for a particular shape. Or store  4 elements of an array or vecotr, in a single or 2D array.have fund.   