News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Wolf3D

Started by ScottB, December 16, 2024, 10:43:27 AM

Previous topic - Next topic

ScottB

I am having trouble calculating basic raycasting program.  I was wondering if someone could help me.
Just the intersects i tried but mine is too buggy. I will work on one though if someone sends me at least the raycasting lines done fast. I get parts of this program but not others good enough to my likeing so i'm asking for help at least get one done thats not glichy like some of my work here is. I Think this is a hard study and work load for one person to wrap head around. so a little help is all's im asking. thanks and thanks again by for now Scott B.

kevin

#1
  The ray intersections can be handle through collision worlds and then you just world out what tile it hit and what fragment to draw. 


 


PlayBASIC Code: [Select]
; PROJECT : Ray Intersect World within simple map
; AUTHOR :
; CREATED : 17/12/2024
; EDITED : 17/12/2024
; ---------------------------------------------------------------------

openscreen 1280,900,32,1

Map_Height = 16
Map_Width = 16

dim Map(Map_Width,Map_Height)

for ylp=0 to Map_Height-1
row$=readdata$()
for xlp=0 to Map_Width-1
ThisBLOCK=mid(row$,1+xlp)-asc("0")
Map(xlp,ylp) = ThisBLOCK
next
next



; Get the Screen size and use it as the world size
WorldWidth=GetScreenWidth()
WorldHeight=GetScreenHeight()

; create a Camera
MyCamera=NewCamera()

; Create world
MyWorld=NewWorld()
CaptureToWorld MyWorld

; draw a series of boarder line for this world
Line 0,0,worldwidth,0
Line worldwidth,0,worldwidth,worldheight
Line worldwidth,worldheight,0,worldheight
Line 0,worldheight,0,0



BlockSizeX#= WorldWidth /float(Map_Width)
BlockSizeY#= WorldHeight/float(Map_Height)

// Draw the map edges to collision for ray intersection
For ylp=0 To Map_Height-1
For xlp=0 To Map_Width-1
ThisBLOCK = map(xlp,ylp)
if ThisBLOCK=0 then continue
// If this is wall block; then check edges

x1# = xlp *BlockSizeX#
x2# = (xlp+1) *BlockSizeX#
y1# = ylp *BlockSizeY#
y2# = (ylp+1) *BlockSizeY#

// edges f this block
if (ylp-1)>=0
if map(xlp,ylp-1)=0
Line x2#,y1#,x1#,y1# // Top
endif
endif

if (ylp+1)<=Map_Height
if map(xlp,ylp+1)=0
Line x1#,y2#,x2#,y2# // bottom
endif
endif

if (xlp-1)>=0
if map(xlp-1,ylp)=0
Line x1#,y1#,x1#,y2# // Left
endif
endif

if (xlp+1)<=Map_Width
if map(xlp+1,ylp)=0
Line x2#,y2#,x2#,y1# // Right
endif
endif
next
next



; Partition The world up into 32 by 32 cells
PartitionWorld MyWorld,32

; Tell PlayBASIC to return to Immediate drawing mode
DrawGFXImmediate


; statrt of DO/Loop
Do

; capture to scene and grab the world info
CaptureToScene
ClsScene
CaptureDepth 100
CameraGrabWorld MyCamera,MyWorld


; Get the mouse position
mx#=MouseX()
my#=MouseY()

; Cast 150 rays out from the mouses position
rays=150
For Ray=1 To Rays
angle#=(360.0/Rays)*Ray
x2#=CosNewValue(mx#,angle#,400)
y2#=SinNewValue(my#,angle#,400)
If RayIntersectWorld(MyWorld,mx#,my#,x2#,y2#)=true
x2#=GetIntersectX#(0)
y2#=GetIntersectY#(0)
CircleC x2#,y2#,3,1,RGB(255,0,0)
EndIf
Line mx#,my#,x2#,y2#
Next

; draw the camera
DrawCamera MyCamera

; show the fps rate and continue this loop
Text 0,0,FPS()
Sync
Loop spacekey()

end




data "11111111111111111111"
data "10000000000000000001"
data "10001111111110000001"
data "10001000000010000001"
data "10001111100010000001"
data "10000000000000011001"
data "10000000000000011001"
data "10000001000000000001"

data "10000000000000000001"
data "10000000000000000001"
data "100100110011001100001"
data "10011111111100110001"

Login required to view complete source code




 


  Related Links:

    - See Ray Intersect World command in PlayBASIC HELP




ScottB

Awesome! But...
How would I get texture mapping done.

Is is something like X1_Ray / X_Cell_Size Mod block size???

kevin