Dark Bit Factory & Gravity

PROGRAMMING => Other languages => Blitz => Topic started by: Tetra on September 24, 2006

Title: BlitzBasic - Raycaster[BB2D]
Post by: Tetra on September 24, 2006
Was revisiting some old snes games and came ascross Jurassic Park. When you go inside you got a Doom style raycasted enviroment, and I wanted to reproduce it.

So heres my first attempt, it looks ok, but there are a few bugs in it. Also its not the best way to do it, its very inaccurate and expensive, but the basic idea is there.

Next step will be to introduce textures.

Use arrow keys to move about and space bar to show the map and your position. Exe and code available as a download.

Code: [Select]
;------------------------------------------
;
; Raycaster
;
; Created on the 24 Spetember 2006
;
; an attempt by Tetra
;
;-----------------------------------------

AppTitle "Raycaster v0.1"

;-----------------------------------------

Global XRES = 640
Global YRES = 480

Global        FOV = 90
Global  half_FOV# = Float(FOV) / 2.0
Global delta_FOV# = Float(FOV) / Float(XRES)

Dim level(64,64)

Global PlayerX# = 60
Global PlayerY# = 60
Global PlayerA# = 220

Global PlayerDX# =  0
Global PlayerDY# =  0

Global Background

Global Timer

;------------------------------------------
;
;
Function Initialize()

Restore .levelData

For y = 0 To 63
For x = 0 To 63
Read level( x,y )
Next
Next

CreateBackground()

Timer = CreateTimer( 60 )

End Function

;------------------------------------------
;
;
Function CreateBackground()

Local c
Local y

Background = CreateImage( 640,480 )
SetBuffer( ImageBuffer( Background ) )

For y = 0 To 150
c = ( 150 - y ) * ( 255.0 / 158.0 )
Color c,c,c
Rect 0,y,640,1

Rect 0,479 - y ,640,1
Next

End Function

;------------------------------------------
;
;
Function Render()

Local dx#
Local dy#

Local currA# = PlayerA# - half_FOV#

Local cx#
Local cy#

Local dist#

Local hit = False

For x = 0 To 639

dx# = Cos#( currA# ) / 50.0
dy# = Sin#( currA# ) / 50.0

cx# = PlayerX#
cy# = PlayerY#

hit = False
dist# = 0.0

; Send out a ray
While Not hit
If cx# > 63 Then cx# = 63
If cx# <  0 Then cx# =  0

If cy# > 63 Then cy# = 63
If cy# <  0 Then cy# =  0

