Originally Posted by
ChrisW67
You want to transpose the matrix. You can do this crudely by making an element by element copy into a new set of nested vectors.
I had actually been trying to do this before I posted here. Its so hard to keep track of exactly what is going on when you have pointers to pointers to pointers so I couldn't tell if I was doing it right, etc. Ended up going out of town and just now getting back to working on this again, but here is the code that I've been trying to use to transpose the matrix, see anything that looks incorrect?
QVector< QVector<MapSpace> > temp;
QVector< QVector<MapSpace> >* builder;
temp.resize(gamemap.grid_x);
for (int i = 0; i <= gamemap.grid_x-1; i++) //this for loop just making the size of temp right. gamemap.grid_x is the size of the x axis, subtract 1 for 0th row
temp[i].resize(gamemap.grid_y); //gamemap.grid_y is the size of the y axis
for (int i = 0; i <= gamemap.grid_y-1; i++)
{
MapSpace* temp2 = (*builder)[i].data(); //builder is already assigned to 2D matrix previously
for (int j = 0; j <= gamemap.grid_x-1; j++)
temp[i][j] = temp2[j];
}
builder = &temp; //reassigning builder to the newly transposed matrix
QVector< QVector<MapSpace> > temp;
QVector< QVector<MapSpace> >* builder;
temp.resize(gamemap.grid_x);
for (int i = 0; i <= gamemap.grid_x-1; i++) //this for loop just making the size of temp right. gamemap.grid_x is the size of the x axis, subtract 1 for 0th row
temp[i].resize(gamemap.grid_y); //gamemap.grid_y is the size of the y axis
for (int i = 0; i <= gamemap.grid_y-1; i++)
{
MapSpace* temp2 = (*builder)[i].data(); //builder is already assigned to 2D matrix previously
for (int j = 0; j <= gamemap.grid_x-1; j++)
temp[i][j] = temp2[j];
}
builder = &temp; //reassigning builder to the newly transposed matrix
To copy to clipboard, switch view to plain text mode
@anda_skoa
I had originally built everything thinking that would work just fine, but the called function works in a column by column fashion that cannot properly execute when the x and y values are simply swapped. The rows of the flipped matrices need to be operated on one at a time, which cannot occur by simply swapping the x and y values.
Bookmarks