I'm making Tetris in Java and am at the point of rotations... Originally I was hardcoding each rotation:
if (direction.equals("right")) {
if (shape.equals("Bar")) {
if (rotationsCounter == 0) {
currXs[0] += 1;
currYs[0] += -1;
currXs[1] += 0;
currYs[1] += 0;
currXs[2] += -1;
currYs[2] += 1;
currXs[3] += -2;
currYs[3] += 2;
rightRotate1 = new int[] {currXs[0], currYs[0], currXs[1], currYs[1], currXs[2], currYs[2], currXs[3], currYs[3]};
}
if (rotationsCounter == 1) {
etc...
Then, I have this to set the correct coordinates based on what the rotated counter is
if (direction == "right") {
if (shape == "Bar") {
if (rotationsCounter == 0) {
pieceRotations = rightRotate1;
}
if (rotationsCounter == 1) {
pieceRotations = rightRotate2;
}
if (rotationsCounter == 2) {
pieceRotations = rightRotate3;
}
if (rotationsCounter == 3) {
pieceRotations = rightRotate0;
}
}
}
if (direction == "left") {
if (shape == "Bar") {
if (rotationsCounter == 0) {
pieceRotations = leftRotate3;
}
if (rotationsCounter == 3) {
pieceRotations = leftRotate2;
}
if (rotationsCounter == 2) {
pieceRotations = leftRotate1;
}
if (rotationsCounter == 1) {
pieceRotations = leftRotate0;
}
}
}
return pieceRotations;
But found that was a very tedious way to go...
People suggested I use rotation matrices in Linear Algebra.
So I tried rotating 1 coordinate in a Tetris piece just to see if I was doing it correctly... the point (1, 1) seems to rotate just fine...
So then I thought that the way to rotate the whole block was to get all the coordinates of each tile in a Piece (4 tiles, 16 coordinates), and rotate each one... but I was wrong.
So my questions is...
In the first picture, I choose (1, 1) as my rotation axis... How do I move the rest of the coordinates in relation to that point?
Thanks!