Jump to content
  • Advertisement

Archived

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

Jonoxon

Rotating a 2D Array...

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

If I have a 4x4 array: 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1 How do I rotate the data so that I end up with this: 0 0 0 0 1 0 0 0 1 0 0 0 1 1 0 0 Any help would be much appreciated, I've tried several things, but none seem to work. Jonoxon [edited by - Jonoxon on September 16, 2002 9:13:30 AM]

Share this post


Link to post
Share on other sites
Advertisement
Simply read each row as a colum instead.
If you read the last first, then the second last etc you''ll have it rotated as you wish:

0000
1000
1000
1100

Share this post


Link to post
Share on other sites
To understand how and why that works, look up matrix transposition.



"With my feet upon the ground I lose myself between the sounds and open wide to suck it in, I feel it move across my skin. I''m reaching up and reaching out. I''m reaching for the random or what ever will bewilder me, what ever will bewilder me. And following our will and wind we may just go where no one''s been. We''ll ride the spiral to the end and may just go where no one''s been." - Maynard James Keenan
[TheBlackJester ]
[Wildfire Studios ]

Share this post


Link to post
Share on other sites
OK, here's what I did, in C++ (it works)


  
int temp[4][4];

int k=3;
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
temp[i][j]=CurrentTet[j][k];
}
k--;
}

//Here I do collision checking, making sure that the rotation is valid etc.


for(i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
CurrentTet[i][j] = temp[i][j];
}
}


The reason I want to do this transform is for something that no programmer would be complete without, my first Tetris clone. This function rotates the tetraminoes 90 degrees.

Jonoxon

[edited by - Jonoxon on September 16, 2002 12:01:01 PM]

Share this post


Link to post
Share on other sites
It is not the tranpose of the matrix.
For example the (3,4) entry, a 1, should be at (4,3) in the tranpose. But it isn''t, there''s a zero there. The transpose would be:
0000
0001
0001
0011

Share this post


Link to post
Share on other sites
The one I have works just fine. If you look you will see that I have a transposed matrix that has been mirrored(transposition causes the data to be mirrored anyway, so mirroring is necessary to maintain the original shape)


Mirror | Transpose
0 0 0 0 | 0 0 0 0
1 0 0 0 | 0 0 0 1
1 0 0 0 | 0 0 0 1
1 1 0 0 | 0 0 1 1



Jonoxon

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!