TGC Codebase Backup



Dynamic terrain(matrix) loading by wh1sp3r

15th Mar 2004 13:36
Summary

sourcecode of dynamic loading



Description



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    CLS
sync on: sync rate 0
rem loading map, objects
load bitmap "height.bmp",1
load image "grass2.bmp",1

rem end
rem definice
Color Backdrop RGB(255,255,255)
INK rgb(0,0,0),rgb(0,0,0)

Backdrop on
set camera range 0,1,1000000000
fog off
fog color rgb(255,255,255)
fog distance 9000000

msize = 12000000
msize2 = msize / 2
tiles = 50
tsize = msize/tiles
mnum = 1
heightscale = 10000
rem end

make matrix 1,msize,msize,tiles,tiles




prepare matrix texture 1,1,1,1
set matrix 1,0,0,1,3,1,1,1
position matrix 1,-msize2,0,-msize2

position camera 10000,100,1000
rotate camera 0,0,0
hide mouse
rem init matrix start
set current bitmap 1
for tilz = 0 to tiles
for tilx = 0 to tiles

aktualheight = rgbr(point(tilx,tilz))
set matrix height 1,tilx, tilz, aktualheight*heightscale

next tilx
next tilz
set current bitmap 0
update matrix 1
rem konec
tilz = 0
tilx = 0

rem load trees

rem end

do


rem ovladani

if shiftkey()
if upkey()then move camera 1500
else
if upkey()then move camera 1000
if downkey() then move camera -15
if spacekey() then hh = hh + 100
endif

xrotate camera camera angle x() + mousemovey()*0.3
yrotate camera camera angle y() + mousemovex()*0.3
rem konec ovladani

rem refresh



cx = camera position x()
cz = camera position z()
mx = matrix position x(mnum)
mz = matrix position z(mnum)
dx=(mx+msize/2)-cx
dz=(mz+msize/2)-cz
 if dz > tsize
 shift matrix down mnum
 rem zmena vysky dolu
 set current bitmap 1

 for tilx = 0 to tiles
 Zslozka = 0 + tilez
 Xslozka = tilx + tilex
 aktualheight = rgbr(point(Xslozka,Zslozka))
 set matrix height 1,tilx, 0, aktualheight*heightscale
 next tilx

 set current bitmap 0
 rem konec
 position matrix mnum,mx,0,mz-tsize
 endif
 if dz < -tsize
 shift matrix up mnum
 rem zmena vysky nahoru
 set current bitmap 1

 for tilx = 0 to tiles
 Zslozka = tiles + tilez
 Xslozka = tilx + tilex
 aktualheight = rgbr(point(Xslozka,Zslozka))
 set matrix height 1,tilx, tiles, aktualheight*heightscale
 next tilx

 set current bitmap 0
 rem konec
 position matrix mnum,mx,0,mz+tsize
 endif
 if dx > tsize
 shift matrix right mnum
 rem zmena vysky doprava
 set current bitmap 1

 for tilz = 0 to tiles
 Zslozka = tilz + tilez
 Xslozka = 0 + tilex
 aktualheight = rgbr(point(Xslozka,Zslozka))
 set matrix height 1,0, tilz, aktualheight*heightscale
 next tilz

 set current bitmap 0
 rem konec
 position matrix mnum,mx-tsize,0,mz
 endif
 if dx < -tsize
 shift matrix left mnum
 rem zmena vysky doleva
 set current bitmap 1

 for tilz = 0 to tiles
 Zslozka = tilz + tilez
 Xslozka = tiles + tilex
 aktualheight = rgbr(point(Xslozka,Zslozka))
 set matrix height 1,tiles, tilz, aktualheight*heightscale
 next tilz

 set current bitmap 0
 rem konec
 position matrix mnum,mx+tsize,0,mz
 endif


 update matrix mnum



h#=get ground height(1,camera position x()-matrix position x(1),camera position z()-matrix position z(1))
rem konec refresh

rem pozice
posx = int(camera position x())
posz = int(camera position z())
tilex = (posx/(msize/tiles))
tilez = (posz/(msize/tiles))
rem konec pozice

rem text
position camera camera position x(),h#+18000,camera position z()

INK rgb(0,0,0),rgb(0,0,0)
TEXT 1,1, "FPS: " +str$(screen fps())
TEXT 1,10, "pozice X: "+str$(camera position x()) + "  pozice Z: "+str$(camera position z())
TEXT 1,20, "TILE X: "+str$(tilex) + "  TILE Z: "+str$(tilez)
text 1,30, "vyska: "+str$(h#)
TEXT 1,40, "POINT X: "+str$(tilx+tilex) + "  POINT Z: "+str$(tilz+tilez)
TEXT 1,50, "DZ: "+str$(dz) + "  TSIDE X: "+str$(tside)

if tilex < 0 or tilez < 0 or tilex > bitmap width(1)-1 or tilez > bitmap height(1)-1
INK rgb(255,0,0),rgb(255,0,0)
TEXT screen width()/2-100, screen height()/2,"You are in NON ZONE!!!!!"
endif
rem konec text
sync
loop