LoginLogin

Raycaster glitching

Root / Programming Questions / [.]

VakoreCreated:
My raycaster is bugging out. I'm not sure if it is smileBasic or my code. I managed to make on in javascript just fine, but my sb one seems to be broken. Here is the link: https://smilebasicsource.com/page?pid=1387 Any help would be greatly appreciated. For extra info, it is running at 30fps(vsync 2) and I used this: https://lodev.org/cgtutor/raycasting.html as a base I would give info on the problem itself, but it's hard to explain. Best to see it for yourself.

Small world. I also made a ray caster based on the same exact web page. I am at my key limit, but I uploaded my version to the key C33N3JGX. If I remembered mine was broken at first and Sim30n was kind enough to help me fix it. I think the original is also producing a mirrored image. I downloaded your version I will see if I can spot anything but it may take me a while to get free time to work on it. So you may want to diff against mine first.

A: Well, it is the first result to pop up when you search "raycaster tutorial" in google B: I tried searching, and all I can see is that you optimize integers where I don't(I'm too used to the free-flow form of javascript) and your code looks a lot nicer, and is organized differently, and uses atan and such in areas where I don't, and yours runs at a higher(but slower) resolution, and you use deltaTimes, but I can't find anything different other then that that I can see. Though I am as blind as a bat when comparing two code pieces together, and since they act differently, I'm probably very wrong.

