Buchempfehlung
MySQL kurz & gut
MySQL kurz & gut
Das preiswerte Taschen- buch stellt MySQL-rele- vante Inhalte systematisch und knapp dar, sodass es sich optimal zum Nach- schlagen beim Pro- grammieren eignet. [Mehr Infos...]
FreeBASIC-Chat
Es sind Benutzer im FreeBASIC-Chat online.
(Stand:  )
FreeBASIC bei Twitter
Twitter FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!

fb:porticula NoPaste

Info
Info / Hilfe
Liste
Übersicht / Liste
Neu
Datei hochladen
Suche
Quellcode suchen
Download
Dateidownload

Bumpmap rekursiv

Uploader:MitgliedMuttonhead
Datum/Zeit:23.04.2008 20:22:41

' erzeugt rekursiv (grayscale)Bumpmaps
' kann man in Raytracern und Renderern wie POVRAY oder Blender benutzen um Gebirge zu erzeugen
' Kritik an muttonhead@hotmail.de

DECLARE sub calcbump (xfirst as integer ,xlast as integer ,yfirst as integer ,ylast as integer,submode as integer)

Dim as integer i,k,l,gray,xlow,ylow,xhigh,yhigh
 xlow=0
 ylow=0
 xhigh=600
 yhigh=600

'werden von calcbump benötigt
'bumpfield array enthält die "Hoehendaten"
'bumplevel ist die vertikale Auflösung (255 entspricht 256 Graustufen)
dim shared as integer bumpfield(xhigh,yhigh) , bumplevel
bumplevel=255



screen 20,8,1
if screenptr then
    color 0,255
    for i=0 to 255
        palette i,i,i,i
    next i
    randomize timer
'berechnen des Hoehenfeldes
  calcbump (xlow,xhigh,ylow,yhigh,1)

' gespiegelte Anzeige des ganzen
   for k=yhigh to ylow step-1
        for i=xlow to xhigh
            gray=255*bumpfield(i,k)/bumplevel
            pset(i,yhigh-k),gray
        next i
    next k

  beep
    sleep
else
    print "Sorry, no Screen available! Press any key..."
    sleep
end if


sub calcbump (xfirst as integer ,xlast as integer ,yfirst as integer ,ylast as integer,submode as integer)
    static as single diff0
    dim as integer diffx,diffz,xmiddle,ymiddle,_
                                 north,east,south,west,center,_
                                 i,k,l
    dim as single randlevel


    diffx  =xlast-xfirst
    diffz  =ylast-yfirst

' beim ersten Aufruf wird das ganze array geloescht
' es geht mit Sicherheit eleganter als mit FOR NEXT, ist halt alte Schule (MaxonBasic);)
    if submode=1 then
        for i=xfirst to xlast
            for k=yfirst to ylast
                bumpfield(i,k)=-1
            next k
        next i

        bumpfield(xfirst,yfirst)=rnd*bumplevel
        bumpfield(xfirst,ylast)=rnd*bumplevel
        bumpfield(xlast,ylast)=rnd*bumplevel
        bumpfield(xlast,yfirst)=rnd*bumplevel

        diff0=(diffx+diffz)/2
    end if

    randlevel=((diffx+diffz)/2)/diff0*bumplevel

  if diffx>1 and diffz>1 then

        west=(bumpfield(xfirst,yfirst)+bumpfield(xfirst,ylast))/2 + (sgn(rnd-.5)*randlevel)
        if west>bumplevel then west=bumplevel
    if west<0 then west=0

        north=(bumpfield(xfirst,ylast)+bumpfield(xlast,ylast))/2 + (sgn(rnd-.5)*randlevel)
        if north>bumplevel then north=bumplevel
    if north<0 then north=0

        east=(bumpfield(xlast,ylast)+bumpfield(xlast,yfirst))/2 + (sgn(rnd-.5)*randlevel)
        if east>bumplevel then east=bumplevel
    if east<0 then east=0

        south=(bumpfield(xlast,yfirst)+bumpfield(xfirst,yfirst))/2 + (sgn(rnd-.5)*randlevel)
        if south>bumplevel then south=bumplevel
    if south<0 then south=0

        xmiddle=xfirst+(diffx/2)
        ymiddle=yfirst+(diffz/2)

' mit Mörder-Mapping Effekt, nicht zu empfehlen
'       bumpfield(xfirst,ymiddle)=west
'   bumpfield(xmiddle,ylast)=north
'       bumpfield(xlast,ymiddle)=east
'       bumpfield(xmiddle,yfirst)=south

' sieht was besser aus...
        if bumpfield(xfirst,ymiddle)=-1 then bumpfield(xfirst,ymiddle)=west
        if bumpfield(xmiddle,ylast)=-1 then bumpfield(xmiddle,ylast)=north
        if bumpfield(xlast,ymiddle)=-1 then bumpfield(xlast,ymiddle)=east
        if bumpfield(xmiddle,yfirst)=-1 then bumpfield(xmiddle,yfirst)=south

    center=(bumpfield(xfirst,yfirst)+bumpfield(xfirst,ylast)+bumpfield(xlast,ylast)+bumpfield(xlast,yfirst))/4 + (sgn(rnd-.5)*randlevel)
        if center>bumplevel then center=bumplevel
    if center<0 then center=0

        bumpfield(xmiddle,ymiddle)=center

        calcbump(xfirst,xmiddle,yfirst,ymiddle,0)
    calcbump(xfirst,xmiddle,ymiddle,ylast,0)
        calcbump(xmiddle,xlast,ymiddle,ylast,0)
        calcbump(xmiddle,xlast,yfirst,ymiddle,0)


    end if

    if diffx>1 and diffz<2 then

        north=(bumpfield(xfirst,ylast)+bumpfield(xlast,ylast))/2 + (sgn(rnd-.5)*randlevel)
        if north>bumplevel then north=bumplevel
    if north<0 then north=0

        south=(bumpfield(xfirst,yfirst)+bumpfield(xlast,yfirst))/2 + (sgn(rnd-.5)*randlevel)
        if south>bumplevel then south=bumplevel
    if south<0 then south=0

        xmiddle=xfirst+(diffx/2)

        if bumpfield(xmiddle,ylast)=-1 then bumpfield(xmiddle,ylast)=north
        if bumpfield(xmiddle,yfirst)=-1 then bumpfield(xmiddle,yfirst)=south

        calcbump(xfirst,xmiddle,yfirst,ylast,0)
        calcbump(xmiddle,xlast,yfirst,ylast,0)
    end if

    if diffx<2 and diffz>1 then

        west=(bumpfield(xfirst,yfirst)+bumpfield(xfirst,ylast))/2 + (sgn(rnd-.5)*randlevel)
        if west>bumplevel then west=bumplevel
    if west<0 then west=0

        east=(bumpfield(xlast,yfirst)+bumpfield(xlast,ylast))/2 + (sgn(rnd-.5)*randlevel)
        if east>bumplevel then east=bumplevel
    if east<0 then east=0

        ymiddle=yfirst+(diffz/2)

        if bumpfield(xfirst,ymiddle)=-1 then bumpfield(xfirst,ymiddle)=west
        if bumpfield(xlast,ymiddle)=-1 then bumpfield(xlast,ymiddle)=east

        calcbump(xfirst,xlast,yfirst,ymiddle,0)
        calcbump(xfirst,xlast,ymiddle,ylast,0)
    end if
end sub