Make Your Own Raycaster Part 1
Why Stack Overflow recommends it
Stack Overflow users link it as the tutorial they followed when asking about bugs in their own raycaster implementations, whether in C, Python or Rust.
Recommended by 1 people across 1 different months, 2020 to 2026.
What it is
A 17-minute tutorial by 3DSage showing how to build a Wolfenstein-style raycaster in C with OpenGL, covering ray casting against a grid map and drawing the resulting 3D view. The description links source code on GitHub, a follow-up part with textures, and example raycasters.
What people said
Recommends dis_quake3_1 · 2022-09 · Stack Overflow · on “Problem with recognising where a ray in raycaster intersects a wall along the horizontal axis”
I am making a ray caster in python with pygame. [this video] The problem is the cast_rays function. I have commented out the previous method that I was using.I used the above video written in C and adapted it to Python. I wanted to use the raycasting algorithm in the above video since it would be casted then checking pixel by pixel.I have tried checking only horizontal lines and checking to see if there is a wall there. But, it doesn't work. import pygame import sys import math pygame.init() screen_height = 480 screen_width = screen_height * 2 map_size = 8 tile_size = screen_height / 8 player_x = screen_width / 4 player_y = screen_width / 4 FOV = math.pi / 3 HALF_FOV = FOV / 2 player_angle = math
Cites Omar and Lorraine · 2020-04 · Stack Overflow · on “Is it defined what will happen if you shift a float?”
I am following This video tutorial [this video] to implement a raycaster. It contains this code: if(ra > PI) { ry = (((int)py>>6)<<6)-0.0001; rx=(py-ry)*aTan+px; yo=-64; xo=-yo*aTan; }//looking up I hope I have transcribed this correctly. In particular, my question is about casting py (it's declared as float ) to integer, shifting it back and forth, subtracting something, and then assigning it to a ry (also a float ) This line of code is entered at time 7:24, where he also explains that he wants to round the y position to the nearest 64th value (I'm unsure if that means the nearest multiple of 64 or the nearest (1/64), but I know that the 6 in the source is derived from the number 64, being 2⁶) F
Cites Peanut Butter Devourer · 2022-12 · Stack Overflow · on “Raycaster sometimes renders walls in the wrong order”
I made a very basic raycasting engine from the formula laid out in this [this video] video in Rust. this works fine and is very flexible, however when it renders two connecting blocks, it sometimes renders the wrong wall. I am fairly certain that this is a rounding error, as I had trouble with that in the past, but I cannot find where it is. The code, in full, is: const SCREEN_WIDTH: f32 = 750f32; const SCREEN_HEIGHT: f32 = 500f32; const SCREEN_OFFSET: f32 = SCREEN_WIDTH / 100f32; const SHOW_2D_RAYS: bool = false; const SHOW_2D_LEVEL: bool = false; const CELL_SIZE: f32 = SCREEN_HEIGHT / MAP_SIZE; const level: [[f32; MAP_SIZE as usize]; MAP_SIZE as usize] = [ [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1
Cites Killhooligan · 2026-02 · Stack Overflow · on “SEGFAULT occuring in C in raycaster due to incorrect high values being input into map array”
Using Dev C++ 5.4.1 I've been following this raycaster tutorial as a fun project for myself: [this video] At the point in the video listed, the player is able to move around and cast a very basic ray that "detects" when a horizontal gridline is hit. For some reason in my code however, despite it being identical, this is not the case. Not only does the ray not correctly stop at wall edges but I have found that spinning in place by holding 'a' or 'd' can cause a SEGFAULT as for some reason at certain values, aTan=-1/tan(ra) produces values in the triple digits causing a cascading calculation error meaning that the map array is accessed with a very high value, causing the SEGFAULT. This is strange a