If level( Int(cx#), Int(cy#) ) > 0
hit = True
Else

dist# = dist# + 0.01
cx# = cx# + dx#
cy# = cy# + dy#
EndIf
Wend


; hack for removing the distortion
dist = dist * Cos( (currA# - PlayerA#) )

; Wall height projection
Local wallHeight# = ( 64.0 / dist# ) * 8.0

col = wallHeight

If col > 255 Then col = 255

Select level( Int(cx#), Int(cy#) )
Case 1 Color col,col,col
Case 2 Color col,0,0
Case 3 Color 0,col,0
Case 4 Color 0,0,col
End Select

size = (wallHeight / 2)
Rect x,( YRES / 2 ) - size, 1, size * 2

currA# = currA# + delta_FOV#

Next


End Function

;------------------------------------------
;
;
Function DrawMap()

Color 255,0,255
For x = 0 To 63
For y = 0 To 63
If level( x,y ) > 0 Then Rect(x*2,y*2,2,2)
Next
Next

Color 255,0,0
Rect( PlayerX*2, PlayerY*2, 2, 2 )

Color 0,255,0
Line PlayerX * 2,PlayerY * 2, (PlayerX * 2)+(PlayerDX * 4),(PlayerY*2)+(PlayerDY * 4)

End Function

;------------------------------------------
;
;
Function InputControl()

; FORWARD
If KeyDown( 200 ) Then
tx# = PlayerX# + (PlayerDX# / 2.0)
ty# = PlayerY# + (PlayerDY# / 2.0)

If tx# < 0 Then tx# = 0
If tx# > 63 Then tx# = 63

If ty# < 0 Then ty# = 0
If ty# > 63 Then ty# = 63

If level( tx,ty ) = 0
PlayerX# = tx#
PlayerY# = ty#
EndIf
EndIf

; BACKWARD
If KeyDown( 208 ) Then
tx# = PlayerX# - (PlayerDX# / 2.0)
ty# = PlayerY# - (PlayerDY# / 2.0)

If tx# < 0 Then tx# = 0
If tx# > 63 Then tx# = 63

If ty# < 0 Then ty# = 0
If ty# > 63 Then ty# = 63

If level( tx,ty ) = 0
PlayerX# = tx#
PlayerY# = ty#
EndIf
EndIf

; TURN LEFT
If KeyDown( 205 ) Then
PlayerA = ( PlayerA + 6 ) Mod 360
EndIf

; TURN RIGHT
If KeyDown( 203 ) Then
PlayerA = PlayerA - 6
If PlayerA < 0 Then PlayerA = PlayerA + 360
EndIf

; DIRECTION VECTOR
PlayerDX# = Cos( PlayerA )
PlayerDY# = Sin( PlayerA )

End Function

;------------------------------------------
;
;
Function Main()

DrawImage( Background, 0, 0 )
InputControl()

Render()

; Press Space to draw map
If KeyDown( 57 ) DrawMap()

Color 255,255,255
Text 10,10,MaxDist

End Function



;==========================================

Graphics XRES,YRES,32,2

Initialize()

SetBuffer( BackBuffer() )

While Not KeyDown(1)
Cls
Main()

WaitTimer( Timer )
Flip

Wend

End



.levelData
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
Data 1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1
Data 1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1
Data 1,0,0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,0,0,0,0,0,0,0,0,0,0,0,0,0,1
Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1


 :||
Title: Re: BlitzBasic - Raycaster
Post by: Shockwave on September 24, 2006
That runs nice Tetra :) I like the perspective too, it looks kind of funky, gives the walls a bowed look sometimes, I actually like that.
Title: Re: BlitzBasic - Raycaster
Post by: Clyde on September 24, 2006
Nice one Tetra :D
Title: Re: BlitzBasic - Raycaster
Post by: benny! on September 25, 2006
Yup. Definately good work !!!
Title: Re: BlitzBasic - Raycaster
Post by: Jim on September 25, 2006
It's nice!  One or two things you could do...your correction for the distance using cos is clever, but it's not quite right - it does look good though :).  The error is based on sqrt.  When you scan at the edge of the screen everything is sqrt(2) further away than it is at the middle.
Can you make it so that every side of every block can have a different colour? ;)
Can you make it so you can detect how far along each block's wall you hit? :)
If you can do that, you can add texture mapping :D

Jim
Title: Re: BlitzBasic - Raycaster
Post by: taj on September 26, 2006
Or if you have the x,y,z of where you hit the wall, apply an inverse of the viewing transform...plug in a 3d texture and avoid that nasty texture mapping code maybe? Hmmm now I wite it, it sonuds like a lot of code to do per pixel.
Title: Re: BlitzBasic - Raycaster
Post by: rdc on September 26, 2006
There is a good tutorial on raycasting that addresses some of these problems:

http://www.permadi.com/tutorial/raycast/
Title: Re: BlitzBasic - Raycaster
Post by: Tetra on September 27, 2006
Thats a pretty cool tutorial, nicly layed out. However there is a better way than that of making a raycaster that removes the distortion. It involves making a camera of sort, but I didnt understand it.

I have had my thinking cap on about the textures, and in the process come across probably a nicer way of rendering the world so that its not this blocky world that everyone referances to.

Before making this I never realised that all raycasters are effectively doing is making the pixel into a rectangle, and renering that. What I was thinking was what if you take the points at the center of that square and connect them up, that would remove the blocky look, and allow for sloped edges at 45 deg angles, unlike now where you get a jagged edge.

Originally I was thinking of using lines to reprisent the world, but thanks to metabballs it seemed clear that you could make the lines up from the pixels them selfs.
This way will lend it self to a texure mapper really well, and provide the coords for mapping the texture.

I will post more soon. Heres a pic to show what I mean: -


Title: Re: BlitzBasic - Raycaster
Post by: Shockwave on September 27, 2006
If I'm right, it will mean that you can have much more interesting looking maps with your method Tetra. Maybe even walls that look curved?
Title: Re: BlitzBasic - Raycaster
Post by: mike_g on January 02, 2007
This is really cool. For what it does its surprisingly little code. I'm not sure exactly how it works though, Im not so good with maths, but I might try figure it out sometime.
Title: Re: BlitzBasic - Raycaster
Post by: Paul on January 02, 2007
Cant belive you wrote that, i just started fidling with raycaster to figure out how they worked yestarday :) and now i get this example

thx