Jump to content
  • Advertisement

Archived

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

Filip

matrices

This topic is 5531 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

Does anyone have an idea how to rotate a matrix(2d array in respect with c++).I have an 2d char array filled with various caharcters,letters and other.I need to rotate it 90 degrees to right.So i figured i would do this: void rot() { for(int a=0;aLink

Share this post


Link to post
Share on other sites
Advertisement
Your 2D matrix must be of quadratic size, like 10x10 or 20x20, orelse you''ll need more complex code to make up for the losses.


char data[64] // 8x8 array

char destination[64] // 8x8 destination array, we don''t wanna screw up the source data


// For each row

for (int y=0; y<8; y++) {

// For each column

for (int x=0; x<8; x++) {

// "Rotate"

destination[y*8+x] = data[x*8+(7-y)];
}
}


I know this is not mathematicly done, but if you want to do things fast, cheat :-)

(I hope I did it right

Albert

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!