Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FdF – Wireframe 3D Map Renderer

FdF (Fil de Fer – “wireframe”) is a graphics project that renders a 2D isometric wireframe using MLX42 library. It reads a map (see the format below), parses the values and calculates the coordinates for pixels first primitively from above. Then, takes into account the given altitude and recalculates coordinates into a 3D-like isometric projection.

Demo

Map File Format

Each line = one row (y). Values separated by spaces. A value can be:

Z
Z,0xRRGGBB

Example:

0 0 0 1 2,0xFF0000
0 1 2 3 4,0x00FFAA

Each number represents a point in space: • The horizontal position corresponds to its abscissa. • The vertical position corresponds to its ordinate. • The value corresponds to its altitude.

Projection Mathematics

In this implementation I applied the 3 x 3 rotation matrix that I found on Wikipedia:

https://en.wikipedia.org/wiki/Rotation_matrix

I took the third matrix since the we only rotate around z axis. Hence these formulas:

	isometric_x = cos(45 * (PI / 180)) * x - sin(45 * (PI / 180)) * y;
	isometric_y = sin(45 * (PI / 180)) * x + cos(45 * (PI / 180)) * y;

Lines

If we wanted perfectly straight or diagonal lines it wouldn't be an issue to just iterate through x and y in loops. Here, the diagonal line can have let's say width 10 and height 4 which would be a shallow line. Because pixels can only be integers (no float), before putting one the programme must decide whether it moves straight to the right (or left) or up (or down). That's where this guy helped me: https://youtu.be/RGB-wlatStc?si=RZXFxfKUcOPuE_mq

Basically

Two variants handle slopes:

  • Shallow: |slope| < 1 → step in x, conditionally adjust y.
  • Steep: |slope| ≥ 1 → step in y, conditionally adjust x.

Color Gradients

ft_gradient(start_color, end_color, position, length) interpolates each RGB channel linearly:

channel = start + (end - start) * position / length

The end

Thanks for reading. If you reached here, I am already fond of you.

About

No description or website provided.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Used by

Contributors

Languages