I'm working on implementing the backend logic behind the classical tetris game, and I'm a bit confused on how a rotation is performed. I understand that you can apply a rotation matrix, but I still have some questions that are perhaps better explained with an example.
In my implementation, I use square matrices of 0s and 1s to represent the shape. e.g., I use a 4x4 matrix with a single row filled to represent the long horizontal block: $$ \begin{bmatrix} 1 & 1 & 1 & 1 \\ 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 \end{bmatrix} $$
And for each block, I also keep track of the bottom right location of the 4x4 matrix relative to the location of the game board.
The question I have is, when you apply a rotation (in this case it would turn into a vertical block), do you have to fix some center? If so, how is this center of rotation defined?
e.g., I could define the center of rotation of the above as the top left element, so apply 90 degree clockwise rotation would yield:
$$ \begin{bmatrix} 1 & 0 & 0 & 0 \\ 1 & 0 & 0 & 0 \\ 1 & 0 & 0 & 0 \\ 1 & 0 & 0 & 0 \end{bmatrix} $$
But you could also make any of the other 15 elements the center of rotation, though it probably makes the most sense to make one of the 4 elements of the original block the center of rotation. I think the issue here is that for the other 3 elements, if you make any of them the center of rotation, part of the rotated block is going to lie outside the existing 4x4 window. So how is something like this prescribed in an implementation?
Alternatively you can swap the indices as in Tetris - Rotations using Linear Algebra (Rotation Matrices) without using a center of rotation, but I'm not sure which approach makes the most sense. Swapping indices is certainly much easier to implement.