Here is a code snippet for setting normals. It assumes that you have an array for your height values called land(x,x):
rem setup ranges for the matrix
range=step#*size
rem Create matrix
make matrix 1,range,range,size,size
rem set heights and generate_normals
for x=1 to Size
for z=1 to Size
rem set heights
set matrix height 1,x,z,land(x,z)
rem create regular normals for Terrain array
rem Verteces on the matrix
rem x-1,z-1 x,z-1
rem x-1,z x,z
rem Get stored heights
h8#=land(x,z-1)
h4#=land(x-1,z)
h1#=land(x,z)
rem Calculate projected angle X using heights
y1#=h1#
y2#=h4#
rem X distance is a function of step#
dx#=step#/10
rem Y distance is the difference in height
dy#=y2#-y1#
ax#=atanfull(dx#,dy#)
ax#=wrapvalue(90-ax#)
rem Calculate projected angle Z using heights
y1#=h1#
y2#=h8#
rem Z distance is a function of step#
dz#=step#/10
rem Y distance is the difference in height
dy#=y2#-y1#
az#=atanfull(dz#,dy#)
az#=wrapvalue(90-az#)
rem calculate point coordinates based on X and Z angles
nx#=sin(ax#)
ny#=cos(ax#)
nz#=sin(az#)
rem set the projected point for the normal
set matrix normal 1,x,z,nx#,ny#,nz#
next x
next z
The Yellow Jester does not play but gently pulls the strings
And smiles as the puppets dance in the court of the Crimson King.