3.3 KiB
3.3 KiB
cube3D
This project is a 3D mini game, that uses raycasting to produce a FPP (first person perspective), just like in Wolfenstein3D or Doom.
It creates a 3D view from a map in a text file, and move the view as if we were walking and looking around.
An example of a map :
$> cat -e map.cub
111111111111111111111111$
1......................1$
1......................1$
1......................1$
1.....11111....1.1.1...1$
1.....1...1............1$
1.....1...1....1...1...1$
1.....1...1....E.......1$
1.....11.11....1.1.1...1$
1......................1$
1......................1$
1......................1$
1......................1$
1......................1$
1.......11.............1$
1.......11.............1$
111111..11............11$
11.1....11.............1$
11....1.11............11$
11.1....11.............1$
11.1111111............11$
11...................111$
1111111111..........1111$
111111111111111111111111$
$>
This map will produce this 3D view :
You can change the images on the wall :
And change the map itself :
raycasting
Raycasting is a technic that creates the illusion of 3D with very low computational power.
This technic has the hability to not show hidden area by design, which is a great simplification for rendering.
How it works :
- first you determine the position and orientation of the viewer in the map, and the distance and width of the screen
- then you will scan this fictif screen with rays, each ray will correspond to a column in the 3D view
- when a ray reaches a wall, it draw it in the 3D view
- the height of the wall is inversely proportional to the length of the ray : the shorter the ray, the higher the wall
- so a full scan gives the illusion of perspective
- but this gives rounded walls, like a fish eye effect, because rays change length while scanning the wall, so we must apply a correction according to the angle
- another step by step example to show how drawing gains in precision with more rays :
example of raycasting with errors in action while construction of the project :











