Public Group

#### Archived

This topic is now archived and is closed to further replies.

# Rotating - The Basic 2d Rotation

This topic is 5202 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a Array int b[6][6],sx,sy; sx = 3; sy = 3; // Thus b[1][1] Will not rotate Now i want the entire array to rotate 90 degrees ect... b[0][0] ---> b[2][0] b[0][2] ---> b[0][0] b[2][2] ---> b[0][2] b[2][0] ---> b[2][2] But that is only if it is a 3,3 Object stored,s if its a 2,2 then b[0][0] --->b[1][0] b[1][0] --->b[1][1] b[1][1] --->b[0][1] b[0][1] --->b[1][0] I dont need the Physical entries to change just there positions eg Block[b[0][0].X = 1 * cos(angle) Block[b[0][0].Y = 1 * sin(angle) Please help -- its for tetris game

##### Share on other sites
I didn''t quite get what you were asking for...

I think for a tetris game (only 90° rotations needed) I''d actually rotate only at drawing time... you could allocate a 4x4 array for every kind of piece there is and rotate it on the fly.

---

Sebastian Beschke
Just some student from Germany
http://mitglied.lycos.de/xplosiff

##### Share on other sites
i would agree with you but since i am trying to get a nice rotation effect, Say
vector b[3][3]

you would rotate it like this
gameLoop
{
angle++
loop; i++;
{
loop; l++
{
sizex = i - 1; // in this case,-1,0,1
sizey = l - 1;
b[l].x = sizex*cos(angle);
b[i][l].y = sizey*sin(angle);
}
}
}

I need to rotate those X+Y as if the middle of the array is the middpoint

##### Share on other sites
To rotate 90 degrees:

y = old_x;
x = block_height - old_y;

See:
[x0][x1][x2][x3][y1][y2][y3]
Rotate:
[y3][y2][y1][x0]            [x1]            [x2]            [x3]
Run the peice through a loop and modify x and y like this to rotate 90 degrees to the right. To rotate 180:

y = block_height - old_y;
x = block_width - old_x;

Do you understand? I can explain further

EDIT: Are you trying to do smooth transition rotation? If so, my example won't work. If not, you don't need sin & cos.

[edited by - Jiia on March 26, 2004 3:47:23 PM]

##### Share on other sites
quote:
I need to rotate those X+Y as if the middle of the array is the middpoint
Then you should either make them zero (and use offsets for each other point), or draw them by using an origin. If you subtract the location of the points you want to make the origin from every other point, they are now the origin.

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 10
• 11
• 37
• 12
• 12
• ### Forum Statistics

• Total Topics
631414
• Total Posts
2999958
×