i cannot stress enough how LARGE these landscapes can be. it takes almost 10 minutes to get from one side to the other.
i WAS making an RPG, and i've managed to get my landscaper working (GeoBreeze). it uses a dynamic matrix (96x96) which refreshes as you traverse the landscape, which is 2017x2017 segs.
media:
look here
http://www.geocities.com/sixurbanninjas/download.html near the middle of the page, under "GeoBreeze"
unzip these into the same directory with the source.
thanks to phaelax for the memblock matrix code
here's the source:
set display mode 800,600,32
randomize timer()
show mouse
sync on
rem fog on
fog color rgb(0, 0, 0)
fog distance 2600
autocam off
backdrop on
color backdrop rgb(0, 0, 0)
set camera range 1, 6000
type matrixtype
ix as integer
iy as integer
xsegs as integer
zsegs as integer
width as float
depth as float
mem_numb as integer
obj as integer
image as integer
mesh as integer
prepared as boolean
x as float
y as float
z as float
cull as integer
light as integer
specular as integer
endtype
type mousetype
movex as integer
movey as integer
click as integer
xpos as integer
ypos as integer
zpos as integer
oldzpos as integer
endtype
type cameratype
xang as float
yang as float
zang as float
xpos as float
ypos as float
zpos as float
endtype
type worldtype
worldwidth as integer
worlddepth as integer
currsegx as integer
currsegz as integer
lastsegx as integer
lastsegz as integer
maxmapsx as integer
maxmapsz as integer
mx as integer
mz as integer
sizex# as float
sizez# as float
tilewh as integer
endtype
type widgettype
worldxpos as float
worldypos as float
worldzpos as float
currxseg as integer
currzseg as integer
brushsize as integer
brushtype as integer
endtype
type stacktype
endtype
dim matrix(1) as matrixtype
dim mouse(1) as mousetype
dim camera(1) as cameratype
dim world(1) as worldtype
dim widget(1) as widgettype
rem load image "sand.bmp", 2
rem load image "hmap.bmp", 3
load image "grass.bmp", 1
rem load image "ash.bmp", 3
make object cube 100, 100
set object wireframe 100, 1
rem disable object zdepth 100
rem ghost object on 100
null = make vector3(1)
world(1).maxmapsx=21
world(1).maxmapsz=21
world(1).mx = 96
world(1).mz = 96
world(1).tilewh = 100
world(1).sizex# = world(1).mx*world(1).tilewh
world(1).sizez# = world(1).mz*world(1).tilewh
world(1).worldwidth=world(1).sizex#*world(1).maxmapsx
world(1).worlddepth=world(1).sizez#*world(1).maxmapsz
widget(1).brushsize=1
widget(1).brushtype=1
rem makelandscapedb()
rem savelandscapedbtofile("oldwest01.lnd")
rem setuplandscape()
prepare_matrix_data(1,1,1,1)
create_matrix(1,world(1).sizex#, world(1).sizez#, world(1).mx, world(1).mz)
prepare_matrix_texture(1,1,1,1)
rem set_matrix_from_heightmap(1,3,250.0)
rem set_matrix_from_colormap(1,2)
rem set_matrix_from_alphamap(1,4)
configure_matrix_normals(1)
set_matrix_light(1,0)
set_matrix_specular(1,0)
rem scale_matrix_texture(1,8,8)
loadlandscapedbfromfile("hmap.dat", 2017, 2017)
update_matrix(1)
rem initial camera position
checkinput()
widgetstuff()
textout()
updatelandscape(0)
position camera world(1).tilewh, world(1).tilewh, world(1).tilewh
sync
do
checkinput()
widgetstuff()
textout()
loop
function checkinput()
getcamvalues()
cx#=camera(1).xpos
cy#=camera(1).ypos
cz#=camera(1).zpos
oldcx#=cx#
oldcy#=cy#
oldcz#=cz#
cxa#=camera(1).xang
cya#=camera(1).yang
mouse(1).movey=mousemovex()
mouse(1).movex=mousemovey()
mouse(1).xpos=mousex()
mouse(1).ypos=mousey()
mouse(1).zpos=mousez()
mouse(1).click=mouseclick()
speed# = 20
if keystate(16)=1
cy#=cy#-10
endif
if keystate(18)=1
cy#=cy#+10
endif
if keystate(17)=1
cx#=newxvalue(cx#,cya#,speed#)
cz#=newzvalue(cz#,cya#,speed#)
updatelandscape(0)
endif
if keystate(31)=1
cx#=newxvalue(cx#,cya#,-speed#)
cz#=newzvalue(cz#,cya#,-speed#)
updatelandscape(0)
endif
if keystate(30)=1
cx#=newxvalue(cx#,wrapvalue(cya#-90.0),speed#)
cz#=newzvalue(cz#,wrapvalue(cya#-90.0),speed#)
updatelandscape(0)
endif
if keystate(32)=1
cx#=newxvalue(cx#,wrapvalue(cya#+90.0),speed#)
cz#=newzvalue(cz#,wrapvalue(cya#+90.0),speed#)
updatelandscape(0)
endif
if mouse(1).movex<>0 and mouse(1).click=4
cxa#=wrapvalue(cxa#+mouse(1).movex)
endif
if mouse(1).movey<>0 and mouse(1).click=4
cya#=wrapvalue(cya#+mouse(1).movey)
endif
if mouse(1).zpos<mouse(1).oldzpos
if keystate(48)=1 and widget(1).brushtype>1 then widget(1).brushtype=widget(1).brushtype-1
if keystate(48)=0 and widget(1).brushsize>1 then widget(1).brushsize=widget(1).brushsize-1
endif
if mouse(1).zpos>mouse(1).oldzpos
if keystate(48)=1 and widget(1).brushtype<3 then widget(1).brushtype=widget(1).brushtype+1
if keystate(48)=0 and widget(1).brushsize<100 then widget(1).brushsize=widget(1).brushsize+1
endif
select mouse(1).click
case 0
endcase
case 1
editverticiesaroundwidget(widget(1).brushtype, widget(1).brushsize)
endcase
case 2
editverticiesaroundwidget( widget(1).brushtype, widget(1).brushsize)
endcase
endselect
select scancode()
case 45
rem "Z" key
endcase
case 44
rem "X" key
endcase
case 21
rem "Y" key
endcase
case 60
rem "F2" key
savelandscapedbtofile("hmap.dat")
endcase
case 61
rem "F2" key
loadlandscapedbfromfile("hmap.dat", 2017, 2017)
endcase
case 62
rem "F3" key
endcase
endselect
mouse(1).oldzpos=mouse(1).zpos
position camera cx#, cy#, cz#
rotate camera cxa#, cya#, 0
endfunction
function getcamvalues()
camera(1).xang=camera angle x()
camera(1).yang=camera angle y()
camera(1).xpos=camera position x()
camera(1).ypos=camera position y()
camera(1).zpos=camera position z()
endfunction
function textout()
text 2, 2, "Camera XAngle:"+str$(int(camera(1).xang))+" YAngle:"+str$(int(camera(1).yang))+" XPos:"+str$(camera(1).xpos)+" YPos:"+str$(camera(1).ypos)+" ZPos:"+str$(camera(1).zpos)
text 2, 15, "WidgetX:"+str$(camera(1).xpos + x vector3(1))+" WidgetY:"+str$(camera(1).ypos + y vector3(1))+" WidgetZ:"+str$(camera(1).zpos + z vector3(1))
text 2, 28, "CurrXSeg:"+str$(world(1).currsegx)+" CurrZSeg:"+str$(world(1).currsegz)
text 2, 41, "WidgetLocalX:"+str$(widget(1).currxseg)+" WidgetLocalZ:"+str$(widget(1).currzseg)
text 2, 54, "Scancode:"+str$(scancode())+" MouseClick:"+str$(mouse(1).click)+" MouseZpos:"+str$(mouse(1).zpos)+" FPS:"+str$(screen fps())+" POLYS:"+str$(statistic(1))
text 2, 67, "BrushType:"+str$(widget(1).brushtype)+" BrushSize:"+str$(widget(1).brushsize)
sync
endfunction
function debug(textout$)
do
text 2, 2, textout$
sync
if spacekey()=1 then exit
loop
do
if spacekey()=0 then exit
loop
endfunction
function prepare_matrix_data(number as integer, object as integer, mb as integer, mesh as integer)
matrix(number).obj = object
matrix(number).mem_numb = mb
matrix(number).mesh = mesh
endfunction
function scale_matrix_texture(number as integer, across as integer, down as integer)
matrix(number).ix = across
matrix(number).iy = down
matrix(number).prepared = 1
tile = 1
ln = 0
for z = matrix(number).zsegs to 1 step -1
for x = 1 to matrix(number).xsegs
tl = ln*across + tile
set_matrix_tile(number, x, z, tl)
inc tile, 1
if tile > across then tile = 1
next x
inc ln, 1
if ln > down-1 then ln = 0
next z
endfunction
function prepare_matrix_texture(number as integer, image as integer, across as integer, down as integer)
rem image=rnd(3)
matrix(number).ix = across
matrix(number).iy = down
matrix(number).image = image
matrix(number).prepared = 1
for z = 1 to matrix(number).zsegs
for x = 1 to matrix(number).xsegs
image=rnd(3)
set_matrix_tile(number, x, z, image)
next x
next z
endfunction
function create_matrix(number as integer, width as float, depth as float, xsegs as integer, zsegs as integer)
fvf = 338
size = 36
matrix(number).width = width
matrix(number).depth = depth
matrix(number).xsegs = xsegs
matrix(number).zsegs = zsegs
numb_verts = matrix(number).xsegs * matrix(number).zsegs * 6
total_size = numb_verts*size + 12
tile_size_x# = width/matrix(number).xsegs
tile_size_z# = depth/matrix(number).zsegs
mem_numb = matrix(number).mem_numb
make memblock mem_numb, total_size
write memblock dword mem_numb, 0, fvf
write memblock dword mem_numb, 4, size
write memblock dword mem_numb, 8, numb_verts
tile = 0
for z = 1 to zsegs
for x = 1 to xsegs
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, diffuse color
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, 0
write memblock float mem_numb, location+16, 1
write memblock float mem_numb, location+20, 0
write memblock dword mem_numb, location+24, rgb(255,255,255)
rem vert 2 - x,y,z
temp_size = size
write memblock float mem_numb, location+temp_size, x2#
write memblock float mem_numb, location+temp_size+4, y2#
write memblock float mem_numb, location+temp_size+8, z2#
write memblock float mem_numb, location+temp_size+12, 0
write memblock float mem_numb, location+temp_size+16, 1
write memblock float mem_numb, location+temp_size+20, 0
write memblock dword mem_numb, location+temp_size+24, rgb(255,255,255)
rem vert 3 - x,y,z
temp_size = size*2
write memblock float mem_numb, location+temp_size, x3#
write memblock float mem_numb, location+temp_size+4, y3#
write memblock float mem_numb, location+temp_size+8, z3#
write memblock float mem_numb, location+temp_size+12, 0
write memblock float mem_numb, location+temp_size+16, 1
write memblock float mem_numb, location+temp_size+20, 0
write memblock dword mem_numb, location+temp_size+24, rgb(255,255,255)
rem vert 4 - x,y,z
temp_size = size*3
write memblock float mem_numb, location+temp_size, x4#
write memblock float mem_numb, location+temp_size+4, y4#
write memblock float mem_numb, location+temp_size+8, z4#
write memblock float mem_numb, location+temp_size+12, 0
write memblock float mem_numb, location+temp_size+16, 1
write memblock float mem_numb, location+temp_size+20, 0
write memblock dword mem_numb, location+temp_size+24, rgb(255,255,255)
rem vert 5 - x,y,z
temp_size = size*4
write memblock float mem_numb, location+temp_size, x5#
write memblock float mem_numb, location+temp_size+4, y5#
write memblock float mem_numb, location+temp_size+8, z5#
write memblock float mem_numb, location+temp_size+12, 0
write memblock float mem_numb, location+temp_size+16, 1
write memblock float mem_numb, location+temp_size+20, 0
write memblock dword mem_numb, location+temp_size+24, rgb(255,255,255)
rem vert 6 - x,y,z
temp_size = size*5
write memblock float mem_numb, location+temp_size, x6#
write memblock float mem_numb, location+temp_size+4, y6#
write memblock float mem_numb, location+temp_size+8, z6#
write memblock float mem_numb, location+temp_size+12, 0
write memblock float mem_numb, location+temp_size+16, 1
write memblock float mem_numb, location+temp_size+20, 0
write memblock dword mem_numb, location+temp_size+24, rgb(255,255,255)
inc tile, 1
next x
next z
make mesh from memblock 1, mem_numb
make object matrix(number).obj,1,0
endfunction
function set_matrix_tile(number as integer, tileX as integer, tileZ as integer, tile as integer)
if tileX < 0 OR tileX > matrix(number).xsegs OR tileX < 0 OR tileZ > matrix(number).zsegs OR matrix(number).prepared = 0
exitfunction
endif
if matrix(number).ix = 0 then matrix(number).ix = 1
if matrix(number).iy = 0 then matrix(number).iy = 1
mem_numb = matrix(number).mem_numb
size = 36
boffset = size*6
location = 12 + ((tileZ-1)*matrix(number).xsegs*boffset + (tileX-1)*boffset)
x_temp = wrap(tile, matrix(number).ix)
mix# = matrix(number).ix
x_max# = x_temp/mix#
x_min# = (x_temp-1)/mix#
y_temp = int((tile - x_temp) / mix#) + 1.0
miy# = matrix(number).iy
y_max# = y_temp/miy#
y_min# = (y_temp-1)/miy#
if y_min# > 0 then y_min# = y_min# + 0.01
if x_min# > 0 then x_min# = x_min# + 0.01
rem vert 1 - UV coordinates
write memblock float mem_numb, location+28, x_min#
write memblock float mem_numb, location+32, y_max#
rem vert 2
write memblock float mem_numb, location+64, x_min#
write memblock float mem_numb, location+68, y_min#
rem vert 3
write memblock float mem_numb, location+100, x_max#
write memblock float mem_numb, location+104, y_min#
rem vert 4
write memblock float mem_numb, location+136, x_min#
write memblock float mem_numb, location+140, y_max#
rem vert 5
write memblock float mem_numb, location+172, x_max#
write memblock float mem_numb, location+176, y_min#
rem vert 6
write memblock float mem_numb, location+208, x_max#
write memblock float mem_numb, location+212, y_max#
endfunction
function set_matrix_diffuse(number as integer, tile_x as integer, tile_z as integer, color as dword)
if tile_x < 0 OR tile_x > matrix(number).xsegs OR tile_z < 0 OR tile_z > matrix(number).zsegs
exitfunction
endif
size = 36
boffset = size*6
numb_verts = matrix(number).xsegs * matrix(number).zsegs * 6
total_size = numb_verts*size + 12
tile_size_x# = width/matrix(number).xsegs
tile_size_z# = height/matrix(number).zsegs
mem_numb = matrix(number).mem_numb
lensize = matrix(number).xsegs*boffset
REM verts 3 and 5
if tile_x > 0 and tile_z > 0
gx = tile_x - 1
gz = tile_z - 1
location = gz*lensize + gx*boffset + 12
write memblock dword mem_numb, location+96, color
write memblock dword mem_numb, location+168, color
endif
REM vert 2
if tile_z > 0 and tile_x < matrix(number).xsegs
gx = tile_x
gz = tile_z - 1
location = gz*lensize + gx*boffset + 12
write memblock dword mem_numb, location+60, color
endif
rem vert 6
if tile_x > 0 and tile_z < matrix(number).zsegs
gx = tile_x - 1
gz = tile_z
location = gz*lensize + gx*boffset + 12
write memblock dword mem_numb, location+204, color
endif
rem verts 1 and 4
if tile_x < matrix(number).xsegs and tile_z < matrix(number).zsegs
gx = tile_x
gz = tile_z
location = gz*lensize + gx*boffset + 12
write memblock dword mem_numb, location+24, color
write memblock dword mem_numb, location+132, color
endif
endfunction
function set_matrix_alpha(number as integer, tile_x as integer, tile_z as integer, alpha as integer)
if tile_x < 0 OR tile_x > matrix(number).xsegs OR tile_z < 0 OR tile_z > matrix(number).zsegs
exitfunction
endif
size = 36
boffset = size*6
numb_verts = matrix(number).xsegs * matrix(number).zsegs * 6
total_size = numb_verts*size + 12
tile_size_x# = width/matrix(number).xsegs
tile_size_z# = height/matrix(number).zsegs
mem_numb = matrix(number).mem_numb
lensize = matrix(number).xsegs*boffset
REM verts 3 and 5
if tile_x > 0 and tile_z > 0
gx = tile_x - 1
gz = tile_z - 1
location = gz*lensize + gx*boffset + 12
write memblock dword mem_numb, location+99, alpha
write memblock dword mem_numb, location+171, alpha
endif
REM vert 2
if tile_z > 0 and tile_x < matrix(number).xsegs
gx = tile_x
gz = tile_z - 1
location = gz*lensize + gx*boffset + 12
write memblock dword mem_numb, location+63, alpha
endif
rem vert 6
if tile_x > 0 and tile_z < matrix(number).zsegs
gx = tile_x - 1
gz = tile_z
location = gz*lensize + gx*boffset + 12
write memblock dword mem_numb, location+207, alpha
endif
rem verts 1 and 4
if tile_x < matrix(number).xsegs and tile_z < matrix(number).zsegs
gx = tile_x
gz = tile_z
location = gz*lensize + gx*boffset + 12
write memblock dword mem_numb, location+27, alpha
write memblock dword mem_numb, location+135, alpha
endif
endfunction
function set_matrix_height(number as integer, tile_x as integer, tile_z as integer, height# as float)
if tile_x < 0 OR tile_x > matrix(number).xsegs OR tile_z < 0 OR tile_z > matrix(number).zsegs
exitfunction
endif
size = 36
boffset = size*6
numb_verts = matrix(number).xsegs * matrix(number).zsegs * 6
total_size = numb_verts*size + 12
tile_size_x# = width/matrix(number).xsegs
tile_size_z# = height/matrix(number).zsegs
mem_numb = matrix(number).mem_numb
lensize = matrix(number).xsegs*boffset
REM verts 3 and 5
if tile_x > 0 and tile_z > 0
gx = tile_x - 1
gz = tile_z - 1
location = gz*lensize + gx*boffset + 12
write memblock float mem_numb, location+76, height#
write memblock float mem_numb, location+148, height#
endif
REM vert 2
if tile_z > 0 and tile_x < matrix(number).xsegs
gx = tile_x
gz = tile_z - 1
location = gz*lensize + gx*boffset + 12
write memblock float mem_numb, location+40, height#
endif
rem vert 6
if tile_x > 0 and tile_z < matrix(number).zsegs
`and tile_z < matrix(number).zsegs
gx = tile_x - 1
gz = tile_z
location = gz*lensize + gx*boffset + 12
write memblock float mem_numb, location+184, height#
endif
rem verts 1 and 4
if tile_x < matrix(number).xsegs and tile_z < matrix(number).zsegs
gx = tile_x
gz = tile_z
location = gz*lensize + gx*boffset + 12
write memblock float mem_numb, location+4, height#
write memblock float mem_numb, location+112, height#
endif
endfunction
function set_matrix_normal(number as integer, tile_x as integer, tile_z as integer, nx as float, ny as float, nz as float)
if tile_x < 0 OR tile_x > matrix(number).xsegs OR tile_z < 0 OR tile_z > matrix(number).zsegs
exitfunction
endif
size = 36
boffset = size*6
numb_verts = matrix(number).xsegs * matrix(number).zsegs * 6
total_size = numb_verts*size + 12
tile_size_x# = width/matrix(number).xsegs
tile_size_z# = height/matrix(number).zsegs
mem_numb = matrix(number).mem_numb
lensize = matrix(number).xsegs*boffset
REM verts 3 and 5
if tile_x > 0 and tile_z > 0
gx = tile_x - 1
gz = tile_z - 1
location = gz*lensize + gx*boffset + 12
write memblock float mem_numb, location+84, nx
write memblock float mem_numb, location+88, ny
write memblock float mem_numb, location+92, nz
write memblock float mem_numb, location+156, nx
write memblock float mem_numb, location+160, ny
write memblock float mem_numb, location+164, nz
endif
REM vert 2
if tile_z > 0 and tile_x < matrix(number).xsegs
gx = tile_x
gz = tile_z - 1
location = gz*lensize + gx*boffset + 12
write memblock float mem_numb, location+48, nx
write memblock float mem_numb, location+52, ny
write memblock float mem_numb, location+56, nz
endif
rem vert 6
if tile_x > 0 and tile_z < matrix(number).zsegs
gx = tile_x - 1
gz = tile_z
location = gz*lensize + gx*boffset + 12
write memblock float mem_numb, location+192, nx
write memblock float mem_numb, location+196, ny
write memblock float mem_numb, location+200, nz
endif
rem verts 1 and 4
if tile_x < matrix(number).xsegs and tile_z < matrix(number).zsegs
gx = tile_x
gz = tile_z
location = gz*lensize + gx*boffset + 12
write memblock float mem_numb, location+12, nx
write memblock float mem_numb, location+16, ny
write memblock float mem_numb, location+20, nz
write memblock float mem_numb, location+120, nx
write memblock float mem_numb, location+124, ny
write memblock float mem_numb, location+128, nz
endif
endfunction
function get_ground_height( number as integer, x#, z#)
tileSizeX# = matrix(number).width / matrix(number).xsegs
tileSizeZ# = matrix(number).depth / matrix(number).zsegs
row = (z# / tileSizeZ#)
column = (x# / tileSizeX#)
if row < 0 OR row > matrix(number).xsegs OR column < 0 or column > matrix(number).zsegs
exitfunction 0.0
endif
h1# = get_matrix_height(number, row, column)
h2# = get_matrix_height(number, row, column+1)
h3# = get_matrix_height(number, row+1, column+1)
h4# = get_matrix_height(number, row+1, column)
ahx# = ((h4#-h1#)+(h3#-h2#)) / 2.0
ahz# = ((h2#-h1#)+(h3#-h4#)) / 2.0
avg# = (ahx# + ahz#) / 2.0
xx# = x# mod tileSizeX#
zz# = z# mod tileSizeZ#
ax# = (xx# * ahx#) / tileSizeX#
az# = (zz# * ahz#) / tileSizeZ#
height# = (ax# + az#) / 2.0
endfunction height#
function get_matrix_height(number as integer, tile_x as integer, tile_z as integer)
if tile_x < 0 OR tile_x > matrix(number).xsegs OR tile_z < 0 OR tile_z > matrix(number).zsegs
exitfunction
endif
size = 36
boffset = size*6
numb_verts = matrix(number).xsegs * matrix(number).zsegs * 6
total_size = numb_verts*size + 12
tile_size_x# = width/matrix(number).xsegs
tile_size_z# = height/matrix(number).zsegs
mem_numb = matrix(number).mem_numb
lensize = matrix(number).xsegs*boffset
if tile_x < matrix(number).xsegs and tile_z < matrix(number).zsegs
location = tile_z*lensize + tile_x*boffset + 12
yheight# = memblock float (mem_numb, location+4)
else
location = (tile_z-1)*lensize + (tile_x-1)*boffset + 12
yheight# = memblock float (mem_numb, location+76)
endif
endfunction yheight#
function set_matrix_from_memblockdb(number as integer, xseg as integer, zseg as integer, max as float)
xsegs = (world(1).maxmapsx*world(1).mx)
zsegs = (world(1).maxmapsz*world(1).mz)
xorigin = ((xseg-2)*world(1).maxmapsx)
zorigin = ((zseg-2)*world(1).maxmapsx)
for x = 0 to world(1).mx
for z = 0 to world(1).mz
offset = ((zorigin + z) * (zsegs+1)) + (xorigin + x)
if offset>-1 and offset<(xsegs*zsegs)
c = memblock byte(255, offset)
else
c=0
endif
h# = (c*max)/255.0
set_matrix_height(number,x,z,h#*50)
inc offset
next z
offset=offset+xsegs
next x
endfunction
function set_matrix_from_heightmap(number as integer, img as integer, max as float)
make memblock from image 256, img
width# = memblock dword(256, 0)
height# = memblock dword(256, 4)
ox# = width#/(matrix(number).xsegs+1)
oz# = height#/(matrix(number).zsegs+1)
for z = 0 to matrix(number).zsegs
for x = 0 to matrix(number).xsegs
location = (int(z*oz#)*width# + int(x*ox#))*4 + 12
c = memblock byte(256, location)
rem convert color value into height value
h# = (c*max)/255.0
set_matrix_height(number,x,z,h#)
next x
next z
delete memblock 256
endfunction
function set_matrix_from_colormap(number as integer, img as integer)
make memblock from image 256, img
width# = memblock dword(256, 0)
height# = memblock dword(256, 4)
ox# = width#/(matrix(number).xsegs+1)
oz# = height#/(matrix(number).zsegs+1)
for z = 0 to matrix(number).zsegs
for x = 0 to matrix(number).xsegs
location = (int(z*oz#)*width# + int(x*ox#))*4 + 12
b = memblock byte(256, location)
g = memblock byte(256, location+1)
r = memblock byte(256, location+2)
c = rgb(r,g,b)
set_matrix_diffuse(number,x,z,c)
next x
next z
delete memblock 256
endfunction
function set_matrix_from_alphamap(number as integer, img as integer)
make memblock from image 256, img
width# = memblock dword(256, 0)
height# = memblock dword(256, 4)
ox# = width#/(matrix(number).xsegs+1)
oz# = height#/(matrix(number).zsegs+1)
for z = 0 to matrix(number).zsegs
for x = 0 to matrix(number).xsegs
location = (int(z*oz#)*width# + int(x*ox#))*4 + 12
a = memblock byte(256, location+3)
set_matrix_alpha(number,x,z,a)
next x
next z
delete memblock 256
endfunction
function position_matrix(number as integer, x as float, y as float, z as float)
matrix(number).x = x
matrix(number).y = y
matrix(number).z = z
position object matrix(number).obj, x, y, z
endfunction
function update_matrix(number as integer)
change mesh from memblock matrix(number).mesh, matrix(number).mem_numb
delete object matrix(number).obj
make object matrix(number).obj, matrix(number).mesh, matrix(number).image
set object cull matrix(number).obj, matrix(number).cull
set object light matrix(number).obj, matrix(number).light
set object specular matrix(number).obj, matrix(number).specular
position object matrix(number).obj, matrix(number).x, matrix(number).y, matrix(number).z
if matrix(number).prepared = 0
set object wireframe matrix(number).obj, 1
endif
endfunction
function set_matrix_cull(number as integer, flag as integer)
matrix(number).cull = flag
set object cull matrix(number).obj, flag
endfunction
function set_matrix_light(number as integer, flag as integer)
matrix(number).light = flag
set object light matrix(number).obj, flag
endfunction
function set_matrix_specular(number as integer, flag as integer)
matrix(number).specular = flag
set object specular matrix(number).obj, flag
endfunction
function configure_matrix_normals(number as integer)
for z=1 to matrix(number).zsegs-1
for x=1 to matrix(number).xsegs-1
rem Get matrix heights
h8#=get_matrix_height(number,x,z-1)
h4#=get_matrix_height(number,x-1,z)
h#=get_matrix_height(number,x,z)
h2#=get_matrix_height(number,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(number,x,z,nx#,ny#,nz#)
next x
next z
endfunction
function pick_matrix(number as integer, x as integer, y as integer, vector as integer)
if matrix(number).obj = 0 then exitfunction
t = pick object(x,y,matrix(number).obj,matrix(number).obj)
vx# = camera().xpos+get pick vector x()
vy# = camera().ypos+get pick vector y()
vz# = camera().zpos+get pick vector z()
set vector3 vector, vx#, vy#, vz#
endfunction
function wrap(n1#,n2#)
while (n1# > n2#)
n1# = n1# - n2#
endwhile
endfunction n1#
function updatelandscape(forcerefresh)
world(1).currsegx=int((camera(1).xpos/(world(1).maxmapsx*world(1).tilewh))+1)
world(1).currsegz=int((camera(1).zpos/(world(1).maxmapsx*world(1).tilewh))+1)
if world(1).currsegx=world(1).lastsegx and world(1).currsegz=world(1).lastsegz and forcerefresh=0 then exitfunction
cx=world(1).currsegx
cz=world(1).currsegz
set_matrix_from_memblockdb(1, cx, cz, 200.0)
update_matrix(1)
position_matrix(1, (cx-2)*(world(1).maxmapsx*world(1).tilewh), object position y(1), (cz-2)*(world(1).maxmapsx*world(1).tilewh))
world(1).lastsegx=world(1).currsegx
world(1).lastsegz=world(1).currsegz
endfunction
function widgetstuff()
pick_matrix(1, mouse(1).xpos, mouse(1).ypos, 1)
widget(1).worldxpos=camera(1).xpos + x vector3(1)
widget(1).worldypos=camera(1).ypos + y vector3(1)
widget(1).worldzpos=camera(1).zpos + z vector3(1)
widget(1).currxseg=int((widget(1).worldxpos - matrix(number).x)/world(1).tilewh)
widget(1).currzseg=int((widget(1).worldzpos - matrix(number).z)/world(1).tilewh)
scale object 100, (widget(1).brushsize)*world(1).tilewh, 10000, (widget(1).brushsize)*world(1).tilewh
position object 100, widget(1).worldxpos+(((widget(1).brushsize)*world(1).tilewh)/2), widget(1).worldypos, widget(1).worldzpos+(((widget(1).brushsize)*world(1).tilewh)/2)
fade object 100, (widget(1).brushsize*100)
endfunction
function makelandscapedb()
make memblock from image 256, 3
make memblock 255, ((world(1).maxmapsz*world(1).mz)+1)*((world(1).maxmapsx*world(1).mx)+1)
width# = memblock dword(256, 0)
height# = memblock dword(256, 4)
offset=0
location=12
for z = 0 to (world(1).maxmapsz*world(1).mz)
for x = 0 to (world(1).maxmapsx*world(1).mx)
c = memblock byte(256, location)
location = location + 4
write memblock byte 255, offset, c
inc offset
next x
next z
delete memblock 256
endfunction
function savelandscapedbtofile(filename$)
if file exist(filename$)=1 then delete file filename$
dboffset=0
open to write 1, filename$
for z = 0 to ((world(1).maxmapsz*world(1).mz))
for x = 0 to ((world(1).maxmapsx*world(1).mx))
h=memblock byte(255, dboffset)
write byte 1, h
inc dboffset
next x
next z
close file 1
endfunction
function loadlandscapedbfromfile(filename$, xsize, zsize)
if memblock exist(255)=0 then make memblock 255, (xsize * zsize)
if file exist(filename$)=0 then exitfunction
if file exist(filename$)=1 then open to read 1, filename$
offset=0
for z = 0 to ((world(1).maxmapsz*world(1).mz))
for x = 0 to ((world(1).maxmapsx*world(1).mx))
read byte 1, h
write memblock byte 255, offset, h
inc offset
next x
next z
close file 1
update_matrix(1)
updatelandscape(1)
endfunction
function editverticiesaroundwidget(brushtype, brushsize)
select brushtype
case 1
for vz=0 to brushsize - 1
for vx=0 to brushsize - 1
editvx=widget(1).currxseg+vx
editvz=widget(1).currzseg+vz
offset = (editvz * ((world(1).maxmapsx*world(1).mz)+1)) + editvx
if mouse(1).click=1
if offset>=0 and offset<=(2017*2017)
oh=memblock byte(255, offset)
if oh<255 then inc oh
write memblock byte 255, offset, oh
endif
endif
if mouse(1).click=2
if offset>=0 and offset<=(2017*2017)
oh=memblock byte(255, offset)
if oh>0 then dec oh
write memblock byte 255, offset, oh
endif
endif
next vx
next vz
update_matrix(1)
updatelandscape(1)
endcase
case 2
for vz=0 to brushsize - 1
for vx=0 to brushsize - 1
editvx=widget(1).currxseg+vx
editvz=widget(1).currzseg+vz
offset = (editvz * ((world(1).maxmapsx*world(1).mz)+1)) + editvx
av=0
offset1 = ((editvz-1) * ((world(1).maxmapsx*world(1).mz)+1)) + (editvx)
if offset1>=0 and offset1<=(2017*2017)
down=memblock byte(255, offset1)
inc av
else
down=0
endif
offset2 = ((editvz) * ((world(1).maxmapsx*world(1).mz)+1)) + (editvx-1)
if offset2>=0 and offset2<=(2017*2017)
left=memblock byte(255, offset2)
inc av
else
left=0
endif
offset3 = ((editvz) * ((world(1).maxmapsx*world(1).mz)+1)) + (editvx+1)
if offset3>=0 and offset3<=(2017*2017)
right=memblock byte(255, offset3)
inc av
else
right=0
endif
offset4 = ((editvz+1) * ((world(1).maxmapsx*world(1).mz)+1)) + (editvx)
if offset4>=0 and offset4<=(2017*2017)
up=memblock byte(255, offset4)
inc av
else
up=0
endif
nh=int((up+down+left+right)/av)
if offset>=0 and offset<=(2017*2017)
write memblock byte 255, offset, nh
endif
next vx
next vz
update_matrix(1)
updatelandscape(1)
endcase
case 3
for vz=0 to brushsize - 1
for vx=0 to brushsize - 1
editvx=widget(1).currxseg+vx
editvz=widget(1).currzseg+vz
offset = (editvz * ((world(1).maxmapsx*world(1).mz)+1)) + editvx
if offset>=0 and offset<=(2017*2017)
ob=memblock byte(255, offset)
nb=ob+rnd(20)-10
if nb>255 then nb=255
if nb<0 then nb=0
write memblock byte 255, offset, nb
endif
next vx
next vz
update_matrix(1)
updatelandscape(1)
endcase
endselect
endfunction
keys:
push and hold mousehweel in (centerclick) - look around with camera
WSAD - move cam forward, back, left, right
QE - move cam up, down
F2 - save map to file "hmap.dat"
F3 - load file "hmap/dat"
mouse:
left/right click - raise and lower landscape around widget
scroll up/down - increase or decrease widget brush size
hold the "B" key AND scroll up/down - change brush type -> 1:height up/down 2:smooth 3:randomize
the wireframe box is the "brush"... notice when you scroll (without holding b) the mouse, the box gets bigger.
it
should run fine.
thanks again to phaelax, who supplied the memblock matrix code!
if you test it, please give feedback here!!!
"Creativity is knowing how to hide your sources" - Einstein