1

Topic: Convert 1D to 2D

Hi!

Ok.. i hace this question... How i can pass the Unidimensial Array 'TILES' to 2D coords??



2D to 1D
** ny*mMap.w+nx ***

int nx = clamp(static_cast<int>(POSX)/32, 0, mMap.w-1);
int ny = clamp(static_cast<int>(POSY)/32, 0, mMap.h-1);

tTiles[ny*mMap.w+nx].index

1D to 2D  (This Not Works) ¿How i can make it??

    for (int i=0; i<mMap.w*mMap.h; i++)
    {
            vec2 posTileMap;
            posTileMap.x = i;
            posTileMap.y = int(i/mMap.w);
            if (i > mMap.w)
                posTileMap.x-=mMap.w*posTileMap.y;
    }


thx!

2

Re: Convert 1D to 2D

The reverse of :

int i = y * width + x;

is :

int x = i % width;
int y = i / width;

3

Re: Convert 1D to 2D

ascii wrote:

¿How i can make it??

Funny from somebody whose name is "ascii" big_smile

Not Luck, Just Magic.

4

Re: Convert 1D to 2D

Thx choupom.. finally i use:

            posTileMap.x = i % mMap.w *32;
            posTileMap.y = i / mMap.w *32;

Close Topic smile