#### Archived

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

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

This topic is 5616 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 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 on other sites
I think I worked out the 3d index in to a 1d array problem:

size_t Index = (a_X * m_Dimensions.x * m_Dimensions.z) + (a_Z * m_Dimensions.z) + a_Y;

Chris Brodie
http:\\fourth.flipcode.com

1. 1
2. 2
Rutin
21
3. 3
4. 4
frob
17
5. 5

• 9
• 12
• 9
• 33
• 13
• ### Forum Statistics

• Total Topics
632595
• Total Posts
3007267

×