Post by Rod on Feb 28, 2021 9:43:33 GMT
bump5.bmp (101.05 KB)
My latest project. Looking for lots of advice. Bump mapping, taking an image and using it as the contour map of computer drawn terrain. In this case undersea landscape. It will be a Submarine adventure eventually.
So the bump mapping is progressing but the drawing of the landscape not so much. I need hidden line removal I think. Possible some height managment. Perhaps even a little perspective and some reduction in height of far away objects.
The code so far: Use the cursor keys to move the "view". You need to click in the undersea window first. It only moves a click at a time for now.
Please feel free to mash it up and fix it.
My latest project. Looking for lots of advice. Bump mapping, taking an image and using it as the contour map of computer drawn terrain. In this case undersea landscape. It will be a Submarine adventure eventually.
So the bump mapping is progressing but the drawing of the landscape not so much. I need hidden line removal I think. Possible some height managment. Perhaps even a little perspective and some reduction in height of far away objects.
The code so far: Use the cursor keys to move the "view". You need to click in the undersea window first. It only moves a click at a time for now.
nomainwin
WindowWidth = 800
WindowHeight = 320
UpperLeftX = (DisplayWidth-WindowWidth)/2
UpperLeftY = (DisplayHeight-WindowHeight)/2
graphicbox #1.gb, 0,0,800,320
open "3D Height Mapping" for graphics_nf_nsb as #1
#1 "trapclose [quit]"
#1.gb "down"
for n=0 to 320
#1.gb "color 0 0 ";(256/320)*(320-n)
#1.gb "line 0 ";n;" 800 ";n
#1.gb "size 4"
next
#1.gb "flush sea"
WindowWidth=320
WindowHeight=320
open "bump" for graphics_nf_nsb as #2
loadbmp "bump","bump5.bmp"
#2 "down ; drawbmp bump 0 0 ;flush bak"
eyeX=150
eyeZ=150
eyeA=90
fov=30
dim hmap(320,320)
dim maxh(320)
open "bump5.bmp" for binary as #bmp
x=1
y=1
seek #bmp,1078
for y=320 to 1 step -1
for x= 1 to 320
n$ = INPUT$(#bmp, 1)
hmap(x,y)=asc(n$)
next
next
close #bmp
#1.gb "when characterInput [keyboardinterrupt]"
#1.gb "setfocus"
[drawit]
'print eyeX,eyeZ,eyeA
z=160
#1.gb "discard ; redraw sea"
while z>=20
eyeL=eyeA-fov
eyeR=eyeA+fov
eyeX1=eyeX+(z*sin(eyeL/57.29577951))
eyeZ1=eyeZ+(z*cos(eyeL/57.29577951))
eyeX2=eyeX+(z*sin(eyeR/57.29577951))
eyeZ2=eyeZ+(z*cos(eyeR/57.29577951))
stepX=(eyeX2-eyeX1)/z
stepZ=(eyeZ2-eyeZ1)/z
'if eyeX2<eyeX1 then stepX=-160/z else stepX=160/z
'if eyeZ2<eyeZ1 then stepZ=-160/z else stepZ=160/z
sX=eyeX2
sZ=eyeZ2
if z=160 then
#2 "discard ; redraw bak ; color red"
#2 "line ";eyeX;" ";eyeZ;" ";eyeX1;" ";eyeZ1
#2 "line ";eyeX;" ";eyeZ;" ";eyeX2;" ";eyeZ2
end if
scrx=0
for x=0 to z
m=800/z
vX=sX
vZ=sZ
if sX<0 then vX=sX+320
if sX>320 then vX=sX-320
if sZ<0 then vZ=sZ+320
if sZ>320 then vZ=sZ-320
y=320-hmap(int(vX),int(vZ))
#2 "set ";vX;" ";vZ
#1.gb "color 0 0 ";160-z+y
'#1.gb "backcolor ";0;" ";0;" ";z+50
#1.gb "line ";scrx;" ";y;" ";scrx+m;" ";y
'#1.gb "place ";scrx;" 320 ; boxfilled ";scrx+m;" ";y
scrx=scrx+m
sX=sX-stepX
sZ=sZ-stepZ
next
z=z-20
wend
wait
[keyboardinterrupt]
'this loop gets called every time a key is pressed
k=asc(right$(Inkey$,1))
if k=39 then eyeA=eyeA-5
if eyeA<0 then eyeA=eyeA+360
if k=38 then
eyeX=eyeX+(1*sin(eyeA/57.29577951))
eyeZ=eyeZ+(1*cos(eyeA/57.29577951))
end if
if k=37 then eyeA=eyeA+5
if eyeA>360 then eyeA=eyeA-360
if k=40 then
eyeX=eyeX-(1*sin(eyeA/57.29577951))
eyeZ=eyeZ-(1*cos(eyeA/57.29577951))
end if
if eyeX>320 then eyeX=eyeX-320
if eyeZ<0 then eyeZ=eyeZ+320
if eyeX<0 then eyeX=eyeX+320
if eyeZ>320 then eyeZ=eyeZ-320
goto [drawit]
[quit]
close #1
close #2
end
Please feel free to mash it up and fix it.