Raycasting Library 3

Advanced game related topics
pg
User
User
Posts: 75
Joined: Wed Jun 18, 2003 3:31 pm
Location: Swiss
Contact:

Raycasting Library 3

Post by pg »

Hello

Here is again the newer version of the raycasting library
with wall, floor and ceilig rendering an many more functions.
It has its own fast pixel-rendering routines.
I hope that some of the coders here can use it.

Library and examples:

:arrow: http://www.mypage.bluewin.ch/bithandler ... aster3.zip
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Really cool library!
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

sweet :D just play'd purestein for 15 minutes :D
-you need to use a password

This is your Password for the raycaster.

pass=InitRaycaster(943984,232359,692895,981105)
Why is that?
pg
User
User
Posts: 75
Joined: Wed Jun 18, 2003 3:31 pm
Location: Swiss
Contact:

Post by pg »

Thanks

The Password is just for the InitRaycaster() function. This is, because the lib was used in another projet, where i had to protect it, but i didn't remove it. :)

I've noticed that PB 3.94 needs other declarations for functions, so
for example:

Declare PutEnemy(a.l,a.l,a.l,a.l,a.l) must be replaced with
Declare PutEnemy(a.l,b.l,c.l,d.l,e.l)

This is used on some examples....
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

oh. well not a big problem :)
ZeHa
User
User
Posts: 38
Joined: Sun Apr 24, 2005 11:39 pm

Post by ZeHa »

Just one question...

I also started to do a Raycasting Engine in PureBasic, but I did not get too far...

At first, I did one that just was drawing vertical lines, and it was very quick. Then, I tried to add wall textures, but it was very slow - and I did not find any way to get those pixels faster on the screen :(

How did you do the drawing?
ZeHa
User
User
Posts: 38
Joined: Sun Apr 24, 2005 11:39 pm

Post by ZeHa »

Or didn't you write the library itself in PB at all?
pg
User
User
Posts: 75
Joined: Wed Jun 18, 2003 3:31 pm
Location: Swiss
Contact:

Post by pg »

Hi

I've wrote the Library in Visual C. I've never tried
to do it with PB, but i'm sure it's also possible with
a good speed. If you can't draw the pels from a texture
fast enough, then maybe it's a problem with the
memory access. If you read the Bytes of the texture
directly from a memory location the it it's fast....
ZeHa
User
User
Posts: 38
Joined: Sun Apr 24, 2005 11:39 pm

Post by ZeHa »

Thank you for your reply!

Well, I scanned the texture once and wrote the RGB values into an array.
Then, when I drawed the walls, I got the colors from the array and Plot(x,y)ed them onto the screen.

Could it be faster if I used a memory buffer instead of an array?
And could it be an advantage if I wrote the RGB directly into the drawing buffer (because I think Plot() doesn't do anything else)?
pg
User
User
Posts: 75
Joined: Wed Jun 18, 2003 3:31 pm
Location: Swiss
Contact:

Post by pg »

hi

This code should render a texture fast enough. It's
different than in my C code but it should give you
more or less the same speed.

You need the "texd.bmp", it must be a
24bit 64*64 texture of your wall, then you can see it.
If you do the same for 8bit it could be faster but then
you need to use a color palette.

the Procedure Render16 does it all...

you can find this rendering function on:
http://mysite.verizon.net/caliarbor75/downloads.html
this is a good page for you!

Code: Select all


InitSprite()
InitKeyboard();
Enumeration
  #Buffer1
  #Tex
EndEnumeration
Declare Render16( a,b, c, d, e)

WndScrID = OpenScreen(640, 480,16, "") 
SetFrameRate(60)
 
 
CreateSprite(#Buffer1, 320,200,#PB_Sprite_Memory) ;//screenbuffer
LoadSprite(#Tex,"texd.bmp",#PB_Sprite_Memory )    ;//texture


StartDrawing(SpriteOutput(#Buffer1))
 buffer1= DrawingBuffer()  ;screenmemory
StopDrawing()

StartDrawing(SpriteOutput(#Tex))
 tex= DrawingBuffer() ; texturememory
StopDrawing()



 


Repeat


;draw the wall with perspective
For a = 1 To 64  ; texture is 64 pixel large
  Render16(buffer1,tex,150-a,a,a) ;200-a = height 
Next a




DisplaySprite(#Buffer1, 1, 1)
FlipBuffers()


ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
End



;/////////////////////RENDER WALL FAST/////////////////////////////
Procedure Render16(screen, bmp,  height, screenx, row)  
  a1=0;                          .
  index=bmp+(128*row);             .
  factor=(64.0/height)* 65536;  
  ch=100-height/2
  If(ch<0)          
   a1=factor*(-ch);                         .
   ch=0;                                         
   dh=200;                           
  Else
   dh=100+height/2;                
  EndIf                                           
  While(ch<dh) 
    color.w= PeekW(index+((a1>>16)<<1) )
    PokeW(screen+((320*ch+screenx)<<1),color )
    ch=ch+1
 	  a1=a1+factor
  Wend
EndProcedure
;////////////////////////////////////////////////////////////

End



ZeHa
User
User
Posts: 38
Joined: Sun Apr 24, 2005 11:39 pm

Post by ZeHa »

Great!

I think I'll try this with my engine today and I'll tell you if it works.

Thank you!
Post Reply