News:

Function Finder  Find all the functions within source code files

Main Menu

Raycasting Help?

Started by ScottieB, July 30, 2015, 05:56:49 AM

Previous topic - Next topic

BlinkOk

put the height information in the surface you collide with then when you hit it you can extract the height

ScottieB



Well,  I now got floorcasting somewhat but it's terriably tooooo slooooowwwwwwww.

Can anyone help me add speed ups.
Kevin is there a way for you to add the power of pb2dll but not the whole program???

will lock and unlock buffer help or will it still be tooooooooooooo sloooooooowwwwwwwwww.

It does pixel by pixel which at the rate is way to many pixels for playbasic alone I think without the help of machine code.

Is there a way to fix this?  Or do I have to give up floors and ceilings all together.

Please reply
Thanks
ScottieB

ScottieB

Here's a solution.

But can it be add more than one texture for the floor???
It's yet to be seen.

It's fast enough compared to many tutorials I've seen.

Any suggestions or ideas??

Tanks
ScottieB

stevmjon

hey scottie

I added lockbuffer and it now draws the screen much faster.

it's looking more complete now, you have done a lot of work for this.
it could use some optimizing though.

for fun I am learning the maths for a 3d engine at the moment, from the net. I want to make a polygon based 3d game. I loved the dungeon master type games from the 80's. I will see how I go. there is more maths formulas to learn than I thought. sometimes it gets confusing, lol.

  stevmjon
It's easy to start a program, but harder to finish it...

I think that means i am getting old and get side tracked too easy.

kevin

#19
   Had another look at the demo yesterday,  has certainly come in along.. Well done !   Spent a bit of time optimizating the casting routines for redundancy last night.   But have left those files at home like a duffer.    Anyway here's some example of where you can win back some performance.    

  The main loop is basically a bunch nested loops, with the following 2D loops in them.  Not without really looking into the method we can strip some overhead from each ray cast by moving some of the inner most comparisons out one loop..


   So this code,

 
PlayBASIC Code: [Select]
For X = 1 To 18
For Y = 1 To 18

If X_Corner(Rays,X) = 0 And X_Dis(Rays,X) <> 0 And X_Dis(Rays,X) < Y_Dis(Rays,Y) Then X_Pos = X:Dir = 1:Scale# = X_Dis(Rays,X):Remainder_1# = Mod(Y3_Pts(Rays,X),64):Goto Exit_1

Next Y
Next X

Exit_1:

For Y = 1 To 18
For X = 1 To 18


If Y_Corner(Rays,Y) = 0 And Y_Dis(Rays,Y) <> 0 And Y_Dis(Rays,Y) < X_Dis(Rays,X) Then Y_Pos = Y:Dir = 2:Scale# = Y_Dis(Rays,Y):Remainder_2# = Mod(X4_Pts(Rays,Y),64):Goto Exit_2


Next X
Next Y

Exit_2:





   This inner loop pulls the values from X_Corner(Rays,X) and makes various other comparisons but for the expression to be tru, then all of those make equate to true.

 
PlayBASIC Code: [Select]
For X = 1 To 18
If X_Corner(Rays,X) = 0
For Y = 1 To 18

If X_Dis(Rays,X) <> 0 And X_Dis(Rays,X) < Y_Dis(Rays,Y) Then X_Pos = X:Dir = 1:Scale# = X_Dis(Rays,X):Remainder_1# = Mod(Y3_Pts(Rays,X),64):Goto Exit_1

Next Y
ENDIF
Next X

Exit_1:

For Y = 1 To 18
If Y_Corner(Rays,Y) = 0
For X = 1 To 18

If Y_Dis(Rays,Y) <> 0 And Y_Dis(Rays,Y) < X_Dis(Rays,X) Then Y_Pos = Y:Dir = 2:Scale# = Y_Dis(Rays,Y):Remainder_2# = Mod(X4_Pts(Rays,Y),64):Goto Exit_2

Next X
ENDIF

Next Y

