Raylibstein
- 4 Devlogs
- 21 Total hours
Pseudo-3D Raycaster
Pseudo-3D Raycaster
Today’s the day I ship, I finally released a web-port version of my raycasting engine, and created a detailed README on the Github repo. To do this, I had to use a tool called emsdk which allowed me to convert all my C++/raylib code into Web Assembly + HTML code!
I now have live web page up and running using GitHub pages & actions, and I debugged any issues that arose (such as the mouse not properly locking to the screen)
This took a while, but I successfully added texture rendering to walls, alongside solid roof and floor colors.
To do this, I created my own MapTexture class which extracted pixel data from a loaded image.For each ray that fired, its final hit position was mapped to a specific pixel from that texture. (using some row and column calcuations)
Some things I also did:
Today I finished implementing the core rendering loop for my 3D C++ raycasting engine and also added player-wall collision detction!
In summary, for every column of your screen, a ray is fired to draw a single vertical strip of a specific size based on how far that ray travels. Then all these strips are combined to form a 3D scene. I also added shading to specific sides of walls.
I then learned how to fix edge distortions (fish-eye correction) and uneven ray distributions using math + geometry.
I also spent ALOT OF MY TIME trying to fix a bug where the player could clip into a corner and get stuck inside, which got very annoying to debug. But I eventually solved it by checking for wall overlaps across the player’s every possible movement position.
I have started working on my new pseudo-3D raycaster project. Using raylib and C++, so far I have created the basic boilerplate code for the main window rendering loop for a basic 2D map. But most importantly during this first session, I created a basic, but working raycasting system which used an algorithm called DDA. (grid-traversal algorithm)To implement it, I worked through the underlying math and logic behind the algorithm, and went through some examples before implementing the code myself. I faced many bugs while coding it and it took a lot of trial and error before I finally had it working.. . The CastRay() function I created allows rays to traverse efficiently across grid cells, skipping over unnecessary positions and without missing any collisions. For the next dev log, I hope to have completed the actual Player object + movement + collision detection, and implement the 3D rendering loop that constructs the 3D scene using my CastRay function.