Skip to content

mbdanielcrespo/Fdf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

25 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ—บ๏ธ FDF (Fil de Fer)

42 Badge Score Language Graphics Status

FDF Badge

๐Ÿ“ Introduction

FDF (Fil de Fer) is a 42 School graphics project that involves creating a simple 3D wireframe renderer. The program reads a map file containing height values and renders it as a 3D wireframe model with various projections.

"This project is about creating a simplified 3D graphic representation of a relief landscape."

FDF introduces the fundamentals of graphics programming, including managing a window, handling events, and creating images with basic transformations.

๐ŸŽฏ Project Objectives

  • Read and parse 3D map files
  • Render 3D wireframe models from height maps
  • Implement different projection types (isometric, parallel)
  • Apply color gradients based on elevation
  • Handle user input for model manipulation (rotation, zoom, translation)
  • Efficiently draw lines between points
  • Properly manage memory and graphical resources

๐Ÿงฉ Project Structure

fdf/ โ”œโ”€โ”€ includes/ โ”‚ โ””โ”€โ”€ fdf.h # Header with structures and function prototypes โ”œโ”€โ”€ src/ โ”‚ โ”œโ”€โ”€ color.c # Color handling functions โ”‚ โ”œโ”€โ”€ draw.c # Line drawing algorithms โ”‚ โ”œโ”€โ”€ god.c # Main rendering and event handling โ”‚ โ”œโ”€โ”€ init.c # Initialization functions โ”‚ โ”œโ”€โ”€ main.c # Program entry point โ”‚ โ”œโ”€โ”€ projections.c # Projection transformations โ”‚ โ”œโ”€โ”€ read_file.c # Map file parsing โ”‚ โ”œโ”€โ”€ setters.c # Setting various parameters โ”‚ โ””โ”€โ”€ utils.c # Utility functions โ””โ”€โ”€ Makefile # Compilation instructions 

๐Ÿ› ๏ธ Implementation Details

color.c

Color handling and management:

Function Description
parse_color Converts hexadecimal color strings (like "0xFF0000") to integer color values
get_default_color Assigns default colors based on height values for gradient coloring

draw.c

Core drawing algorithms:

Function Description
draw_line Implements Bresenham's line algorithm to draw lines between points
put_pixel Places a pixel at specific coordinates in the image buffer

god.c

Main rendering and event handling:

Function Description
render_map Coordinates the drawing of all lines to create the complete wireframe
handle_events Processes user inputs and updates the display parameters accordingly

init.c

Setup and initialization:

Function Description
init_fdf Sets up the main FDF structure with default values and settings
init_mlx Initializes the MiniLibX graphical context and creates a window

main.c

Program entry point:

Function Description
main Parses command-line arguments, initializes structures, and starts the main loop

projections.c

3D to 2D coordinate transformations:

Function Description
apply_isometric Transforms 3D coordinates to isometric projection (30ยฐ rotation)
apply_parallel Applies parallel (orthographic) projection to 3D coordinates

read_file.c

Map file parsing:

Function Description
read_map Reads the map file line by line and stores height values in data structure
parse_line Parses individual lines into coordinate and color data

setters.c

Parameter adjustment:

Function Description
set_zoom Automatically adjusts the zoom level based on map dimensions
set_offsets Calculates initial offsets to center the map in the window

utils.c

Utility functions:

Function Description
ft_atoi Converts string representations of numbers to integers
error_exit Handles error messages and gracefully exits the program

๐ŸŽฎ Features

  • Multiple Projections: Switch between isometric and parallel views
  • Dynamic Coloring: Height-based color gradients or custom colors from map files
  • Interactive Controls:
    • Zoom in/out
    • Rotate model
    • Pan/translate
    • Adjust height factor
  • Automatic Scaling: Adapts to different map sizes
  • Error Handling: Robust handling of invalid inputs and file formats

๐Ÿ–ผ๏ธ Supported Map Format

The program reads maps with the following format:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 0 0 10 10 0 0 0 10 10 10 10 10 0 0 0 0 0 10 10 0 0 10 10 0 0 0 0 0 0 0 10 10 0 0 0 0 10 10 0 0 10 10 0 0 0 0 0 0 0 10 10 0 0 0 0 10 10 10 10 10 10 0 0 0 0 10 10 10 10 0 0 0 0 0 0 10 10 10 10 10 0 0 0 10 10 0 0 0 0 0 0 0 0 0 0 0 0 10 10 0 0 0 10 10 0 0 0 0 0 0 0 0 0 0 0 0 10 10 0 0 0 10 10 10 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 

Each number represents a point in 3D space:

  • Position in the grid (x,y)
  • Height value (z)
  • Optional color in hexadecimal format: 10,0xFF0000 for a red point at height 10

๐Ÿง  Skills Developed

  • Graphics programming fundamentals
  • 3D to 2D projection mathematics
  • Event-driven programming
  • Memory management for graphics resources
  • File parsing and validation
  • Implementation of drawing algorithms
  • User interface design for interactive graphics

๐Ÿ“Š Project Stats

Metric Value
Final Score 100/100
File Count 9
Graphics Library MiniLibX
Projection Types 2

C Graphics 42

About

Project that involves creating a 3D wireframe renderer in C. It reads elevation data from a file and displays it using isometric projection, utilizing the MiniLibX library for graphical output.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors