FDF is a program that read a map and render it in 3D. The map give us several points and we have to link these points with lines to form the projection. FDF is short for "Fil de Fer" in French that means ’iron wire’, i.e., all surfaces of the 3D object are outlined by lines. It is a 42 School project.
In order to compile and run, follow these commands. You must have glfw (Graphics Library Framework) and cmake instaled.
git clone https://github.com/alissonmarcs/fdf.git
cd fdf
make bonus
./fdf_bonus ./maps/elem2.fdf
Compiling with make bonus
you will be able to use keys to rotate, translate and zoom than only with make
. These are keys for doing that:
- Arrow keys to translate.
-/=
to zoom.w/s
to rotate aroud x axes.a/d
to rotate around y axes.q/e
to rotate around z axes.j/k
to decrease/increase z scale.r
to reset view.1
and2
to toggle beetween isometric and top view projection.Esc
to close windows and terminate.
Several maps are avaliable in maps
folder. More cool maps are avaliable in maps/others
folder. To generate amazing maps from images, take a look in map generator for FDF.
- Understanding the map file format.
- Centralize, scale beetwen points and scale for z.
- How to get isometric projection (3D projection that subject requires).
- Understanding rotations.
- Drawing lines that connect all map points.
The map file give us several numbers, every number represent a point. Every point in map have yours x, y and z cordinate. The x value of a point is the column index that he is (the line is splited by spaces), the y value of a point is the line index that he is, and the z value is its not any index, but the value itself. Every number we see in the above map file are values for z of all points, while the x and y values are infered by the position of the z values.
To centralize, I put the center of the projection on origin of window (point 0, 0), and afterwards add offsets on x and y of all points to achieving centralization. Scale beetween points (scale for x and y of each point) is necessary because if not, the projection will be very small, and it needs be dymanic, small maps require more scale than big maps. Some maps have z values very small, while others very big, and projection of these maps were distorced in z axis, so a dymanic scale for z axis is also necessary.
See the projection axes as the follows:
To get isometric, all we have to do is rotate projection aroud it vertical axis z by 45° then rotate again around x axis by 35°.
Rotate a projection around its whateaver axis is like we grab that axis with our handy and twist it.
The traditional way of doing that is using rotation matrices, but I used simplified formulas for doing that.
To form the desired projection we have to connect all points that map give us. Since MLX42 graphics library doesn't have function to draw lines, I have do study Bresenham line drawing algorithm and implement it.