There are also some intermittent horizontal lines that still exist that are unrelated to this problem.
Code: Select all
;simple Voxel engine
;
;done by TheWanderer on Amiga
;converted to TLib by jhd
;converted/speedup to PureBasic by jhd
InitSprite()
InitMouse()
OpenScreen(640,480,16,"Voxel")
#gXd = 400;512
#gYd = 400;512
Global blickhoehe.f, blickwinkel.f,blickwinkel_grad.f
Global grwh.f: grwh = #gXd/2
Global grhh.f: grhh = #gYd/2
Global px.f,pz.f
Global Dim pic.l(255,255)
LoadImage(0,"height5.bmp")
StartDrawing(ImageOutput(0))
For y=0 To 255
For x=0 To 255
col=Point(x,y)
pic(x,y)=Red(col)
Next
Next
StopDrawing()
Global Dim piccol.l(255,255)
LoadImage(0,"color5.bmp")
StartDrawing(ImageOutput(0))
For y=0 To 255
For x=0 To 255
piccol(x,y)=Point(x,y)
Next
Next
StopDrawing()
; -- very simple voxel routine
Procedure voxel_show(winkel.f,hoehe.f)
StartDrawing(ScreenOutput())
For i = -grwh To grwh-1 ;Step 2
row.f = #gYd + 1
grwh_mi.f = (grwh - i)
rayx.f = px.f
rayz.f = pz.f
stepx.f = Sin(winkel + 0.00255 * i)
stepz.f = Cos(winkel + 0.00255 * i)
count = 1
While count < 200 ; sichtweite
rayx = rayx + stepx
rayz = rayz + stepz
If rayx>-grwh And rayx<grwh
If rayz>-grhh And rayz<grhh
xx.l=rayx+grwh:If xx<0:xx+255:ElseIf xx>255:xx-255:EndIf
yy.l=rayz+grhh:If yy<0:yy+255:ElseIf yy>255:yy-255:EndIf
c.l = pic(xx,yy)
h.f = ((24000.0 - hoehe*100)/count) - ((0.15*hoehe+40)*c)/count
col.l = piccol(xx,yy)
If h < row
; -- paint vertical voxel
x.f = grwh_mi
If x>20 And x<620 And h>0 And row<420
For y = h To row-1 ;Step 2
Plot(x,y,col.l)
Next y
EndIf
row = h
EndIf
EndIf
EndIf
count + 1
Wend
Next
StopDrawing()
EndProcedure
; -- MAINPROGRAM ------------------------------------------------------------
px.f = 0
pz.f = 0
Repeat
ClearScreen(RGB(200,180,190))
ExamineMouse()
blickhoehe.f = MouseY()
If blickhoehe > 100 : blickhoehe = 100:EndIf
demo_counter.f = (demo_counter + 0.5)
demo_winkel.f = (demo_counter * #PI/180)
blickwinkel = Sin(demo_winkel) -Cos(demo_winkel) ;
px + (Sin(demo_winkel)/4 - Cos(demo_winkel))
pz + (Cos(demo_winkel)/4 - Sin(demo_winkel))
voxel_show(blickwinkel, blickhoehe)
FlipBuffers()
Until MouseButton(1)
End