I want to evaluate the values of the surface to implement a marching tetrahedron algorithm, but I don\'t understand how to work with .raw unformatted data.
After lo
The way you'd index the datum at (x, y, z) is:
pVolume[((x * 256) + y) * 256 + z]
Behind the scenes, this is what the C compiler does for you if you write:
GLuByte array[256][256][256];
array[x][y][z]
It only works that simply because C indexes from 0; if the language indexed from 1, you'd have to revise the calculation to achieve the net result obtained by subtracting one from each of x, y and z before doing the indexing.
Can you generalize the formula for arbitrary dimensions?
Given (where the numeric values don't really matter):
DIMx = 256
DIMy = 128
DIMz = 64
the datum at (x, y, z) in 1D array pData
is found at:
pData[((x * DIMx) + y) * DIMy + z]
The value of DIMz serves primarily for validation: 0 <= z < DIMz
(using mathematical rather than C notation), and in parallel 0 <= x < DIMx; 0 <= y <= DIMy
. The C notation for z
is 0 <= z && z < DIMz
; repeat mutatis mutandis for x
and y
.