Posted: 25th Jan 2004 12:47
I havent contributed to the forums for a while so Here is one of the things that I have been doing.
This Code gets the the color data from a bmp and converts it to
height data. The lighter the shade the heigher the darker the lower.



Here's the code:
http://www.freewebs.com/dboutland/Bmp_Hmap.zip
Posted: 26th Jan 2004 15:10
helo anyone there, hmm I guess it isnt usefull then LOL
Posted: 26th Jan 2004 17:43
he he he thats pritty cool code you done there v usefull for background mountins an stuff keep up the cool work he he he




dancedreemer...
Posted: 26th Jan 2004 17:50
i got a problem running your code in dbc it says "no sutch dimention initialsed at line 29"

witch is this line in your code > set matrix height 1,x,z,hmap(x,z)*3

any idears ?

dancedreemer...
Posted: 26th Jan 2004 17:51
Posted: 26th Jan 2004 23:22
it means you haven't declared the array,use
dim hmap(x,z) somewhere near the top.
Posted: 27th Jan 2004 21:58
finally!!! a very FAST function to load a heightmap in DBC thanks man, i was lookin a long time for that!
Posted: 28th Jan 2004 16:06
Heres the code corrected:


+ Code Snippet
`------------------------Coded By OutLand---------------------------
`---------------------Height Bmp to Matrix-------------------------
`This Code gets the the color data from a bmp and converts it to
`height data. The lighter the shade the heigher the darker the lower.
`I create my height Bmp's in a program called PhotoStudio2000
`They can also be made in PaintShop

`This function Get the height data from the Hmap.Bmp and saves it
`as a hmap(x,z) array. I picked up the bmp decoder off a forum a
`while back from Kevin Picone. I have cut it down to do the job
`I need it to do.

`--------------------------------------------------------------------

set display mode 1024,768,32
sync on
sync rate 0
backdrop on
color backdrop rgb(0,0,0)
set camera range 1,10000

`this array line isnt needed in dbpro only in dbc
`hmap(1) the array is re-created in the getheightbmp("hmap.bmp") function with the right values
dim hmap(1)

getheightbmp("hmap.bmp")

make matrix 1,5000,5000,70,70
for x=1 to 70
for z=1 to 70
set matrix height 1,x,z,hmap(x,z)*3
next z
next x

update matrix 1

do

rem Crude way to fix mouse pointer (hide this and run again)
position mouse 320,240

rem Use MOUSEMOVE to alter camera angles
cx#=wrapvalue(cx#+mousemovey())
cy#=wrapvalue(cy#+mousemovex())
cz#=wrapvalue(cz#+mousemovez())
rotate camera cx#,cy#,cz#

rem Simple movement
if upkey()=1 then move camera 25
if downkey()=1 then move camera -25

rem Update screen
sync
loop

function getheightbmp(file$)

`this function only gets information from a 24-bit bitmap
`so make sure you save it as one

   open to read 1,file$
`--------------------
`decode the header
`The info contained here is not usefull.
        read byte 1,notusefull
        read byte 1,notusefull
        read long 1,notusefull
        read long 1,notusefull
        read long 1,notusefull
        read long 1,notusefull

`--------------------
`Get Bitmap Width
read long 1,BmpWidth
`Get Bitmap Height
read long 1,BmpHeight
`--------------------

        read word 1,notusefull

`--------------------
`Get BitDepth
read word 1,BitDepth
`--------------------

`The info contained here is not usefull.
        read long 1,notusefull
        read long 1,notusefull
        read long 1,notusefull
        read long 1,notusefull
        read long 1,notusefull
        read long 1,notusefull
`--------------------
`error check only if bitdepth=24
if BitDepth=24

ypos=BmpHeight

` Calculate If bmp required Padding

bmpwidth#=bmpwidth
evenwidth1#=(BmpWidth#*3)/4
evenwidth2=(BmpWidth*3)/4
padlen=0
if evenwidth1#<>evenwidth2
   evenwidth1#=evenwidth1#-evenwidth2
   padlen=4-(evenwidth1#*4)
endif

`-------------------------------------------
`create the hmap array
dim hmap(bmpwidth,bmpheight)
`-------------------------------------------


`Get color info
For Ylp=1 to BmpHeight
for Xlp=1 to Bmpwidth

`Read color values
  read byte 1,blue
  read byte 1,Green
  read byte 1,red

`enter color info into height array
hmap(xlp,ypos)=(blue+green+red)/3

next Xlp

dec Ypos
`Padding
    if padlen<>0
    for padlp=1 to padlen
    read byte 1,padbyte
    next padlp
    endif

next Ylp
endif

close file 1

endfunction
Posted: 29th Jan 2004 16:22
PERFECT!

A little bit of adjustment, and this will be useable in my landscape engine.
thanks