Apologies if I'm on the wrong track here and you already knew this, but here's a visual example of normalization 'in action':
+ Code SnippetGosub Setup
Do
CX#=Camera Angle X(): CY#=Camera Angle Y(): CZ#=Camera Angle Z()
CY#=Wrapvalue(CY#+mousemovex())
CX#=Wrapvalue(CX#+mousemovey())
Rotate Camera CX#,CY#,CZ#
If MouseClick()=1 Then Move Camera 10
If MouseClick()=2 Then Move Camera -10
If Scancode() Then Normalise(1)
Sync
Center Text 400,5,"Press Any Key To Apply Normalization"
Loop
Rem **************************************************
Rem Smooth Matrix
Rem **************************************************
Smooth:
Rem Averages matrix heights to remove jagged edges
for Z=0 to 70
for X=0 to 70
P0#=Get Matrix Height(1,X,Z): Rem Current point height
Rem Get 4 adjoining points heights (if they exist)
If Z-1>=0
P1#=Get Matrix Height(1,X,Z-1)
Else
P1#=P0#
Endif
If X+1<=TilesX
P2#=Get Matrix Height(1,X+1,Z)
Else
P2#=P0#
Endif
If Z+1<=TilesZ
P3#=Get Matrix Height(1,X,Z+1)
Else
P3#=P0#
Endif
If X-1>=0
P4#=Get Matrix Height(1,X-1,Z)
Else
P4#=P0#
Endif
Average#=(P0#+P1#+P2#+P3#+P4#)/5: Rem Av height of other points
RHeight#=Average#
Set Matrix Height 1,x,z,RHeight#
Next x
Next z
Update Matrix 1
Return
Setup:
Set Display Mode 800,600,32
Sync On: Sync Rate 0: CLS 0: Sync
AutoCam Off
Set Camera Range 1.0, 100000.0
Hide Mouse
Create Bitmap 1,1024,1024
Rem ********************
Rem Matrix Texture
Rem ********************
Ink RGB(0,110,0),0
Box 0,0,1023,1023
For N=1 To 15000
Ink RGB(0,Rnd(150)+50,0),0
Dot Rnd(512),Rnd(512)
Next N
Blur Bitmap 1,1
Sync
Get Image 100,0,0,512,512,1
Sync
Rem ********************
Rem Matrix
Rem ********************
Make Matrix 1,7000,7000,70,70: Rem 1 Tile = 100
Prepare Matrix Texture 1,100,70,70
Randomize Matrix 1,2000.0
For N=1 To 40
X=Rnd(66)+2: Z=Rnd(66)+2
Set Matrix Height 1,X,Z,7000.0
Next N
For N=1 To 15
Gosub Smooth
Next N
t=1
For z=69 to 0 Step -1
For x=0 to 69
Set Matrix Tile 1,x,z,t
Inc t
Next x
Next z
Update Matrix 1
Set Current Bitmap 0
Delete Bitmap 1
Position Camera 0,3000,0
Point Camera 3500,0,3500
Ink RGB(255,255,255),0
Return
Rem *********************************************************
Rem *** FUNCTIONS ***
Rem *********************************************************
Function Normalise(MatNum)
Rem By Lee Bamber From DB Example - Adds shaded areas to matrix to give depth
For z=1 to 70
For x=1 to 70
h8#=get matrix height(MatNum,x,z-1)
h4#=get matrix height(MatNum,x-1,z)
h#=get matrix height(MatNum,x,z)
h2#=get matrix height(MatNum,x,z)
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#)
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#)
nx#=sin(ax#)
ny#=cos(ax#)
nz#=sin(az#)
Set matrix normal MatNum,x,z,nx#,ny#,nz#
next x
next z
Update Matrix MatNum
EndFunction