3D Voxel Flugsim für B2D von |
Die verwedenteten Bilder sollten in den Beispiel Ordnern sein, oder sonst hier: http://www.melog.ch/dl/voxel_bb.zip [code:1:24248fb2b2] ;3D Voxel/Raycast mit Textur und Nebel - Flug über Landschaft ; by CSP just4fun Graphics 320,240,16,2 SetBuffer BackBuffer() ; die 2 Bilder sollten in den Examples Ordnern zu finden sein Global hm=LoadImage("heightmap_256.BMP");256*256 Global mossy=LoadImage("MossyGround.BMP");256*256 Global grw=GraphicsWidth() Global grh=GraphicsHeight() Global grwh=grw/2 Global grhh=grh/2 Global my Global px#=8.0 Global pz#=8.0 Global a# MoveMouse grwh,0 ;__________________________MAINLOOP_________________________ While KeyDown(1)=0 Cls If KeyDown(200) Then ; up px=px+Sin(a) pz=pz+Cos(a) EndIf If KeyDown(208) Then ; down px=px-Sin(a) pz=pz-Cos(a) EndIf a=(a-mxs#) Mod 360 ; use mouse to steer raycast() ; Text 0,0, "x:"+px+ " z:"+pz Flip my=MouseY() If my>130 Then my=130 mxs#=MouseXSpeed()/3.0 ; used by steer MoveMouse GraphicsWidth()/2,my Wend End ;________________________eo mainloop__________________________ Function raycast() For i=-grwh To grwh-1 Step 4 row=grh+1 grwh_mi=grwh-i rayx#=px rayz#=pz stepx#=Sin(a+0.125*i) stepz#=Cos(a+0.125*i) count#=0 LockBuffer BackBuffer() LockBuffer ImageBuffer(hm) LockBuffer ImageBuffer(mossy) While count<200 ; camerarange rayx#=rayx+stepx rayz#=rayz+stepz If rayx>-127 And rayx<127 If rayz>-127 And rayz<127 c#=ReadPixelFast(rayx+127,rayz+127,ImageBuffer(hm)) And $ff h#=((15000.0-my*100)/count)-((.1*my+30)*c)/count If h<row If c=0 Then co=$9dd0 ; wasser Else ;co=((c Xor $ff)Shl 7)And $ff00 Or (c Shl 16) co=ReadPixelFast(rayx+127,rayz+127,ImageBuffer(mossy)) And $ffff Or (c Xor $FF) EndIf For ii= h To row-1 x=grwh_mi y=ii If x>=0 And x<=grw And y>=0 And y<=grh WritePixelFast x,y,co,BackBuffer() EndIf Next row=h EndIf EndIf EndIf count=count+1 Wend UnlockBuffer BackBuffer() UnlockBuffer ImageBuffer(hm) UnlockBuffer ImageBuffer(mossy) Next End Function [/code:1:24248fb2b2] |
von h |
Boah, ist das geil :!: |
von ??? |
Danke :-) |
von ??? |
Yap, sehr schön ... selbst mit einem Step von 2 habe ich noch 40 FPS |
von ??? |
Cool! Aber man könnte das noch beschleunigen, in dem Du die Bilder vorher in Arrays (event. sogar mal mit einer Banks versuchen) lädst. And $FF und And $FFFF könntest Du dann auch schon vorberechnen lassen. mfg olli |
von ??? |
... Function raycast() For i=-grwh To grwh-1 Step [b:cc6aa5f250]4[/b:cc6aa5f250] ... Einfach den Stepwert heraus lassen, so werden die Spalten nicht mehr angezeigt :) |
von ??? |
Freax - ein Speed optimierte Version kannst du hier gerne posten! |
von ??? |
Das ist cool :D Mit Step 2 läuft es noch ziemlich flüssig! |
..... von ??? |
Es gibt auch noch paar Frames mehr wen man die Lock und UnlockBuffer befehle noch außerhalb der For next schleife hinpackt. Ansonsten sehr schick. Klein aber fein. Gute arbeit. bye |
von ??? |
Hab auf die Schnelle mal bisschen optimiert: [code:1:2403f669f4];3D Voxel/Raycast mit Textur und Nebel - Flug über Landschaft ; by CSP just4fun Graphics 320,240,16,1 ; die 2 Bilder sollten in den Examples Ordnern zu finden sein Global hm=LoadImage("heightmap_256.jpg");256*256 Global mossy=LoadImage("MossyGround.jpg");256*256 Global grw=GraphicsWidth() Global grh=GraphicsHeight() Global grwh=grw/2 Global grhh=grh/2 Global my Global px#=8.0 Global pz#=8.0 Global a# Dim HeightMap(256,256) SetBuffer ImageBuffer(hm) LockBuffer For i=0 To 256 For ii=0 To 256 HeightMap(i,ii)=ReadPixelFast(i,ii) And $FF Next Next UnlockBuffer Dim Textur(256,256) SetBuffer ImageBuffer(mossy) LockBuffer For i=0 To 256 For ii=0 To 256 Textur(i,ii)=ReadPixelFast(i,ii) And $FFFF Next Next UnlockBuffer SetBuffer BackBuffer() MoveMouse grwh,0 ;__________________________MAINLOOP_________________________ While KeyDown(1)=0 Cls my=MouseY() If my>130 Then my=130 mxs#=MouseXSpeed()/3.0 ; used by steer MoveMouse GraphicsWidth()/2,my If KeyDown(200) Then ; up px=px+Sin(a) pz=pz+Cos(a) EndIf If KeyDown(208) Then ; down px=px-Sin(a) pz=pz-Cos(a) EndIf If KeyDown(203) Then ; left px=px-Sin(a-90) pz=pz-Cos(a-90) EndIf If KeyDown(205) Then ; right px=px-Sin(a+90) pz=pz-Cos(a+90) EndIf a=(a-mxs#) Mod 360 ; use mouse to steer raycast() ; Text 0,0, "x:"+px+ " z:"+pz FPSCounter=FPSCounter+1 If MilliSecs()>FPSTimer+1000 Then FPS=FPSCounter FPSCounter=0 FPSTimer=MilliSecs() EndIf Text 5,5,FPS Flip Wend End ;________________________eo mainloop__________________________ Function raycast() LockBuffer BackBuffer() For i=-grwh To grwh-1; Step 4 row=grh+1 grwh_mi=grwh-i rayx#=px rayz#=pz stepx#=Sin(a+0.125*i) stepz#=Cos(a+0.125*i) For count=0 To 199 rayx#=rayx+stepx rayz#=rayz+stepz If rayx>-127 And rayx<127 Then If rayz>-127 And rayz<127 Then c#=HeightMap(rayx+127,rayz+127) h#=((15000.0-my*100)/count)-((.1*my+30)*c)/count If h<row Then If c=0 Then co=$9dd0 ; wasser Else co=Textur(rayx+127,rayz+127); Or (c Xor $FF) EndIf For ii=h To row-1 If grwh_mi>=0 And grwh_mi<=grw And ii>=0 And ii<=grh Then WritePixelFast grwh_mi,ii,co,BackBuffer() EndIf Next row=h EndIf EndIf EndIf Next Next UnlockBuffer BackBuffer() End Function[/code:1:2403f669f4] Man könnte jetzt vielleicht noch Sinus und Cosinus vorberechnen... aber soviel würde das auch nicht bringen. Achso, das Step 4 hab ich auskommentiert... bei mir hats bis zu 75 FPS |
hehe von ??? |
mal sehen ob bmax inline asm hat ?! ansonsten ein sehr netter code @norc |
von ??? |
Hammer, ist das geil! :shock: Die speed-optimierte version läuft selbst auf meiner Klapperkiste (siehe Signatur) mit superflutschigen 42 FPS. Das werden seelige Comanche1 Erinnerungen wach *hach* |
von ??? |
Wirklich sau geil mein größtes Lob!!!!!!!!!!!! :D |
von ??? |
Hammerfettkrasti**engeiloberaffenhammerfett!!!!!! |