diff --git a/README.md b/README.md index 0c2c3f0..0811a21 100644 --- a/README.md +++ b/README.md @@ -1,36 +1,50 @@ -# FDF - fil de fer +# FDF - fil de fer (french for Wire) +--- -### this is an exercise to discover 3D drawing, keyboard events, and pixel images manipulation +This project is an introduction to 3D drawing. It takes a map file and render it with its height. It listen to keyboard event to apply transformations on it, such as translation, rotations, zoom, and change in altitude factor. -it reads a map, which is a simple text file like this : +the input map is a simple text file that looks like this : ``` -0 0 0 0 0 -0 0 0 0 0 -0 10 0 0 0 -0 0 0 0 0 -0 0 0 0 0 +$> cat -e map_test.fdf +0 0 0 0 0$ +0 0 0 0 0$ +0 10 0 0 0$ +0 0 0 0 0$ +0 0 0 0 0$ +$> ``` -and it converts it into a rectangular net, like a landscape with the height equal to the numbers : +and the program converts it into a rectangular net, like a landscape with the height equal to the numbers : ![example 3D of map before modification](assets/fdf_demo_1.jpg) -we can modify the map to change the 3D drawing : +we can modify the map to see a new 3D model : + +``` +$> cat -e map_test.fdf +0 0 0 0 0$ +1 2 3 4 5$ +0 10 8 0 0$ +0 0 0 9 0$ +0 0 0 0 0$ +$> +``` ![example 3D of map after modifications](assets/fdf_demo_2.jpg) -### it is based on a library called [minilibx](https://github.com/42Paris/minilibx-linux), which is like a simplified version of X11 +# ressources +--- -some of the difficulties of this program : +- it is based on a library called minilibx : https://github.com/42Paris/minilibx-linux +- equations to transform a 2D drawing into a perspective : https://math.stackexchange.com/questions/2305792/3d-projection-on-a-2d-plane-weak-maths-ressources/2306853#2306853 +- drawing a line between two points : https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm +- bits manipulation for colors shifting : https://dev.to/freerangepixels/a-probably-terrible-way-to-render-gradients-1p3n +- optimizing events response with debouncing and throttling : https://stackoverflow.com/questions/25991367/difference-between-throttling-and-debouncing-a-function +- building images instead of asking the X library to draw each pixel one by one : https://github.com/Gontjarow/MiniLibX/blob/master/docs/mlx-tutorial-create-image.md -- finding the equations to transform a 2D drawing into a perspective -- drawing a line between two points -- bits manipulation for colors -- organization of the code to take care of all the events and transformations -- building images instead of asking the minilibx library to draw each pixel one by one - -it can listen to keyboards events to transform the 3D, like turning around, zooming... : +# transformations : +--- **zoom :** diff --git a/includes/fdf.h b/includes/fdf.h index 73851d1..a0afd75 100644 --- a/includes/fdf.h +++ b/includes/fdf.h @@ -74,10 +74,10 @@ int is_color(char *color); void size_map(t_fdf *fdf, char *raw, int height); int **parse_map(t_fdf *fdf, int fd); -// steps size for the hight transform with p and o +// steps size for the height transform with p and o // must be > 0 // 100 is small, 1 is the biggest -# define Z_HEIGHT 10 +# define Z_HEIGHT 100 // then define the speed for height transform // must be > 0 // 1 is small, 100 is the big @@ -104,12 +104,12 @@ int **parse_map(t_fdf *fdf, int fd); */ /* # define COLOR_END 0x877264 // brown -# define COLOR_END 0xa263f6 // purple # define COLOR_END 0x1423e6 // blue # define COLOR_END 0xf263a6 // pink # define COLOR_END 0xffffff // white -*/ # define COLOR_END 0x00d700 // green +*/ +# define COLOR_END 0xa263f6 // purple // pixels deplacement for each keypress # define MOVE 10