Archived

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

gimp

How do I use [] in to a 3d array?

Recommended Posts

I feel silly asking this: I have a 3 dimensional bitmap struture stored as a simple 1d array for simplicity. I''m attempting to access the pixels like this: return m_Data[(a_X * m_Dimensions.x) * (a_Z * m_Dimensions.z) + a_Y]; But this doesn''t work that way I anticipated, if either X or Z are 0 Y writes to the same memory area. How is this done? Is there an easier way? Perhaps some way of making this work: bool* Data = new[x][y][z]; then bool a = Data[x][y][z]; Is this at all possible? Stick to a single dimenstional array and do the math myself? Chris Brodie http:\\fourth.flipcode.com

Share this post


Link to post
Share on other sites
to do a 3D array will be kind of a pain:

bool *** m_Data;
m_Data = new bool**[XDimension];
for(int i = 0; i < XDimension; ++i)
{
m_Data[ i ] = new bool * [YDimension];
for(int j = 0; j < YDimension; ++i)
{
m_Data[ i ][j] = new bool[ZDimension];
}
}

as you can see, deleting will also be a pain...

[edited by - billybob on May 6, 2003 10:09:30 PM]

[edited by - billybob on May 6, 2003 10:15:42 PM]

Share this post


Link to post
Share on other sites
billybob: i think hes asking how to access objects in the array with 3 numbers. hmmm... i know you can access an object with 2 numbers like this:

array[x*y+width]=array[x][y];

maybe something like array[x*y*z+width+length]?



doh, nuts. Mmmm... donuts
My website

[edited by - brassfish89 on May 6, 2003 10:16:48 PM]

Share this post


Link to post
Share on other sites