Memory positions assume the object X format is 338.
REM ==========================================================================
REM Parameters:
REM matrix number
REM tile X (grid-based coordinate)
REM tile Z (grid-based coordinate)
REM nx,ny,nz - normal
function set_matrix_normal(number as integer, tile_x as integer, tile_z as integer, nx as float, ny as float, nz as float)
if tile_x < 0 OR tile_x > matrix(number).xsegs OR tile_z < 0 OR tile_z > matrix(number).zsegs
exitfunction
endif
size = 36
boffset = size*6
numb_verts = matrix(number).xsegs * matrix(number).zsegs * 6
total_size = numb_verts*size + 12
tile_size_x# = width/matrix(number).xsegs
tile_size_z# = height/matrix(number).zsegs
mem_numb = matrix(number).mem_numb
lensize = matrix(number).xsegs*boffset
REM verts 3 and 5
if tile_x > 0 and tile_z > 0
gx = tile_x - 1
gz = tile_z - 1
location = gz*lensize + gx*boffset + 12
write memblock float mem_numb, location+84, nx
write memblock float mem_numb, location+88, ny
write memblock float mem_numb, location+92, nz
write memblock float mem_numb, location+156, nx
write memblock float mem_numb, location+160, ny
write memblock float mem_numb, location+164, nz
endif
REM vert 2
if tile_z > 0 and tile_x < matrix(number).xsegs
gx = tile_x
gz = tile_z - 1
location = gz*lensize + gx*boffset + 12
write memblock float mem_numb, location+48, nx
write memblock float mem_numb, location+52, ny
write memblock float mem_numb, location+56, nz
endif
rem vert 6
if tile_x > 0 and tile_z < matrix(number).zsegs
gx = tile_x - 1
gz = tile_z
location = gz*lensize + gx*boffset + 12
write memblock float mem_numb, location+192, nx
write memblock float mem_numb, location+196, ny
write memblock float mem_numb, location+200, nz
endif
rem verts 1 and 4
if tile_x < matrix(number).xsegs and tile_z < matrix(number).zsegs
gx = tile_x
gz = tile_z
location = gz*lensize + gx*boffset + 12
write memblock float mem_numb, location+12, nx
write memblock float mem_numb, location+16, ny
write memblock float mem_numb, location+20, nz
write memblock float mem_numb, location+120, nx
write memblock float mem_numb, location+124, ny
write memblock float mem_numb, location+128, nz
endif
endfunction
"eureka" - Archimedes