Hacker News new | ask | show | jobs
by Tempest1981 2686 days ago
I'd kill for a dozen comments, esp. if a goal is to educate students. 498 lines would still be impressive.
2 comments

It's a neat trick of projection, and really easy to hack on and extend yourself once you know the trick. Using your map of the space, cast a ray from the camera position through every column of the display rectangle; using the distance the ray travelled before intersecting the wall, you can calculate the apparent height of the wall seen in that column of the display; so, in that column, draw the wall that high. You can get fancier with textures for the walls, varying the floor height, walls that can appear and disappear (i.e. "doors"), and so on.

Better than my 10-second explanation: https://lodev.org/cgtutor/raycasting.html

Note that the site has several more entries with extensions to that base raycaster, which you can find in the index.

Interesting note about this technique: you get perspective correct texturing for free. "Real" 3D rendering usually had to cope with affine texturing due to performance costs until dedicated hardware for it came along.

like this? https://github.com/ssloy/tinyraycaster/wiki table of contents is in upper right
Nice!
I see the link to the wiki now in the README.md. The first time, I think the doom graphics distracted me, along with the "cat | wc" metrics. Thanks for the pointer.