Exit_2:





  Then we can pull the comparison of X_Dis(Rays,X) out of the inner loops and we get this.


 
PlayBASIC Code: [Select]
For X = 1 To 18
If X_Corner(Rays,X) = 0
IF X_Dis(Rays,X) <> 0
For Y = 1 To 18

If X_Dis(Rays,X) < Y_Dis(Rays,Y) Then X_Pos = X:Dir = 1:Scale# = X_Dis(Rays,X):Remainder_1# = Mod(Y3_Pts(Rays,X),64):Goto Exit_1

Next Y
ENDIF
ENDIF
Next X

Exit_1:

For Y = 1 To 18
If Y_Corner(Rays,Y) = 0
If Y_Dis(Rays,Y) <> 0

For X = 1 To 18

If Y_Dis(Rays,Y) < X_Dis(Rays,X) Then Y_Pos = Y:Dir = 2:Scale# = Y_Dis(Rays,Y):Remainder_2# = Mod(X4_Pts(Rays,Y),64):Goto Exit_2

Next X
ENDIF
ENDIF

Next Y

Exit_2:





   We can take that further by pulling the value from X_Dis(Rays,X) into a variable.  Which saves polling that same position within the array 18 times per each loop per ray.  Which really adds up.

   
PlayBASIC Code: [Select]
For X = 1 To 18
If X_Corner(Rays,X) = 0

X_Dis_Rays_X = X_Dis(Rays,X)
IF X_Dis_Rays_X <> 0

For Y = 1 To 18

If X_Dis_Rays_X < Y_Dis(Rays,Y) Then X_Pos = X:Dir = 1:Scale# = X_Dis_Rays_X:Remainder_1# = Mod(Y3_Pts(Rays,X),64): exitfor X

Next Y
ENDIF
ENDIF
Next X


For Y = 1 To 18
If Y_Corner(Rays,Y) = 0

Y_Dis_Rays_Y =Y_Dis(Rays,Y)

If Y_Dis_Rays_Y <> 0

For X = 1 To 18

If Y_Dis_Rays_Y < X_Dis(Rays,X) Then Y_Pos = Y:Dir = 2:Scale# = Y_Dis_Rays_Y:Remainder_2# = Mod(X4_Pts(Rays,Y),64): exitfor Y

Next X
ENDIF
ENDIF

Next Y








kevin

#20
Quote from: stevmjon on August 24, 2015, 09:12:34 PM

 for fun I am learning the maths for a 3d engine at the moment, from the net. I want to make a polygon based 3d game. I loved the dungeon master type games from the 80's. I will see how I go. there is more maths formulas to learn than I thought. sometimes it gets confusing, lol.

 stevmjon

  It's fun the legacy demos are just pure PB (software polygon rendering)  but if your really interested setting up a wrapper for OpenGL would be possible.   






kevin

#21
Quote from: ScottieB on August 23, 2015, 10:37:42 AM


Well,  I now got floorcasting somewhat but it's terriably tooooo slooooowwwwwwww.

Can anyone help me add speed ups.
Kevin is there a way for you to add the power of pb2dll but not the whole program???

 I could.. but you'd need to set everything up as a set of functions.  Like split all the important (needs to be fast code) off into a separate file with a simple function interface then, have that compiled to machine code for you..  Anybody who owns PB2DLL can do that for you.  The important thing is to create the function interface, so you'll need to use functions.  The speed of which running through the VM doesn't matter, since the conversion process removes the VM overhead and inner loops are very lean.   With rendering loop like a floor plotting, the I'd go with direct memory access to get the leanest possible overhead per pixel.     

Quote
will lock and unlock buffer help or will it still be tooooooooooooo sloooooooowwwwwwwwww.

It does pixel by pixel which at the rate is way to many pixels for playbasic alone I think without the help of machine code.

Is there a way to fix this?  Or do I have to give up floors and ceilings all together.


 There's always a solution, but the question is how willing one is to find an alternative method to achieve the same / similar result.    


kevin

#22
  Here's my version of the demo from the other day.