For each pixel, maintain a container (e.g.In your case, rather than representing a line as simply the edge-to-edge representation using the numbering scheme described in the paper, keep track of both the edge-to-edge line segment as well as the valid end points within your white/black (open/closed, available/blocked) grid.
(You may be able to use your full 10x10 grid breaking down a grid into subgrids introduces some complexity.)
For each and every pixel, assign a binary representation of all the digital lines that pass through that pixel within some NxN grid of pixels.You could almost certainly simplify the line-fitting technique mentioned in the paper above, but the general technique is worth knowing as a means for precomputing fits in a 2D digital image.
Though you'll have to adapt it to your purposes, there is a method for precomputing line fits that you can read about in the paper "A Fast Rule-Based Parameter Free Discrete Hough Transform" by Genswein & Yang (1999):īriefly put, your code would calculate all possible lines of sight before the maze or game appears on screen for the first time. You shouldn't have to recalculate rays every cycle. Since your scene is static, at least until another scene is generated, you can perform all of your raycasting at the time of scene generation. If (Keyboard::isKeyPressed(Keyboard::Key::W)) Void checkEvents(RenderWindow & gameWindow) map data, 1 represents wall, 0 - no wall If there was no wall, we repeat step 2 and 3. When ray is pointing in right and down there is no problem, but when it is pointing to left or up we need to fix wall checking by checking one wall earlier. Here starts raycast loop, program is checking that ray is pointing to wall. Then it chooses the lowest and move ray by that coords. Then it compares their squares (pythagoras). Program is calculating next vertical and horizontal side distances using player position and tangents. Cursor sets actual player direction vector, which is calculated from atan2() function. Player can move in every direction by w s a d keys. I have implemented a 2D raycast algorithm in SFML to detect walls in a 2D game: