Here is my take on moulding a matrix from a heightmap, To make the matrix look smooth increase the variable blur factor.
Rem Project: Matrix test
Rem Created: 28/01/2003 15:31:57
Rem ***** Main Source File *****
sync on
sync rate 60
hide mouse
rem ****************************************************************************************
rem Setup Code ****************************************************************************
`variables
largest_value#=0.0
scale_factor#=0.0
max_matrix_height#=100.0
bitmapheight=51
bitmapwidth=51
matrix_scale=10
movespeed#=10.0
`INC the blur_factor for a smoother terrain
blur_factor=1
`arrays and types
dim matrix_vertex_height(bitmapheight-1, bitmapwidth-1) as float
dim smooth_height(bitmapheight-1, bitmapwidth-1) as float
dim height_value(5) as float
`load media
load bitmap "map.bmp", 1
load image "map.bmp", 1
rem ****************************************************************************************
rem ****************************************************************************************
rem ****************************************************************************************
rem extract heights from bitmap and place into an array ************************************
`set bitmap to heigtmap
set current bitmap 1
lock pixels
`extract data row by row (invert m to get correct orientation)
for n=0 to bitmapheight-1
for m=0 to bitmapwidth-1
matrix_vertex_height(n, (bitmapwidth-1)-m)=point(n, m)
if matrix_vertex_height(n, (bitmapwidth-1)-m) > largest_value# then largest_value#=matrix_vertex_height(n, (bitmapwidth-1)-m)
next m
next n
unlock pixels
delete bitmap 1
rem ****************************************************************************************
rem ****************************************************************************************
rem ****************************************************************************************
rem blur the heights to make matrix look smooth ********************************************
for o=1 to blur_factor
for n=0 to bitmapheight-1
for m=0 to bitmapwidth-1
height_value(1)=matrix_vertex_height(n, m)
height_value(2)=matrix_vertex_height(n+1, m)
height_value(3)=matrix_vertex_height(n, m+1)
height_value(4)=matrix_vertex_height(n-1, m)
height_value(5)=matrix_vertex_height(n, m-1)
if n=0 then height_value(4)=matrix_vertex_height(n, m)
if n=bitmapheight-1 then height_value(2)=matrix_vertex_height(n, m)
if m=0 then height_value(5)=matrix_vertex_height(n, m)
if m=bitmapwidth-1 then height_value(3)=matrix_vertex_height(n, m)
smooth_height(n, m)=(height_value(1)+ height_value(2) + height_value(3) + height_value(4) + height_value(5))/5.0
next m
next n
`transfer smoothed values back to matrix vertex height
for n=0 to bitmapheight-1
for m=0 to bitmapwidth-1
matrix_vertex_height(n, m)=smooth_height(n, m)
next m
next n
next o
rem ****************************************************************************************
rem ****************************************************************************************
rem ****************************************************************************************
rem make a matrix and position all the vertice based upon heights in array *****************
`firstly find scale factor for matrix
scale_factor#=largest_value#/max_matrix_height#
for n=0 to bitmapheight-1
for m=0 to bitmapwidth-1
matrix_vertex_height(n, m)=matrix_vertex_height(n, m)/scale_factor#
next m
next n
`make matrix
make matrix 1, bitmapwidth*matrix_scale, bitmapheight*matrix_scale, bitmapwidth-1, bitmapheight-1
`set heights
for n=0 to bitmapheight-1
for m=0 to bitmapwidth-1
set matrix height 1, n, m, matrix_vertex_height(n, m)
next m
next n
`update the matrix
update matrix 1
rem ****************************************************************************************
rem ****************************************************************************************
rem ****************************************************************************************
rem Simple Viewing loop ********************************************************************
do
if mouseclick()=1 then move camera movespeed#
if mouseclick()=2 then move camera -1.0*movespeed#
yrotate camera 0, camera angle y(0)+ mousemovex()
xrotate camera 0, camera angle x(0)+ mousemovey()
`paste height image
paste image 1, 0, 0
sync
loop
rem ****************************************************************************************
rem ****************************************************************************************
Specs:- 1GHZ athlon, Radeon8500, 192mb ram, winxp