Skip to content

Create the schematic representation graphically of relief terrain.

Notifications You must be signed in to change notification settings

FlorentBelotti/42_cursus_FdF

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

42_cursus_Fil_de_fer---------------------------------------------------

C

Summary---------------------------------------------------

Features---------------------------------------------------

  • Renders a wireframe model of a terrain using isometric projection.
  • Supports dynamic window resizing and smooth rendering.
  • Includes keyboard and mouse event handling for interactive terrain exploration.
  • Bonus features:
    • Additional projection modes (e.g., parallel or conic).
    • Zoom in and out functionality.
    • Translation (panning) of the terrain.
    • Rotation of the terrain view.

Code Overview---------------------------------------------------

The project is organized into several source files, each handling different aspects of the program:

  • FdF_main.c: Contains the main function and program entry point.
  • FdF_bresenham.c: Implements the Bresenham line algorithm for drawing lines.
  • FdF_clear_draw.c: Handles clearing and redrawing the window content.
  • FdF_isometric.c: Manages the isometric projection calculations.
  • FdF_offset.c: Deals with adjusting the terrain offset for proper centering in the window.
  • FdF_line_error.c: Contains functions for handling line errors.
  • FdF_token_error.c: Contains functions for handling token errors.
  • Minilibx_creation.c: Initializes the MiniLibX window and related components.
  • Minilibx_key_handling.c: Manages keyboard inputs and interactions.
  • FdF_memory_management.c: Manages memory allocation and deallocation.
  • FdF_node_management.c: Handles the creation and management of nodes in the terrain model.
  • FdF_parsing.c: Parses the input .fdf file to create the terrain model.
  • FdF_bresenham_utils.c: Utility functions for the Bresenham line algorithm.
  • FdF_draw_utils.c: Utility functions for drawing operations.
  • FdF_list_utils.c: Utility functions for managing linked lists.
  • FdF_mvt_utils.c: Utility functions for handling movements (translation, rotation).
  • FdF_size_utils.c: Utility functions for size and scaling operations.

Feedback---------------------------------------------------

In the curriculum, the FdF and So_Long projects represent our first ventures into graphical projection. An essential skill to acquire here is mastering the MiniLibX, the specified graphics library. For FdF in particular, it is crucial to understand the principles of the point projection algorithm. My project was thus focused on these two main areas.

  • The process began with parsing the map, a relatively straightforward step thanks to the data manipulation skills acquired early in the 42 curriculum.

  • The next phase involved learning to display graphics via MiniLibX, including handling window macros and pixel-by-pixel rendering.

  • The most complex phase was implementing Bresenham's algorithm for plotting points. Bresenham's algorithm is essential for drawing straight lines on a pixel grid while minimizing rounding errors and using only integer operations for maximum efficiency. Here’s how it works:

    1. Initialization: Determine the starting point (x0, y0) and the ending point (x1, y1) of the line.

    2. Calculate Differences: Compute the difference in x:

    Δx = x1 - x0

    and in y:

    Δy = y1 - y0

    Then determine the signs for advancing on the grid (increment or decrement).

    3. Initial Error Determination: The initial error is defined as:

    Δy - Δx

    for lines that are more horizontal than vertical.

    4. Plotting Loop: For each x from x0 to x1:

    • Plot the pixel at coordinates (x, y).
    • Update the error. If the accumulated error exceeds 0, increment y and adjust the error by subtracting:
    • Increment x and adjust the error by adding:

This algorithm is adaptive, adjusting the plotting based on the slope of the line to ensure that each segment of the line is as close as possible to the theoretical line.

Ultimately, the FdF project is one of the most demanding of the initial projects in the curriculum, preceding Minishell. I would not recommend it to those who are not particularly interested in algorithmic challenges.

Thanks---------------------------------------------------

To Romeo Rodor (Rrodor): who took the time to help me understand the Bresenham algorithm, and more generally the logic of projecting points in space.

About

Create the schematic representation graphically of relief terrain.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published