Matrix rotation (Tetris)

Started by
11 comments, last by SonicD007 11 years, 6 months ago
If you want to go the matrix route, the general method is to "translate the origin", i.e. since a cardinal rotation matrix rotates about a single world axis passing through the world origin (0,0), and you want to rotate about the point p, you'll temporarily make point p the origin, then rotate, and then translate back. In matrix math, using the M*v convention, the formula is M = T(p) * R * T(-p), where T(p) translates by the point p, and R is the original rotation matrix about the origin.

Alternatively, and what might be easier, just manually compute the offsets you want to perform after each rotation, and store them in some precomputed table.
Advertisement

Hey everyone,
I have another question regarding this same topic. I got the rotation working using the cyclic roll (as mentioned in this topic) and my Tetris game has been going well so far. Now I noticed that using the method in this post, my tetris piece will rotate, but its rotated location isn't the location of where it was before. I know I need to offset it but I don't really understand how. I've been looking at http://stackoverflow...nd-pivot-tetris for a bit but nothing is clicking for me at the moment and my brain is getting fried thinking about it.
Can anyone tell me the steps to get the output I want or help explain how to do this? Maybe I need some time to think on that post but right now my brain is NOT working! =/
Here is what my rotation looks like for a line

**#* **** *#** ****
**#* **** *#** ####
**#* #### *#** ****
**#* **** *#** ****

That is exactly how it's showing on my playing field when I rotate, you can see the piece will move slightly when rotated. How do I fix this? Do I adjust my rotation algorithm or do I leave the rotation alone and offset it somehow when I'm drawing it/using it in the game?


This was one of the reasons I didn't bother with rotation algorithms when I tried tetris. I programmed a certain number of states into each shape (4 for the T, and both Ls, 2 for the Z pieces and the line, and 1 for the square) and had the "rotate" button just change states. Primitive? Perhaps, but it achieved the desired result. I like the elegance of the approach you are taking, but functionally I think it creates more problems than it's worth.

If you want to go the matrix route, the general method is to "translate the origin", i.e. since a cardinal rotation matrix rotates about a single world axis passing through the world origin (0,0), and you want to rotate about the point p, you'll temporarily make point p the origin, then rotate, and then translate back. In matrix math, using the M*v convention, the formula is M = T(p) * R * T(-p), where T(p) translates by the point p, and R is the original rotation matrix about the origin.

Alternatively, and what might be easier, just manually compute the offsets you want to perform after each rotation, and store them in some precomputed table.


Can you show me an example? Is there any way I can use the matrix I already get from rotating and offset that somehow or is this the only way?

This topic is closed to new replies.

Advertisement