Translating 3-dimensional array reference onto 1-dimensional array

Posted by user146780 on Stack Overflow See other posts from Stack Overflow or by user146780
Published on 2010-06-08T15:39:29Z Indexed on 2010/06/08 16:22 UTC
Read the original article Hit count: 218

Filed under:
|

If there is an array of ar[5000] then how could I find where element [5][5][4] would be if this was a 3 dimensional array? Thanks

I'm mapping pixels: imagine a bimap of [768 * 1024 * 4] where would pixel [5][5][4] be?

I want to make this:

static GLubyte checkImage[checkImageHeight][checkImageWidth][4];

static GLuint texName;
bool itt;
void makeCheckImage(void)
{
    Bitmap *b = new Bitmap(L"c:/boo.png");

    int i, j, c;
    Color cul;

    for (i = 0; i < checkImageHeight; i++) {
        for (j = 0; j < checkImageWidth; j++) {
            b->GetPixel(j,i,&cul);


            checkImage[i][j][0] = (GLubyte) cul.GetR();
            checkImage[i][j][1] = (GLubyte) cul.GetG();
            checkImage[i][j][2] = (GLubyte) cul.GetB();
            checkImage[i][j][3] = (GLubyte) cul.GetA();
        }
    }
    delete(b);
}

work without making a multidimensional array. width = 512, height = 1024....

© Stack Overflow or respective owner

Related posts about c++

Related posts about c