ray->side == 0: Hit a vertical wall (NS-facing)
ray->side == 1: Hit a horizontal wall (EW-facing)
For Vertical Walls (side == 0):
ray->ray_dx < 0: Ray going left → Use WEST textureray->ray_dx > 0: Ray going right → Use EAST textureFor Horizontal Walls (side == 1):
ray->ray_dy < 0: Ray going up → Use NORTH textureray->ray_dy > 0: Ray going down → Use SOUTH textureVertical walls: wall_hit = fmod(ray_y, BLOCK) / BLOCK
Horizontal walls: wall_hit = fmod(ray_x, BLOCK) / BLOCK
This gives a value 0.0-1.0 representing where along the wall edge the ray hit.
tex_x = (int)(wall_hit * tex->width)
Converts the 0.0-1.0 hit position to actual texture pixel coordinate.
Flips texture for consistent lighting/orientation:
if ((side == 0 && ray_dx > 0) || (side == 1 && ray_dy < 0))
tex_x = tex->width - tex_x - 1;
This ensures textures appear consistent from the player's perspective.