Archived

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

multiple coordinate systems

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

Recommended Posts

Hi all, I''m just starting out in game programming and figured that a good place to start, as suggested by a gamedev article, would be with a tetris clone. Everything''s been going alright so far, slow...but alright, with one exception...block rotation. when i go to rotate the block(i only have the bar so far) it rotates around the center of the screen. Is there any way to give it it''s own set of local axes or am i going to have to break down and find a linear algebra book somewhere? Thanks, Crimson

Share on other sites
Here is a suggestion, where you don''t need linear algebra at all.

If you have your "Pieces" data set up in a 4x4 array such as the following:

0000
0000
0000
0000

You can set up your pieces by setting the appropriate place in the array as a 1 to indicate a "fill". Fill in a color or graphic.

0000 1100 0000 0000
1111 1000 0110 0100
0000 1000 0110 1110
0000 0000 0000 0000

To rotate your block all you need to do is make a temporary array, and refill it but in a set order like the following:
1100 1110 0010 0000
1000 0010 0010 1000
1000 0000 0110 1110
0000 0000 0000 0000
1st 2nd 3rd 4th repeat

So you are mapping from one array to another
piece[x][y] -> temp[x][y]
piece[0][0] -> temp[2][0]
piece[1][0] -> temp[2][1]
piece[1][0] -> temp[2][2]
piece[3][0] -> temp[2][2] ....etc

Fiddle around with it and you can probably make a nice loop function to perform rotation

Share on other sites
Or try rotating before you translate.

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 28
• 11
• 11
• 9
• Forum Statistics

• Total Topics
631772
• Total Posts
3002260
×