Wall Hit Position: fmod(ray_x, BLOCK) / BLOCK

Grid World (BLOCK = 64)
Wall Texture Mapping

Ray Hit Position

Number Line Visualization:

World coordinates →
Block-relative position:

What This Calculation Does:

1. The Problem:

When a ray hits a wall, we need to know where exactly along that wall face the hit occurred. This determines which part of the texture to display.

2. World Coordinates vs Block-Relative Coordinates:

3. The fmod() Function:

fmod(ray_x, BLOCK) gives the remainder when dividing ray_x by BLOCK:

4. Normalizing to 0.0-1.0:

Dividing by BLOCK converts the remainder to a fraction:

5. Why This Matters for Textures:

6. Example Usage:

If texture is 64 pixels wide and wall_hit = 0.75:

texture_x = (int)(0.75 * 64) = 48

So we'd use column 48 of the texture for this wall strip.