[ad_1]
I am engaged on implementing the backend logic behind the classical tetris sport, and I am a bit confused on how a rotation is carried out. I perceive that you may apply a rotation matrix, however I nonetheless have some questions which might be maybe higher defined with an instance.
In my implementation, I take advantage of sq. matrices of 0s and 1s to characterize the form. e.g., I take advantage of a 4×4 matrix with a single row crammed to characterize the lengthy horizontal block:
$$
start{bmatrix}
1 & 1 & 1 & 1
0 & 0 & 0 & 0
0 & 0 & 0 & 0
0 & 0 & 0 & 0
finish{bmatrix}
$$
And for every block, I additionally maintain observe of the underside proper location of the 4×4 matrix relative to the situation of the sport board.
The query I’ve is, if you apply a rotation (on this case it will flip right into a vertical block), do you need to repair some heart? In that case, how is that this heart of rotation outlined?
e.g., I may outline the middle of rotation of the above as the highest left ingredient, so apply 90 diploma clockwise rotation would yield:
$$
start{bmatrix}
1 & 0 & 0 & 0
1 & 0 & 0 & 0
1 & 0 & 0 & 0
1 & 0 & 0 & 0
finish{bmatrix}
$$
However you would additionally make any of the opposite 15 components the middle of rotation, although it in all probability makes probably the most sense to make one of many 4 components of the unique block the middle of rotation. I believe the problem right here is that for the opposite 3 components, in case you make any of them the middle of rotation, a part of the rotated block goes to lie exterior the prevailing 4×4 window. So how is one thing like this prescribed in an implementation?
Alternatively you possibly can swap the indices as in Tetris – Rotations utilizing Linear Algebra (Rotation Matrices) with out utilizing a middle of rotation, however I am undecided which method makes probably the most sense. Swapping indices is actually a lot simpler to implement.
[ad_2]