ADDED TO
@LOOP
CLS
?PX,PY
?DIRX,DIRY
Notice as decimal portion if px is high, around .9, the wall height looks correct.As the decimal portion of px approaches 0 the height difference is exaggerated...the wall seems to clip further, extend furthwr off into the distance. Guessing some check is not letting the wall finish drawing, and it draw until its height hits 0. When ya start, i just look at the green blue corner. it throws off the drawing from left to right so the darkgreen has to finish "growing" to like some max height or is too close to camera? The next green wall has to finish shrinking to 0, then the blue wall gets drawn. Check the dda or map checking somewhere? Or wall seg stuff. This is what it should look like Also added a button to slow turning and moving
IF (BUTTON() AND #L) THEN MOVESPEED=0.0001:ROTSPEED=0.0001

Thank you for trying to help in void. I made some changes(including the slowing of mlving/looking, added
cls
, and removed the black bars), and I am currently fiddling with the code to try and fix the problem.

Try line 77. Missing multiplying by deltadistx in the "else" at the end of the line ..i cant explain what its doing... but i know the "else" condition isnt doing what the if condition is doing... when it reverses px and mapx I might be wrong but i think mapx and mapy are already the FLOOR of px and py on lines 57,58 so ya could probably take those out of the line 77 unless ya meant to floor the final value of
PX-MAPX*DELTADISTX
(MAPX-PX+1)*DELTADISTX

Really? That was all that I missed. Thanks for helping. Something like this happened when I made a textured raycaster in ja, and I simply forgot to floor a value xD Thanks! Edit: it works, and I updated it, but the blind king is still there. If I remove 'cls' it helps, but it still blinks, and even more at higher resolutions. Is this a smilebasic think or a code thing?

What 3ds ya got? It worked fine on mine new 3dsxl. I just put the cls there to clear the screen so i could put the "hud" up and see Px,py Dirx,diry In the corner... I think it runs fine. No flicker.

I have an o2ds. If you remove the black bars by going to the for loop the runs the raycast, you might see it. Or increase the screen resolution by editing the w and h variables and where I draw the lines(might be tricky)

Oh yeah.. messing with q w and multiplier was able to get picket fencing..
W=100:H:75
CS=2'SCALAR OF RESOLUTION
GAP=1'GAP BETWEEN COLUMNS
CWIDTH=CS*4-GAP*CS'COLUMN WIDTH
VS=1 'VSYNC VALUE

DEF RAYCAST
GCLS
FOR Q=0 TO W/CS
IF Q<0 OR Q>W/CS THEN NEXT'REMOVED BORDERS
X=Q*CS

....
GFILL X*4,DRAWSTART*4,X*4+CWIDTH,DRAWEND*4,RGB(C1,C2,C3)
tried to variablize it.. your border needs to take into account the scale as well...i didnt do it i just took it out..im sure than if statement can go away too.. Also if its chugging and slow.. i think it is calculating as you are rotating..so the columns on the right are actually drawn later in time...and the player is at a different angle. So that might be what you are seeing. You are moving the player/rotating every column. Could move that to the main loop somehow. Either my eyes are terrible or the new3dsxl let me run with vsync 1 I should probably did something with gfill x*4

It isnt chugging, and as a matter of fact, runs pretty well at 1/2 resolution. It's just the the lines starting from right to left are flickers, and if the resolution is higher it gets worse. Also it is happening even when I'm not rotating.

Glad to hear you got it figured out and got the program working. I may be able to help with the flickering, by adding in page flipping. start by adding this to the top of the file:
DIM VPAGE = 0, HPAGE = 1
vpage stands for visual page, and hpage for hidden page. Then just before your main loop (which I STRONGLY suggest you change into a While loop) add:
GPAGE VPAGE, HPAGE
SWAP VPAGE, HPAGE
and finally before your vsync call add another:
GPAGE VPAGE, HPAGE
SWAP VPAGE, HPAGE
If you get it right, all of the draw commands will happen on an off-screen page then you swap it with the visual page on completion. Then if it takes more than one frame, it will just be slow, and not flicker

Do ya have battery sve or low power setting? Wouldnt ya only need one page flip vefore the vsync or after etc.

I thought you might get a kick out this. Here is my version with texture mapping by making a single pixel wide sprite for every column on the screen. Leaves about a hundred sprites for enemies and projectiles. I also z-indexed the sprites so that enemies could just be dumped into the world and automatically be covered/revealed as needed. Never did finish it. Maybe I should port it over to SmileBasic switch and make a Wolfenstein type game. I was thinking you may be able to do floor casting with LMATRIX. If the speed is good enough maybe I could do the whole thing on a offscreen buffer and do floor/ceiling casting right. I rather like how I darkened the colors the further it was from the camera. The first page flip is to set it up before the main loop. Then it is just once per loop through the main loop. Wouldn't really hurt much if you left out the first one, worst case scenario is one garbled frame before it returns to normal.

Did something like that but no movement just a single wall kinda bound to the screen. But got tearing and flickering with the sprites :( i probably approached it wrong Did ya do posts or columns that would each be a sprite? Or did ta do one sprite per texture U cordinate? I figure it was too many sprite calls..or i just dont know sprites Had to spset, sphome, spofs, spscale, spcolor I dunno if it is set that resets the home and offset...would changig the uv with anim be better? Ohwell.

What I did in javascript for the sprites was loop through every column just like the walls.

Had to spset, sphome, spofs, spscale, spcolor I dunno if it is set that resets the home and offset...would changig the uv with anim be better? Ohwell.
You might be looking for SPCHR, which does the same thing as SPSET without initializing the rest of the sprite's settings.

Thanks seggiepants! It worked! Two things: A: what does it being a while loop do? B: could you please explain what this is doing for me? Thanks!

A while loop gets rid of a GOTO call. GOTO quickly makes any code an unmaintainable mess when used. It gives you a clearly defined loop that has well defined entry and exit locations and describes your intent better. GPAGE let's you send all draw commands to a hidden screen in memory so you can switch it over to the display only once all drawing is finished. Without it, drawings taking longer than a single frame can rip, tear, or flicker. I did use spchr for the texture mapping, I just made 1x16 sprites one for each column of the display. I used spofs to position it with a z index related to perspective distance, and spcolor to make one side darker and again darker with distance. Spscale let me size them correctly

Can you use vsync in a while loop?