I'm still trying to think of a use for this snippet. Just sort of created it as a learning experience.
Any thoughts on how I can calculate the normals?
Test results: 5000,5000,100,100
Built-in Matrix - 75fps
My Matrix - 210fps
bright = 128
for x =1 to 16
for y=1 to 16
dot x,y,rgb(bright,rnd(128)+bright,bright)
next y
next x
get image 1, 1,1,16,16
sync on
sync rate 60
autocam off
hide mouse
global xsegs
global zsegs
xsegs = 20
zsegs = 20
`make matrix 1,1000,1000,80,80
create_matrix(1000,1000)
for x = 1 to xsegs-1
for z = 1 to zsegs-1
set_matrix_height(x,z,rnd(30))
next z
next x
change mesh from memblock 1, 1
delete object 1
make object 1,1,1
`scale object texture 1,5,5
`position object 1,0,0,0
`texture object 1, 1
set object ambient 1, 0
position camera 0,100,0
point camera 0,0,300
do
gosub camera_poo
sync
loop
function create_matrix(width as float, height as float)
fvf = 274
size = 32
numb_verts = xsegs * zsegs * 6
total_size = numb_verts*size + 12
tile_size_x# = width/xsegs
tile_size_z# = height/zsegs
mem_numb = 1
make memblock mem_numb, total_size
write memblock dword mem_numb, 0, fvf
write memblock dword mem_numb, 4, 32
write memblock dword mem_numb, 8, numb_verts
tile = 0
for z = 1 to zsegs
for x = 1 to xsegs
`location = ((y-1)*xsegs + (x-1)*6) + (12 + tile*size)
location = tile*size*6 + 12
x1# = tile_size_x# * (x-1)
y1# = 0
z1# = tile_size_z# * (z-1)
x2# = tile_size_x# * (x-1)
y2# = 0
z2# = tile_size_z# * z
x3# = tile_size_x# * x
y3# = 0
z3# = tile_size_z# * z
x4# = x1#
y4# = y1#
z4# = z1#
x5# = x3#
y5# = y3#
z5# = z3#
x6# = x3#
y6# = 0
z6# = z1#
rem vert 1 - x,y,z, normals x,y,z, U, V
write memblock float mem_numb, location, x1#
write memblock float mem_numb, location+4, y1#
write memblock float mem_numb, location+8, z1#
`write memblock float mem_numb, location+12,
`write memblock float mem_numb, location+16,
`write memblock float mem_numb, location+20,
write memblock float mem_numb, location+24, 0
write memblock float mem_numb, location+28, 1
rem vert 2 - x,y,z
write memblock float mem_numb, location+32, x2#
write memblock float mem_numb, location+36, y2#
write memblock float mem_numb, location+40, z2#
`write memblock float mem_numb, location+44,
`write memblock float mem_numb, location+48,
`write memblock float mem_numb, location+52,
write memblock float mem_numb, location+56, 0
write memblock float mem_numb, location+60, 0
rem vert 3 - x,y,z
write memblock float mem_numb, location+64, x3#
write memblock float mem_numb, location+68, y3#
write memblock float mem_numb, location+72, z3#
`write memblock float mem_numb, location+76,
`write memblock float mem_numb, location+80,
`write memblock float mem_numb, location+84,
write memblock float mem_numb, location+88, 1
write memblock float mem_numb, location+92, 0
rem vert 4 - x,y,z
write memblock float mem_numb, location+96, x4#
write memblock float mem_numb, location+100, y4#
write memblock float mem_numb, location+104, z4#
`write memblock float mem_numb, location+108,
`write memblock float mem_numb, location+112,
`write memblock float mem_numb, location+116,
write memblock float mem_numb, location+120, 0
write memblock float mem_numb, location+124, 1
rem vert 5 - x,y,z
write memblock float mem_numb, location+128, x5#
write memblock float mem_numb, location+132, y5#
write memblock float mem_numb, location+136, z5#
`write memblock float mem_numb, location+140,
`write memblock float mem_numb, location+144,
`write memblock float mem_numb, location+148,
write memblock float mem_numb, location+152, 1
write memblock float mem_numb, location+156, 0
rem vert 6 - x,y,z
write memblock float mem_numb, location+160, x6#
write memblock float mem_numb, location+164, y6#
write memblock float mem_numb, location+168, z6#
`write memblock float mem_numb, location+172,
`write memblock float mem_numb, location+176,
`write memblock float mem_numb, location+180,
write memblock float mem_numb, location+184, 1
write memblock float mem_numb, location+188, 1
inc tile, 1
next x
next z
make mesh from memblock 1, mem_numb
img = 1
make object 1,1,img
endfunction
REM Tile coordinates range from 0 to number of segments minus 1
function set_matrix_height(tile_x, tile_z, height#)
if tile_x < 0 OR tile_x > xsegs OR tile_z < 0 OR tile_z > zsegs
exitfunction
endif
numb_verts = xsegs * zsegs * 6
total_size = numb_verts*size + 12
tile_size_x# = width/xsegs
tile_size_z# = height/zsegs
mem_numb = 1
lensize = xsegs*192
if tile_x > 0 and tile_z > 0
gx = tile_x - 1
gz = tile_z - 1
location = gz*lensize + gx*192 + 12
write memblock float mem_numb, location+68, height#
write memblock float mem_numb, location+132, height#
endif
if tile_z > 0
gx = tile_x
gz = tile_z - 1
location = gz*lensize + gx*192 + 12
write memblock float mem_numb, location+36, height#
endif
if tile_x > 0
gx = tile_x - 1
gz = tile_z
location = gz*lensize + gx*192 + 12
write memblock float mem_numb, location+164, height#
endif
gx = tile_x
gz = tile_z
location = gz*lensize + gx*192 + 12
write memblock float mem_numb, location+4, height#
write memblock float mem_numb, location+100, height#
endfunction
function get_ground_height(x#, z#)
h# = intersect object(1,x#,0,z#,x#,10000,z#)
endfunction h#
camera_poo:
oldcx#=cx#
oldcz#=cz#
speed# = 5
if upkey()=1
cx#=newxvalue(cx#,a#,speed#)
cz#=newzvalue(cz#,a#,speed#)
endif
if downkey()=1
cx#=newxvalue(cx#,a#,-speed#)
cz#=newzvalue(cz#,a#,-speed#)
endif
if leftkey()=1
cx#=newxvalue(cx#,wrapvalue(a#-90.0),speed#)
cz#=newzvalue(cz#,wrapvalue(a#-90.0),speed#)
endif
if rightkey()=1
cx#=newxvalue(cx#,wrapvalue(a#+90.0),speed#)
cz#=newzvalue(cz#,wrapvalue(a#+90.0),speed#)
endif
a#=wrapvalue(a#+(mousemovex()/3.0))
cxa#=cxa#+(mousemovey()/3.0)
if cxa#<-90.0 then cxa#=-90.0
if cxa#>90.0 then cxa#=90.0
cy# = get_ground_height(cx#,cz#)
position camera cx#,cy#+100,cz#
rotate camera wrapvalue(cxa#),a#,0
RETURN
"eureka" - Archimedes