woohoo, i got classic again!
All I had to do from my code above was change the memblock number and now it works in classic. Also, resolution must be 32-bit. A different version must be written for 16-bit.
REM ===================
REM heightmap to matrix
REM coded by: Phaelax
REM ===================
set display mode 800,600,32
sync on
autocam off
load image "terrain\sand.bmp", 1
load image "heightmap_01.bmp", 2
rem number of matrix tiles
xsegs = 50
zsegs = 50
rem create a matrix
make matrix 1, 4000,4000,xsegs, zsegs
prepare matrix texture 1,1,1,1
rem create an image memblock from the heightmap
make memblock from image 255, 2
rem get the image's dimensions
width = memblock dword(255, 0)
height = memblock dword(255, 4)
rem convert integer variables to floats
xsegs# = xsegs+1
zsegs# = zsegs+1
rem pixel offset for configuring match between pixel and tile number
ox# = width/xsegs#
oz# = height/zsegs#
rem max height of matrix
max# = 500
rem get pixel color from image location matching corresponding tile coordinates
for z = 0 to zsegs-1
for x = 0 to xsegs-1
location = (int(z*oz#)*width + int(x*ox#))*4 + 12
c = memblock byte(255, location)
rem convert color value into height value
h# = (c*max#)/255.0
set matrix height 1,x,z,h#
next x
next z
delete memblock 255
gosub matrix_normals
update matrix 1
DO
gosub camera_stuff
set cursor 0,0
print cy#
print c
sync
LOOP
camera_stuff:
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#*-1)
cz#=newzvalue(cz#,a#,speed#*-1)
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
if shiftkey() then inc cy#, 2
if controlkey() then dec cy#, 2
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(1,cx#,cz#)
position camera cx#,cy#+50,cz#
rotate camera wrapvalue(cxa#),a#,0
RETURN
matrix_normals:
rem Use matrix normals to make it smooth
for z=1 to zsegs-1
for x=1 to xsegs-1
rem Get matrix heights
h8#=get matrix height(1,x,z-1)
h4#=get matrix height(1,x-1,z)
h#=get matrix height(1,x,z)
h2#=get matrix height(1,x,z)
rem Calculate projected angle X using heights
x1#=(x-1)*25.0 : y1#=h#
x2#=(x+0)*25.0 : y2#=h4#
dx#=x2#-x1#
dy#=y2#-y1#
ax#=atanfull(dx#,dy#)
ax#=wrapvalue(90-ax#)
rem Calculate projected angle Z using heights
z1#=(z-1)*25.0 : y1#=h2#
z2#=(z+0)*25.0 : y2#=h8#
dz#=z2#-z1#
dy#=y2#-y1#
az#=atanfull(dz#,dy#)
az#=wrapvalue(90-az#)
rem Make normal from projected angle
nx#=sin(ax#)
ny#=cos(ax#)
nz#=sin(az#)
rem Setting matrix normal for smoothness
set matrix normal 1,x,z,nx#,ny#,nz#
next x
next z
RETURN
"eureka" - Archimedes
