• Check out the results of the Techtree Contest #19!
  • Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

dimensional arrays

Status
Not open for further replies.
Hello! Every array in the physics memory (1d, 2d, 3d etc) are placed linear. And why you create 3 dimensional array in c++ for example, elements for this array will placed as
0,0,0 ; 1,0,0 ; .... mx-1,0,0; 0,1,0; 1,1,0; ... mx-1,1,0; etc...

the basic formula for poly dimensially arrays to transfer this to 1-dimensially array (or physics memory) for 2 and 3 dimensions:

El[0] ... El[ma] - linear array (for example, this is your map array of any type)

mx - x dimension of array you need to make
my - y dimension of array you need to make
mz - z dimension of array you need to make

for 2 dimensions ma = (mx * my - 1)
for 3 dimensions ma = (mx * my * mz - 1)

register your El array with "ma" elements and use for access this formulas:

for element x,y of 2d array you need to get El[a] element where a = x + y*mx

for element x,y,z of 3d array you need to get El[a] element where a = x + y*mx + z*my*mx




for example, u need array with mx=2, my=3, mz=4. ma = mx*my*mz-1 = 23. 23 is the max index, but not dimension of linear array; really dimension is 24. and for access to element 0,0,0 you need to access El[0]; for access to 1,2,3 you need to access El[23]; for access to 1,0,2 you need to access El[13]


Note that all coordinates in this formulas are started with 0, not with 1! if you want to first index 1, you must replace all x,y and z with (x-1), (y-1),(z-1) and add +1 to all formulas

sorry for my bad english
 
WRONG BITСH

multidimensional arrays in c++ are represented by buffers of data scattered randomly and pointers to them. char m[10] will take 10 bytes. char n[10][20] will take 20x10 bytes for data, not necessarily continuous, AND 10x4 bytes for pointers. n[4] will be a pointer to array of 20 chars.
 
lol.
i only were want to help human with his problem in warcraft map. by for c++ you right, i was error, because i wasnt program c++ too long...
but my formulas are right and question is fully closed :P
 
I would rather not jimmy-rig 3 or 2 1 dimension arrays into a simulation of a 2 dimensional array, that just doesn’t sound efficient

what is the point of my spell working, if the game lags ?

There should be a text box in the variable options that changes the dimension of your array.
 
Status
Not open for further replies.
Back
Top