Raycasting engine - polished


So i've been hard at work on my wolf3d raycasting clone, and have added floors, ceilings and furniture. For more information on what ray casting is, check out my previous video:
https://yonnyzohardesignblog.blogspot.com/2020/04/were-still-dealing-with-pseudo-3d-retro.html
Anyway, the furniture is drawn after being hit by a ray, except it is not drawn column by column like the walls, but rather as a single blit, and scaled by its distance. This means it looks the same regardless of angle, although you could always prepare in advance different images to be blitted at different angles (36 images to be changed every 10 angles for instance).
The Floors however we a completely different story. I ended up using a technique called "mode7" - creating an off screen bitmap, equivalent in size to my map, populated with floor tiles. I then defined a near and far plane that stretched from the left most angle of my line of sight to the right most angle. I then began sampling each pixel in my screen and checked where it mapped to in my FOV (field of view), and finally translated that to a pixel in the off screen bitmap -> and then back to the screen pixel. It's a technique so simple, utilizing so few lines of code, it's scary.

Update:
So i think i'm about done with my ray casting engine. It can be tweaked and improved forever but i'm getting a bit sick of it so i thought i'd recap before moving on to the next best thing:
1. ray casting is a technique where lines are "drawn" outwards from the player's position across his field of view until they intersect with wall tiles in a 2d grid. Based on the each line's or ray's length, a column of pixels is drawn on screen from left to right, where each pixel column on screen maps to a ray. 2. To create an illusion of depth, walls can be assigned different colors based on distance, or textures based on numbers assigned to tiles. Since the grid is made of tiles with fixed sizes and locations you can easily map the coordinate your ray hit on the tile to a percentage to sample a texture from. 3. In order to create a ceiling and floor you can define "near" and "far" planes that slice through your field of view and sample pixels within that area to create an illusion of depth. 4. Furniture and other objects are not drawn column by column but rather blitted as a whole and placed on screen according to their angle relative to the player's field of view. 5.Finally, enemies can be placed in the scene and given some AI of your choosing. In this, simply move towards the player when he gets close. This was a truly fun exercise that taught me allot about 2d and 3d graphics. I've developed an appetite for the the next pseudo 3d engine in line - the BSP engine (binary space partitioning) used to create Doom and other more advanced pseudo 3d games.
As usual, all source code is available here:

תגובות

פוסטים פופולריים מהבלוג הזה

Thoughts on HTML5, a Flash Developers hopeless rant

Pseudo 3d Isometric view

Veroni Noise